I have come across an unusual timing issue... I'm not sure what is causing it but it is repeatable...
Here is a single task file from part of my initial set up... (I've removed the AIX and 32 bit variants but they are interspersed with the 64 bit RedHat version.
---
# file: roles/common/tasks/sar.yml
# Ensure that the necessary package is installed on RedHat
- name: ensure that the sysstat package is installed for RedHat based systems
yum: name="sysstat" state=present
when: ansible_os_family == "RedHat"
# Add an entry to the cron file to make sure that the line only occurs once
- name: Verify the crontab file is managed by Ansible
lineinfile: 'backup=no dest=/etc/cron.d/sysstat state=present
line="#Ansible: sar" insertbefore="/usr/lib64/sa/sa1"'
when: ansible_os_family == "RedHat" and ansible_userspace_bits == "64"
# Now modify the cron.d file to check output every ten minutes.
# cron either has inotify support, or checks certain locations for changes
# every minute. Either way, no notification is needed.
- name: modify the cron.d file to run sar every ten minutes for RedHat
cron: name="sar" backup=no cron_file=sysstat state=present user={{root_user}}
job="/usr/lib64/sa/sa1 600 1" minute="*/10"
when: ansible_os_family == "RedHat" and ansible_userspace_bits == "64"
So, when I run this as part of a larger playbook I get the following behaviour (and no errors)
If sysstat is already installed the /etc/cron.d/sysstat file is modified to add the Ansible tag before the existing (default) line and then the cron job is modified to look the way that I want it. This is what I would expect.
If I run the play again nothing changes. Again this is what I expect.
If sysstat is not installed then it is installed (as expected) and the sysstat file is modified to add the new cron job. But the old one is not tagged so I end up with two similar entries in the file.
I could add a deliberate delay in here between installing sysstat and modifying the cron job, but I haven't yet. I'm wondering why I am seeing the behaviour that I see.
Any thoughts?
Adam