Timing issue, installing a package and then modifying one of it's files...

134 views
Skip to first unread message

Adam Morris

unread,
Mar 4, 2014, 1:54:27 PM3/4/14
to ansible...@googlegroups.com
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

Michael DeHaan

unread,
Mar 4, 2014, 2:04:43 PM3/4/14
to ansible...@googlegroups.com
Do you think there's a background process spawned by sysstat that is modifying it's own cron job?




--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/0e705fd4-9cdc-4c1e-a90e-8f7607865295%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Adam Morris

unread,
Mar 4, 2014, 4:13:46 PM3/4/14
to ansible...@googlegroups.com


On Tuesday, March 4, 2014 11:04:43 AM UTC-8, Michael DeHaan wrote:
Do you think there's a background process spawned by sysstat that is modifying it's own cron job?


If there is it's fast enough that yum install sysstat && cat /etc/cron.d/sysstat gives me the results that I expect. It looks like the sysstat package includes a default /etc/cron.d/sysstat file that doesn't appear to change at any point.

I'm rather confused by this, unless the install task is returning before it's finished and I don't know why that would happen.

Adam

Adam Morris

unread,
Mar 4, 2014, 4:35:20 PM3/4/14
to ansible...@googlegroups.com
Running yum manually with rpmverbosity set to debug I can see that the /etc/cron.d/sysstat file is the first one that is deployed from the RPM and the only script appears to be a postinstall script that runs chkconfig. 

I'm trying a run with -vvv and dumping it to a file to see if I can see exactly where the issue lies.  

Adam


Adam Morris

unread,
Mar 10, 2014, 6:21:40 PM3/10/14
to ansible...@googlegroups.com
My stupidity was at fault...

There is originally a commented out line in the file that ALSO matches the regexp I was using.  So, my change was made to the second of two matching lines and not the first...  Kind of confusing when using insertbefore...

So I have...

example line 1
# line 2 example

and using line in file I insert "#Ansible test" before "line" and it gets put in between lines 1 and 2.  i.e. after line 1 and before line 2.

thus I end up with

example line 1
#Ansible test
# line 2 example

and not 

#Ansible test
example line 1
# line 2 example

as I was expecting...  that behaviour is clearly documented for regexp but it might be worth adding a note to "insertbefore" that it will insert before the LAST line that matches the regexp.

Adam


Reply all
Reply to author
Forward
0 new messages