Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running playbooks automatically

Tags:

ansible

I am learning ansible recently and I am a hard time figuring out, how to configure ansible to run the playbooks on its own after a certain interval. ? Just like puppet does.

like image 239
Gana Sagar Avatar asked Mar 12 '26 19:03

Gana Sagar


2 Answers

Ansible works in a different way compared to Puppet.

Puppet PULLS for configuration changes from a central place and applies changes on the remote host that asked for it.

Ansible by design works different. You PUSH the changes (from any control machine that has SSH access to remote hosts - usually your own computer) to remote hosts.

You can make Ansible work in pull mode also but it's not how Ansible was designed to be used.

You can see this answer for more information: Can't run Ansible in daemon-mode

If you would like the host to automatically run playbooks on itself (localhost) you would basically use ansible-pull script + crontab.

like image 107
Michal Gasek Avatar answered Mar 16 '26 05:03

Michal Gasek


If you want to run the playbooks once after a certain interval, you can use the at command.

Example

# Schedule a command to execute in 20 minutes as root.
- at: command="ls -d / > /dev/null" count=20 units="minutes"

Further information available on ansible official site.

like image 28
Radouane ROUFID Avatar answered Mar 16 '26 05:03

Radouane ROUFID



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!