Running ansible-playbook using Python API

前端 未结 6 1645
余生分开走
余生分开走 2020-12-04 14:47

How can I run a playbook in python script? What is the equivalent of the following using ansible module in python:

ansible -i hosts dbservers -m setup
ansibl         


        
6条回答
  •  醉话见心
    2020-12-04 15:17

    Based on vigilander's answer, I took the liberty to upload a pkg to pypi and now you can use this simple ansible runner:

    Just pip install ansible-playbook-runner and run:

    from ansible_playbook_runner import Runner
    
    Runner(['inventory_path'], 'playbook_path').run()
    

提交回复
热议问题