问题
Can I run Ansible to manage my hosts like a daemon? For example, I sometimes change my playbooks and I don't want to run "ansible-playbook main.yml" manually. Please, don't propose crontab. There is a specific point and I can't use crontab on production server.
Thank you
回答1:
What you are talking about here is called pull mode. Architectually Ansible is designed to work in push mode - you push changes to server from a control machine.
If you really would like to make Ansible work in pull mode then you can do so with Ansible-Pull script, see docs here: http://docs.ansible.com/playbooks_intro.html#ansible-pull
Ansible-pull is a script that can fetch your configuration playbooks from remote repository and run them against localhost. Ansible-pull does not however solve a problem of checking for a new configuration changes - you need to solve it yourself with cron.
Another alternative is using Ansible Tower (you need a paid license for it). Ansible Tower supports callbacks via API, so the server you want to configure has to do API request to Ansible Tower server, Tower in turn will check whether the host that sent API request is in its inventory. If it's in inventory then Tower will start configuring it.
来源:https://stackoverflow.com/questions/27295348/cant-run-ansible-in-daemon-mode