如何从python脚本运行ansible

如何从python脚本运行ansible,python,ansible,Python,Ansible,我正在尝试在用作flask服务器一部分的python脚本中运行ansible剧本。 然而,当试图用python构建剧本时,它并没有按照预期的方式工作 原始剧本应为: --- - hosts: dc gather_facts: no tasks: - name: create user omtest win_domain_user: name: omtest firstname: om su

我正在尝试在用作flask服务器一部分的python脚本中运行ansible剧本。 然而,当试图用python构建剧本时,它并没有按照预期的方式工作

原始剧本应为:

---
- hosts: dc
  gather_facts: no
  tasks:
      - name: create user omtest
        win_domain_user:
            name: omtest
            firstname: om
            surname: test
            password: sjsd
            state: present
            attributes:
                telephoneNumber: 123456
            path: ou=Hilv,ou="Users",dc=ic,dc=com
            password_expired: yes
            groups:
            - "_AV_NL"
以及它的python代码:

play_ovirt = dict(
        name="win-domain",
        hosts=host_list,
        gather_facts='no',
        tasks=[
            dict(action=dict(module='win_domain_user', args='dict(name='omtest', firstname='om', 'surname='test', password="sjsd', state='present', attributes='dict(telephoneNumber='123456')', path='ou=Hilv,ou="Users",dc=ic,dc=com', groups='['_AV_NL']', password_expired="yes"), register='shell_out')
        ]
    )
我知道python代码有问题,但无法确定是什么问题。
这也是我第一次将ansible作为python代码的一部分使用。

请阅读。现在,如果您想继续并尝试学习ansible的内部结构,并最终做出贡献,这是绝对好的。否则,只需启动
ansible playbook
作为
os.system()
指令。我希望可以将ansible playbook命令与os.system()一起使用,但我需要解析输出,检查是否失败,并相应地采取行动。您可以定义ansible使用的回调插件,以获得所需的确切格式。您是否看到密码字符串没有正确终止?而且
args='dict
似乎也有错误。