Is it possible to run a playbook in “pull mode”?

…衆ロ難τιáo~ 提交于 2019-12-10 17:49:27

问题


I have playbooks which I start on a master host and which run specific actions on remote hosts. This is a "push" mode - the activity is initiated by the master host.

Several of my hosts are down at a given time and obviously fail to run the playbook when in such a state. This leads to hosts which are up-to-date, while others are not.

To fix this I could run the playbook on the master host in a regular way (via cron for instance) but this is not particularly effective.

Is there a built-in way in Ansible to reverse the flow, that is to initiate from a remote host a playbook available on the master, to run it on that remote host?

I can imagine that the remote host could ssh to the master (at boot time for instance) and then trigger the playbook with the host as a parameter (or something around that idea) but I would definitely prefer to use an Ansible feature instead of reinventing it.


回答1:


There is a script called ansible-pull which reverses the default push architecture of Ansible. There is also an example playbook from the Ansible developers available.




回答2:


The use of ansible-pull mode is really simple and straight-forward, this example might help you:

ansible-pull -d /root/playbooks -i 'localhost,' -U git@bitbucket.org:arbabnazar/pull-test.git --accept-host-key

options detail:

1. --accept-host-key: adds the hostkey for the repo url if not already added
 2. -U: URL of the playbook repository
 3. -d: directory to checkout repository to
 4. –i localhost,: This option indicates the inventory that needs to be considered. 
                   Since we're only concerned about one host, we use -i localhost,.

For detail, please refer to this tutorial



来源:https://stackoverflow.com/questions/38663591/is-it-possible-to-run-a-playbook-in-pull-mode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!