How to manage the crontab entries that were not done by Ansible's cron module

1,925 views
Skip to first unread message

Manas Shukla

unread,
Jan 26, 2017, 4:13:59 PM1/26/17
to Ansible Project
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

Johannes Kastl

unread,
Jan 27, 2017, 8:37:57 AM1/27/17
to ansible...@googlegroups.com
On 26.01.17 20:46 Manas Shukla wrote:

> 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 ?

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

signature.asc

Jinesh Choksi

unread,
Jan 27, 2017, 11:46:31 AM1/27/17
to Ansible Project
>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.
Reply all
Reply to author
Forward
0 new messages