Hello,
I have really enjoyed using Ansible to be able to completely template new servers that I set up, but one thing I have not yet figured out how to do in my workflow is deal with changes that occur after a playbook has been run on a server. For example, let’s say that I have a cron task that creates a cron:
- name: create my cron
cron: name=“My Cron version 1.0” job=/usr/local/bin/cron.sh minute=1
I run the playbook on my servers and this cron is added to the crontab, good. However, later I decide to change the name, the job, or some other attribute. If I do that, Ansible will add a new entry to the crontab but leave this old one around. One solution would be to add a state=absent task, but that involves duplicating or adding some legacy code to my playbook:
- name: create my cron (old)
cron: name=“My Cron version 1.0” job=/usr/local/bin/cron.sh minute=1 state=absent
- name: create my cron
cron: name=“My Cron version 1.1” job=/usr/local/bin/cron.sh minute=1
The best way to handle this that I can think of is:
- review changes made to playbook, determine if they change any pre-existing files, crons, etc
- if changes to pre-existing files are made, duplicate corresponding tasks and add a state=absent entry with the old names, run playbook to remove old data
- remove duplicate tasks, commit changes to playbooks repository
Is there a better way for ansible to handle removing old data from a previous version of a playbook?
Thanks,
Andrew