Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to execute ansible playbook from crontab?

Tags:

ansible

Is it possible to execute an ansible playbook from crontab? We have a playbook that needs to run at a certain time ever day, but I know that cron doesn't like ssh.

Tower has a built in scheduling engine, but we are not interested in using Tower. How are other people scheduling ansible playbooks?

like image 894
Bobby Kimble Avatar asked Sep 08 '16 19:09

Bobby Kimble


2 Answers

We can run as konstantin-suvorov's answer as well as

type

# whereis ansible-playbook
  /usr/bin/ansible-playbook

and run with the path displayed in the output

we can run with this in crontab

#crontab -e


*/15 * * * * /usr/bin/ansible-playbook /home/user1/yourplaybook.yml

It worked like charm

like image 155
Javeed Shakeel Avatar answered Sep 18 '22 19:09

Javeed Shakeel


It will also work, I am using this to check an agent status and starting it if it is stopped.

*/5 * * * * ansible-playbook -i /root/playbooks/agent /root/playbooks/agent.yml


like image 41
Hasan S Syed Avatar answered Sep 18 '22 19:09

Hasan S Syed