![](/img/trans.png)
[英]how can i Thread and play sound while program still working and noe freezing
[英]How can I run an ansible play programmatically while still using a local file as my play?
我想運行一個位於 /tmp/run_tests.yml 的 ansible play,我想在 python 腳本中執行運行,而不是命令行(這些是對我正在處理的問題的一般限制)。 我已經嘗試了幾種不同的方法,這些方法都感覺像是對 Runner 類進行逆向工程的猜測工作,但都沒有成功。 我希望知道這是否可行以及代碼是什么樣的。
如果我想運行單個命令,我可以簡單地使用 Ansible API 的運行程序:
ansible.runner.Runner(**{
"pattern": '*',
"module_name": 'ping',
"inventory": webInventory,
"remote_user": self.username,
"private_key_file": self.private_key
}).run()
hosts = ["127.0.0.0.1"] #dummy ip address
webInventory = ansible.inventory.Inventory(hosts)
runner = ansible.runner.Runner(pattern="*", )
response = runner.run(**{
"pattern": '*',
"module_name": "/tmp/run_tests.yml",
"inventory": webInventory,
"remote_user": "ubuntu",
"private_key_file": "~/.ssh/id_rsa"
})
{'contacted': {}, 'dark': {'127.0.0.1': {'failed': True, 'msg': 'module is missing interpreter line'}}}
從源代碼來看,該錯誤表明缺少 shebang,並且由於我是 ansible 的新手,因此我推測傳遞 yml 文件不是 module_name 的合適文件。 為了運行我的 python 游戲,runner 命令必須是什么樣子的?
我相信您在 3 個多月后已經弄清楚了這一點,但是 Ansible Runner
對象中的module_name
應該是 Ansible 的模塊索引中可用的模塊,例如“apt”或“service”。
我認為您正在尋找Ansible 的 ansible ansible-playbook
等價物,它有自己的run
類方法。
看起來以編程方式運行 Playbook的工作示例可能在這里。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.