Hi All,
I am noob to ansible and hence this basic question.
I am trying to manage the crontabs on my servers through ansible. My servers already have a set of cronjobs.
As I understand the ansible cron module prefixes all the cron jobs set by it with #Ansible: Name and uses this to manage them in the future.
My existing crontabs do not have this tag prefixed. Can I still update and delete them through Ansible cron module ?
Thanks and Regards,
Manas Shukla
The lineinfile is always an option, but you lose a lot of ansibles
simplicity, and the regexp stuff is horror...
I would try to convert your existing cronjobs to ansible syntax (i.e.
write an ansible task that spits out the same line in the crontab) and
then prefix your lines with the corresponding "#Ansibe: foo" line.
This can be done manually, via template or with lineinefile.
It all depends on the variety of your existing cronjobs. One per
server? 20? The same everywhere, only with different arguments?
Testing this with the disabled option to the cron module seems like a
good idea.
Johannes
My existing crontabs do not have this tag prefixed. Can I still update and delete them through Ansible cron module ?
From the documentation, it doesn’t look likely since if you don’t set a name parameter and if state=present then it will create a new crontab entry regardless of any existing ones. See the description for the “name” parameter in link.
However, nothing is stopping you from using the lineinfile module to remove entries your want to update / delete and then use the cron module to create a updated but “managed by Ansible” crontab entry.