Ansible python API 2.0: run a playbook in a python script for windows clients
<p>I am trying to re-write this script (<a href="https://stackoverflow.com/questions/35368044/how-to-use-ansible-2-0-python-api-to-run-a-playbook">How to use Ansible 2.0 Python API to run a Playbook?</a>) to call an ansible playbook within a python script that runs against windows clients. I have a test folder that contains the playbook (<code>deploy.yml</code>) the host file (<code>hosts</code>) and additional variables (<code>ansible_user</code>,<code>ansible_port</code>..) in the subfolder <code>group_vars/win_clones.yml</code>.</p>

<p>I would like to point to these files to run my playbook within the python script. I did so for <code>deploy.yml</code> and <code>hosts</code> files but I don't know where to point to  <code>group_vars/win_clones.yml</code>. How can i make this work?</p>

<pre><code>from collections import namedtuple
from ansible.parsing.dataloader import DataLoader
from ansible.vars import VariableManager
from ansible.inventory import Inventory
from ansible.executor.playbook_executor import PlaybookExecutor 

variable_manager = VariableManager()
loader = DataLoader()

inventory = Inventory(loader=loader, variable_manager=variable_manager,  host_list='fullpath/to/hosts')
playbook_path = 'fullpath/to/deploy.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 = {'ansible_user': 'ansible', 'ansible_port': '5986', 'ansible_connection': 'winrm', 'ansible_password': 'pass', 'ansible_winrm_server_cert_validation': 'ignore'} # Here are the variables used in the winclones.yml

passwords = {}

pbex = PlaybookExecutor(playbooks=[playbook_path], inventory=inventory, variable_manager=variable_manager, loader=loader, options=options, passwords=passwords)
results = pbex.run()
</code></pre>

<p>EDIT 1</p>

<p>This is the output of the play run through python script:</p>

<pre><code>TASK [setup]     *******************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: AttributeError: 'NoneType' object has no attribute 'upper'
fatal: [cl3]: FAILED! =&gt; {"failed": true, "msg": "Unexpected failure during module execution.", "stdout": ""}
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: AttributeError: 'NoneType' object has no attribute 'upper'
fatal: [cl1]: FAILED! =&gt; {"failed": true, "msg": "Unexpected failure during module execution.", "stdout": ""}
</code></pre>