HI, It would be great if someone can help me to specify tags while running ansible playbook via Ansible API 2.0.
I have below code taken from https://stackoverflow.com/questions/27590039/running-ansible-playbook-using-python-api: #!/usr/bin/env python import osimport sysfrom collections import namedtuple from ansible.parsing.dataloader import DataLoaderfrom ansible.vars import VariableManagerfrom ansible.inventory import Inventoryfrom ansible.executor.playbook_executor import PlaybookExecutor variable_manager = VariableManager() loader = DataLoader() inventory = Inventory(loader=loader, variable_manager=variable_manager, host_list='/ansible/hosts') playbook_path = '/ansible/ls.yml' if not os.path.exists(playbook_path): print '[INFO] The playbook does not exist' sys.exit() Options = namedtuple('Options', ['listtags', 'listtasks', 'listhosts', 'syntax', 'connection','module_path', 'forks', 'remote_user', 'private_key_file', 'ssh_common_args', 'ssh_extra_args', 'sftp_extra_args', 'scp_extra_args', 'become', 'become_method', 'become_user', 'verbosity', 'check']) options = Options(listtags=False, listtasks=False, listhosts=False, syntax=False, connection='ssh', module_path=None, forks=100, remote_user='slotlocker', private_key_file=None, ssh_common_args=None, ssh_extra_args=None, sftp_extra_args=None, scp_extra_args=None, become=True, become_method=None, become_user='root', verbosity=None, check=False) variable_manager.extra_vars = {'hosts': 'mywebserver'} # This can accomodate various other command line arguments.` passwords = {} pbex = PlaybookExecutor(playbooks=[playbook_path], inventory=inventory, variable_manager=variable_manager, loader=loader, options=options, passwords=passwords) results = pbex.run() Using above code I can achieve below: ansible-playbook ls.yml -i hosts --extra-vars "hosts=mywebserver" However I want to specify tags and achieve it using Ansible API 2.0: ansible-playbook ls.yml -i hosts --extra-vars "hosts=mywebserver" --tags "TestCopy" Thanks, Anonymous -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/8949bdea-a8d0-462a-8007-6a59da8c6a45%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
