Need help with Ansible Notify module: Handlers are not invoked even if template target file changes

Hi

I am using ansible-playbook version 1.8.2.

I have the following task in my ansible playbook that needs to invoke a set of handlers whenever the config file changes:

  • name: ceilometer proxy config

template: src=ceilometer_proxy_config.j2 dest=/usr/local/share/monitoring-channel-1_ceilometer_proxy_config mode=0777

notify:

  • restart monitoring-channel

I am observing that the actual file on the target machine changes, but ansible reports the whole operation as “changed: false” as shown below so that notify handlers are not getting invoked.

<10.0.0.3> EXEC ssh -C -tt -q -o ControlMaster=auto -o ControlPersist=60s -o ControlPath=“/root/.ansible/cp/ansible-ssh-%h-%p-%r” -o StrictHostKeyChecking=no -o IdentityFile="/opt/xos/synchronizers/m

onitoring_channel/sys/MonitoringChannel_1.key" -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=ubu

ntu -o ConnectTimeout=10 10.0.0.3 /bin/sh -c ‘sudo -k && sudo -H -S -p “[sudo via ansible, key=cdmmgwzmnomzpfikxmbzpqyxcoiiwlsy] password: " -u root /bin/sh -c '”’"'echo SUDO-SUCCESS-cdmmgwzmnomzpfik

xmbzpqyxcoiiwlsy; rc=flag; [ -r “/usr/local/share/monitoring-channel-1_ceilometer_proxy_config” ] || rc=2; [ -f “/usr/local/share/monitoring-channel-1_ceilometer_proxy_config” ] || rc=1; [ -d "/usr/l

ocal/share/monitoring-channel-1_ceilometer_proxy_config" ] && rc=3; python -V 2>/dev/null || rc=4; [ x"$rc" != “xflag” ] && echo “${rc} /usr/local/share/monitoring-channel-1_ceilometer_proxy_config”

&& exit 0; (python -c ‘"’“'”‘"’“'”‘"’“'import hashlib; print(hashlib.sha1(open(”/usr/local/share/monitoring-channel-1_ceilometer_proxy_config", “rb”).read()).hexdigest())‘"’“'”‘"’“'”‘"’"’ 2>/dev/null

) || (python -c ‘"’“'”‘"’“'”‘"’“'import sha; print(sha.sha(open(”/usr/local/share/monitoring-channel-1_ceilometer_proxy_config", “rb”).read()).hexdigest())‘"’“'”‘"’“'”‘"’"’ 2>/dev/null) || (echo "0 /

usr/local/share/monitoring-channel-1_ceilometer_proxy_config")‘"’"‘’

<10.0.0.3> EXEC ssh -C -q -o ControlMaster=auto -o ControlPersist=60s -o ControlPath=“/root/.ansible/cp/ansible-ssh-%h-%p-%r” -o StrictHostKeyChecking=no -o IdentityFile="/opt/xos/synchronizers/monit

oring_channel/sys/MonitoringChannel_1.key" -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=ubuntu

-o ConnectTimeout=10 10.0.0.3 /bin/sh -c ‘sudo -k && sudo -H -S -p “[sudo via ansible, key=vclkghiatnbspgrortpgrtspkuxxaxya] password: " -u root /bin/sh -c '”’"'echo SUDO-SUCCESS-vclkghiatnbspgrortpg

rtspkuxxaxya; LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /usr/bin/python ; rm -rf /home/ubuntu/.ansible/tmp/ansible-tmp-1462993325.34-125201446134255/ >/dev/null 2>&1’“'”‘’

ok: [10.0.0.3] => {“changed”: false, “gid”: 0, “group”: “root”, “mode”: “0777”, “owner”: “root”, “path”: “/usr/local/share/monitoring-channel-1_ceilometer_proxy_config”, “size”: 389, “state”: “file”,

“uid”: 0}

Not sure why the “changed” flag is false even though the file content is changing on the target machine. For ex:

Before file change, the following is the timestamp of the file:

ubuntu@mysite-ceilometer-1:~$ ls -alrt /usr/local/share/

total 28

-rwxrwxrwx 1 root root 389 May 11 18:52 monitoring-channel-1_ceilometer_proxy_config

drwxr-xr-x 6 root root 4096 May 11 18:52 .

And after change of the file:

ubuntu@mysite-ceilometer-1:~$ ls -alrt /usr/local/share/

total 28

-rwxrwxrwx 1 root root 422 May 11 19:11 monitoring-channel-1_ceilometer_proxy_config

drwxr-xr-x 6 root root 4096 May 11 19:11 .

I have even compared the hash of files using the same commands (hashlib.sha1, sha.sha) before and after change which is indeed different.

Could any one help me with this issue and how I can troubleshoot what is going wrong here? Plz let me know if you need more details.

Thanks

Srikanth

Go to your target host, move the file to
monitoring-channel-1_ceilometer_proxy_config.TEST and rerun your
playbook. As the file does not exist before, it should return changed.

Compare the two files. Is there any difference?

I was thinking maybe the only difference is a {{ ansible_managed }}
inside the file that is being changed. If this is the only difference,
ansible might report the file as unchanged, even if the timestamp is
changed inside the file. Just a wild guess.

Johannes

Hi

Thanks for your response. I will try this and let you know.

From the file content wise, I have verified it before if the file is really changing or not and it was changing… The file looked like the following before change:

This file autogenerated by monitoring-channel observer

It contains a list of attributes to be used by ceilometer proxy web server

syntax: key=value

[default]
auth_url=http://130.127.133.58:5000/v2.0
admin_user=admin
admin_tenant=admin
admin_password=d1am0nd
ceilometer_pub_sub_url=http://130.127.133.58:4455/

[allowed_tenants]
57fc48675c384d4ca547a59e9d44b053
default_admin_tenant

And after change, it is (There is one new entry getting added in to the file as highlighted in RED below):

This file autogenerated by monitoring-channel observer

It contains a list of attributes to be used by ceilometer proxy web server

syntax: key=value

[default]
auth_url=http://130.127.133.58:5000/v2.0
admin_user=admin
admin_tenant=admin
admin_password=d1am0nd
ceilometer_pub_sub_url=http://130.127.133.58:4455/

[allowed_tenants]
57fc48675c384d4ca547a59e9d44b053
36df52d6b22e4b29b87ed7ab9bb78d64
default_admin_tenant

Thanks
Srikanth