Non-idempotence on template - reports changed each time - perhaps a problem with md5sum

I am having a small problem.

I am running Vagrant and am writing out a small configuration file using a template.

Each time I run it, the result shows changed.

I looked at the source to see what might get me to that point and all I could see is that the md5 might be different… except each time I run it, the md5 of the resultant file is identical.

Here is what is getting reported:

changed: [192.168.111.101] =>{

“changed”:true,
“dest”:“/opt/sweird/repo/src/sweird/local_settings.py”,
“gid”:1003,
“group”:“sweird”,
“item”:“”,
“md5sum”:“cf5991322069bae4258b4cb6fa8c5869”,
“mode”:“0644”,
“owner”:“sweird”,
“size”:2538,
“src”:“/home/vagrant/.ansible/tmp/ansible-1388360109.45-120659720431969/source”,
“state”:“file”,
“uid”:1001
}

And then if I go into the destination and run:

root@appserver1:/home/vagrant# md5sum /opt/sweird/repo/src/sweird/local_settings.py
cf5991322069bae4258b4cb6fa8c5869 /opt/sweird/repo/src/sweird/local_settings.py
root@appserver1:/home/vagrant#

What I am seeing here is that there is a message with the file name included in the output of the command.

This is consistent with the executed line (where it does a bunch of ORing):

EXEC COMMAND /bin/sh -c ‘sudo -k && sudo -H -S -p “[sudo via ansible, key=xwsjfftauthtycoxcqzhvizeizmuzhad] password: " -u root /bin/sh -c '”’“‘echo SUDO-SUCCESS-xwsjfftauthtycoxcqzhvizeizmuzhad; rc=0; [ -r “/opt/sweird/repo/src/sweird/local_settings.py” ] || rc=2; [ -f “/opt/sweird/repo/src/sweird/local_settings.py” ] || rc=1; [ -d “/opt/sweird/repo/src/sweird/local_settings.py” ] && rc=3; (/usr/bin/md5sum /opt/sweird/repo/src/sweird/local_settings.py 2>/dev/null) || (/sbin/md5sum -q /opt/sweird/repo/src/sweird/local_settings.py 2>/dev/null) || (/usr/bin/digest -a md5 /opt/sweird/repo/src/sweird/local_settings.py 2>/dev/null) || (/sbin/md5 -q /opt/sweird/repo/src/sweird/local_settings.py 2>/dev/null) || (/usr/bin/md5 -n /opt/sweird/repo/src/sweird/local_settings.py 2>/dev/null) || (/bin/md5 -q /opt/sweird/repo/src/sweird/local_settings.py 2>/dev/null) || (/usr/bin/csum -h MD5 /opt/sweird/repo/src/sweird/local_settings.py 2>/dev/null) || (echo “${rc} /opt/sweird/repo/src/sweird/local_settings.py”)’”‘"’’

Since the line in the code appears to only be wanting to grab the md5 of the resultant string and comparing it with what might be the md5 with the filename appended to it, there is a 100% chance that this will report changed 100% of the time.

I looked at the options for md5sum and tried a few things but always got the filename reported back.

Does this function need to look for the first space and hack off anything after it?

Thanks,
Christian

P.S. this is getting run against precise64 straight from vagrantup

It may be helpful to see the rest of your play, however, I ran into an issue like this once.

It turned out that the file I was templating was also in my git repo. My git task, was using force=yes to revert any local changes. This would cause git to overwrite my settings file on every run, and then the template task would repopulate.

Just a thought of something to look into.

Matt,

You are exactly correct - I discovered this fact shortly after I posted this message - too bad there is no ‘recall this message as it makes me look like an idiot’ function :slight_smile:

What this ultimately told me is that the recommended practice of vvvv is not 100% what I needed… I also needed the --diff as well to show me a bit more of what is going on.

I am considering making an edit to the docs to show this.

It would have saved me an hour.

Thanks for the info!

P.S. I moved the content of local_settings.py into the bottom of my settings file, removed the file from my repo and placed a try/catch around importing the missing file. All is good in the world now.

Yep, the template module is definitely reporting changed correctly, because we would have heard about this 1000x over by now if it were not :slight_smile:

–Michael