**** ansible.errors.AnsibleError:无法找到库存文件,请指定-i?****

时间:2015-03-18 07:04:54

标签: python-2.7 ansible-inventory ansible-api

  

**** 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()

sample1.yml:

- hosts: localhost
  connection: local
  sudo: no

的/ etc / ansible /主机:

[localhost]
localhost ansible_connection=local

0 个答案:

没有答案