copy module: task is getting marked as 'changed' on every run

Hi,

I have this task:

  • name: set Location for timezone
    copy: src=timezone dest=/etc/timezone
    owner=root
    group=root
    mode=0644
    notify:
  • update timezone

My problem is it is updating the file on every run even though the file has not changed:

TASK: [common | set timezone variables] ***************************************
changed: [host1]
changed: [host2]
changed: [host3]

NOTIFIED: [common | update timezone] ******************************************
changed: [host1]
changed: [host2]
changed: [host3]

PLAY RECAP ********************************************************************
host1 : ok=6 changed=2 unreachable=0 failed=0
host2 : ok=6 changed=2 unreachable=0 failed=0
host3 : ok=6 changed=2 unreachable=0 failed=0

How do I get it to change the file only if it has changed? I tried it with both 1.5 and 1.4.4 versions

Likely your ‘update timezone’ handler, which I will guess is calling dpkg-reconfigure, causes the file to change slightly.

Try running with --diff. Make sure your ‘timezone’ file has a trailing new line. Also maybe show us your handler and the contents of your timezone file.

The following discussion may also be of benefit:

https://github.com/ansible/ansible/issues/5715

That was exactly the case thank you very much for your prompt response!