**** ansible.errors.AnsibleError:无法找到库存文件,请使用-i?****指定一个
#!/usr/bin/python
import ansible.playbook
from ansible import callbacks
from ansible import utils
ANSIBLE_HOSTS = 'hosts'
PLAYBOOK = 'sample1.yml'
def deploy():
stats = callbacks.AggregateStats()
playbook_cb = callbacks.PlaybookCallbacks(verbose=utils.VERBOSITY)
inventory = ansible.inventory.Inventory(ANSIBLE_HOSTS)
runner_cb = callbacks.PlaybookRunnerCallbacks(stats,verbose=utils.VERBOSITY)
pb = ansible.playbook.PlayBook(playbook=PLAYBOOK,
callbacks=playbook_cb,
runner_callbacks=runner_cb,
stats=stats,
inventory=inventory,
extra_vars={'test': "TEST"})
pb.run()
if __name__ == "__main__":
deploy()
- hosts: localhost
connection: local
sudo: no
[localhost]
localhost ansible_connection=local