I am trying hard to create a simple script to execute a playbook with python
`
from ansible.parsing.dataloader import DataLoader
from ansible.vars.manager import VariableManager
from ansible.inventory.manager import InventoryManager
from ansible.executor.playbook_executor import PlaybookExecutor
loader = DataLoader()
inventory = InventoryManager(loader=loader, sources=“localhost,”)
variable_manager = VariableManager(loader=loader, inventory=inventory)
passwords={}
playbook = PlaybookExecutor(playbooks=[‘test.yml’],inventory=inventory,variable_manager=variable_manager,loader=loader,passwords=passwords)
playbook.run()
`
This is simple, but keep saying error:
`
Traceback (most recent call last):
File “ansible_play.py”, line 13, in
playbook.run()
File “/Users/brunoselva/.local/share/virtualenvs/devops-lambda-sY4jyCvw/lib/python2.7/site-packages/ansible/executor/playbook_executor.py”, line 146, in run
if context.CLIARGS[‘syntax’]:
File “/Users/brunoselva/.local/share/virtualenvs/devops-lambda-sY4jyCvw/lib/python2.7/site-packages/ansible/module_utils/common/collections.py”, line 20, in getitem
return self._store[key]
KeyError: ‘syntax’
`
Someone knows what I am doing wrong ?