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

**URL:** <https://forum.ansible.com/t/how-to-manage-the-crontab-entries-that-were-not-done-by-ansibles-cron-module/23571>\
**Category:** Ansible Project\
**Created:** [January 26, 2017, 7:46pm UTC](https://forum.ansible.com/t/how-to-manage-the-crontab-entries-that-were-not-done-by-ansibles-cron-module/23571 "2017-01-26T19:46:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Manas\_Shukla](https://avatars.discourse-cdn.com/v4/letter/m/bbce88/32.png) [@Manas\_Shukla](https://forum.ansible.com/u/Manas_Shukla)\
**Post date:** [January 26, 2017, 7:46pm UTC](https://forum.ansible.com/t/how-to-manage-the-crontab-entries-that-were-not-done-by-ansibles-cron-module/23571/1 "2017-01-26T19:46:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Johannes\_Kastl](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@Johannes\_Kastl](https://forum.ansible.com/u/Johannes_Kastl)\
**Post date:** [January 27, 2017, 1:37pm UTC](https://forum.ansible.com/t/how-to-manage-the-crontab-entries-that-were-not-done-by-ansibles-cron-module/23571/2 "2017-01-27T13:37:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Jinesh\_Choksi](https://avatars.discourse-cdn.com/v4/letter/j/a6a055/32.png) [@Jinesh\_Choksi](https://forum.ansible.com/u/Jinesh_Choksi)\
**Post date:** [January 27, 2017, 4:46pm UTC](https://forum.ansible.com/t/how-to-manage-the-crontab-entries-that-were-not-done-by-ansibles-cron-module/23571/3 "2017-01-27T16:46:31Z")

</div>

> 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](http://docs.ansible.com/ansible/cron_module.html).

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.
