简体   繁体   English

在python脚本中调用Ansible adhoc命令/ playbooks

[英]Calling Ansible adhoc commands/playbooks in python script

How to run Ansible playbooks and commands from python script 如何从python脚本运行Ansible playbooks和命令

Is this suggesgted way? 这是暗示的方式吗? https://docs.ansible.com/ansible/latest/dev_guide/developing_api.html#python-api-example https://docs.ansible.com/ansible/latest/dev_guide/developing_api.html#python-api-example

Called ansible playbook/adhoc commands runs smoothly inside python script 被称为ansible playbook / adhoc命令在python脚本中运行顺畅

Ansible doesn't recommend using that method. Ansible不建议使用该方法。 Quoting directly from the link you shared: 直接从您分享的链接引用:

This API is intended for internal Ansible use. 此API适用于内部Ansible使用。 Ansible may make changes to this API at any time that could break backward compatibility with older versions of the API. Ansible可能随时对此API进行更改,这可能会破坏与旧版本API的向后兼容性。 Because of this, external use is not supported by Ansible. 因此,Ansible不支持外部使用。

Another option would be to use the subprocess library to call your command using the command line syntax (as opposed to the API). 另一种选择是使用子进程库使用命令行语法(而不是API)来调用命令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM