Cron module usage question...

Greetings,

I have used the cron module in one of my playbooks and it worked perfectly. However when I came to test on a second server it added a second cron job identical to a previous one. The previous one was not added by Ansible.

Would it make sense to add a check to see if Ansible is planning on adding an identical line to one that already exists? Does anyone else feel that this might be useful or is it just me?

Adam

Having played with this a little more I am having concerns about how the cron module works when a similar line already exists.

For example, if I want to change an existing line in a crontab to modify the parameters to the command what is the best way to do that?

The most effective way on linux seems to be to use lineinfile to modify the file directly. This works because cron actually looks for changed files on Linux. This doesn’t work on AIX though and while modifiying the cron module to work for AIX is trivial this does not provide the functionality that I would like.

Does anyone have any suggestions or do I need to rewrite the cron module completely?

Adam

Hi

AFAIK Cron module checks only those crons which starts with ansible. From docs:


- 'The module includes one line with the description of the crontab entry C("#Ansible: <name>")
    corresponding to the "name" passed to the module, which is used by future ansible/module calls
    to find/check the state.'

I agree that this is not the best way to manage crons. Perhaps this module should be re-written and should use something like python-crontab https://pypi.python.org/pypi/python-crontab

Edgars

pirmdiena, 2014. gada 6. janvāris 22:58:17 UTC+1, Adam Morris rakstīja:

I found a reasonable alternative… I have a lineinfile task before the cron task to add the “#Ansible: name” before the pre-existing line that I want to manage through Ansible.

That works for me… I did some testing on a few scenarios and it seems to resolve my issues.

Adam