Every evening a script on one of our Linux servers books the next day's collections with our parcel carrier, one for each of our fourteen depots. It has run from cron for years, and since last spring the entry has been managed by Ansible's cron module, with the name book collections and a schedule of half past six.

In October a colleague tidied the role. He renamed the entry to book carrier collections for all depots and moved it to a quarter past six, so the booking would reach the carrier well before their cut off. The pull request showed one task changing, the playbook ran green, and the next morning two drivers arrived at every depot. The carrier charged us for fourteen failed collections, and the depots spent the morning explaining to the second driver that there was nothing for him.

The cron module does not recognise a job by its command or its schedule. It writes a comment above each entry it manages, #Ansible: followed by the name, and on every run it looks for that comment to decide which line it owns. A new name is a new job. Ansible found no line marked book carrier collections for all depots, so it added one. It left the line marked book collections exactly where it was, because nothing in the playbook mentioned it any more. From then on the script ran at a quarter past six and again at half past, and the carrier's API accepted the second booking as a new one.

In the repository it was one job being renamed. On the server it was one job becoming two, and nothing in between showed the difference.

We deleted the old line by hand that morning. In the role, the old name now has its own task with state: absent, which stays for a full release cycle so every server loses it, and renames are done that way as a rule: absent under the old name, present under the new one. A task at the end of the role reads the crontab, collects every #Ansible: name in it, and fails if any of them is not in the list the role manages. The booking script also asks the carrier for collections already booked for tomorrow before it books another.

The name you give a resource is often how the tool finds it again. Change it and you have not renamed anything. You have created a second one and orphaned the first.

– Sergey Shinder