Adding a cron job to our EC2 instance

We are now going to create a cron tab entry to periodically call ansible-pull. Here, too, we will rely on Ansible to create our cron job remotely. Run the following command by adapting the IP address:

$ ansible '18.206.223.199' \
--private-key ~/.ssh/EffectiveDevOpsAWS.pem \
-m cron -a 'name=ansible-pull minute="*/10" job="/usr/bin/ansible-pull -U https://github.com/<your_username>/ansible helloworld.yml -i localhost --sleep 60"'  

In the preceding command, we are telling Ansible to use the cron module targeting our ec2 instance. Here, we are providing a name that Ansible will use to track the cron job over time, telling cron to run the job every 10 minutes, followed by the command to execute and its parameters. ...

Get Effective DevOps with AWS - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.