<p dir="auto">Ansible: 1.9.4</p>
<p dir="auto">Task is always changed:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="- name: install /etc/timezone
  copy: content=&quot;{{ timezone }}&quot; dest=/etc/timezone mode=0644 owner=root group=root
  notify: update tzdata
  tags: timezone"><pre class="notranslate"><code class="notranslate">- name: install /etc/timezone
  copy: content="{{ timezone }}" dest=/etc/timezone mode=0644 owner=root group=root
  notify: update tzdata
  tags: timezone
</code></pre></div>
<p dir="auto">Works as intended:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="- name: install /etc/timezone
  copy: content=&quot;{{ timezone }}\n&quot; dest=/etc/timezone mode=0644 owner=root group=root
  notify: update tzdata
  tags: timezone"><pre class="notranslate"><code class="notranslate">- name: install /etc/timezone
  copy: content="{{ timezone }}\n" dest=/etc/timezone mode=0644 owner=root group=root
  notify: update tzdata
  tags: timezone
</code></pre></div>
<p dir="auto">Same problem occurs if I use template module with template <code class="notranslate">{{ timezone }}</code> (no new line symbol).</p>
<p dir="auto">Problem seems to exist since 2013: <a href="https://gist.github.com/garethrees/5591027">https://gist.github.com/garethrees/5591027</a></p>
<h5 dir="auto">Issue Type:</h5>
<p dir="auto">Bug Report</p>
<h5 dir="auto">Ansible Version:</h5>
<p dir="auto">ansible 1.7 (devel <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/ansible/ansible/commit/8646cc798897dd74055f509c2a9050b2dba4e42e/hovercard" href="https://github.com/ansible/ansible/commit/8646cc798897dd74055f509c2a9050b2dba4e42e"><tt>8646cc7</tt></a>) last updated 2014/08/04 22:04:49 (GMT -200)</p>
<h5 dir="auto">Environment:</h5>
<p dir="auto">MacOS 10.9.4</p>
<h5 dir="auto">Summary:</h5>
<p dir="auto">The copy module is not correctly identifying if the file has been changed when the "content" option is used instead of "src".</p>
<h5 dir="auto">Steps To Reproduce:</h5>
<p dir="auto">A task as described will always notify the handler even though when the file has not been changed and matches exactly the value of the "content" option.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="  tasks:
  - name: set time zone
    copy: content=&quot;America/Sao_Paulo&quot; dest=/etc/timezone
          owner=root group=root mode=0644
    notify:
    - update timezone

  handlers:
  - name: update timezone
    command: dpkg-reconfigure --frontend noninteractive tzdata"><pre class="notranslate"><code class="notranslate">  tasks:
  - name: set time zone
    copy: content="America/Sao_Paulo" dest=/etc/timezone
          owner=root group=root mode=0644
    notify:
    - update timezone

  handlers:
  - name: update timezone
    command: dpkg-reconfigure --frontend noninteractive tzdata
</code></pre></div>
<p dir="auto">Possibly an issue on how the MD5 hash is being calculated. I noticed that the output of the ansible-playbook states a hash that does not match either the file or the value of the "content" option.</p>
<h5 dir="auto">Expected Results:</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="TASK: [set time zone] ********************************************************* 
ok: [10.52.20.106] =&gt; {&quot;changed&quot;: false, &quot;dest&quot;: &quot;/etc/timezone&quot;, &quot;gid&quot;: 0, &quot;group&quot;: &quot;root&quot;, &quot;md5sum&quot;: &quot;1c978baa6e3453cca63bcbed6d20d232&quot;, &quot;mode&quot;: &quot;0644&quot;, &quot;msg&quot;: &quot;could not write content temp file: global name 'self' is not defined&quot;, &quot;owner&quot;: &quot;root&quot;, &quot;size&quot;: 18, &quot;src&quot;: &quot;&quot;, &quot;state&quot;: &quot;file&quot;, &quot;uid&quot;: 0}"><pre class="notranslate"><code class="notranslate">TASK: [set time zone] ********************************************************* 
ok: [10.52.20.106] =&gt; {"changed": false, "dest": "/etc/timezone", "gid": 0, "group": "root", "md5sum": "1c978baa6e3453cca63bcbed6d20d232", "mode": "0644", "msg": "could not write content temp file: global name 'self' is not defined", "owner": "root", "size": 18, "src": "", "state": "file", "uid": 0}
</code></pre></div>
<h5 dir="auto">Actual Results:</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="TASK: [set time zone] ********************************************************* 
changed: [10.52.20.106] =&gt; {&quot;changed&quot;: true, &quot;dest&quot;: &quot;/etc/timezone&quot;, &quot;gid&quot;: 0, &quot;group&quot;: &quot;root&quot;, &quot;md5sum&quot;: &quot;1c978baa6e3453cca63bcbed6d20d232&quot;, &quot;mode&quot;: &quot;0644&quot;, &quot;owner&quot;: &quot;root&quot;, &quot;size&quot;: 17, &quot;src&quot;: &quot;/root/.ansible/tmp/ansible-tmp-1407201133.17-273344189894207/source&quot;, &quot;state&quot;: &quot;file&quot;, &quot;uid&quot;: 0}

NOTIFIED: [update timezone] *************************************************** 
changed: [10.52.20.106] =&gt; {&quot;changed&quot;: true, &quot;cmd&quot;: [&quot;dpkg-reconfigure&quot;, &quot;--frontend&quot;, &quot;noninteractive&quot;, &quot;tzdata&quot;], &quot;delta&quot;: &quot;0:00:00.974934&quot;, &quot;end&quot;: &quot;2014-08-04 22:12:27.138238&quot;, &quot;rc&quot;: 0, &quot;start&quot;: &quot;2014-08-04 22:12:26.163304&quot;, &quot;stderr&quot;: &quot;\nCurrent default time zone: 'America/Sao_Paulo'\nLocal time is now:      Mon Aug  4 22:12:26 BRT 2014.\nUniversal Time is now:  Tue Aug  5 01:12:26 UTC 2014.&quot;, &quot;stdout&quot;: &quot;&quot;}"><pre class="notranslate"><code class="notranslate">TASK: [set time zone] ********************************************************* 
changed: [10.52.20.106] =&gt; {"changed": true, "dest": "/etc/timezone", "gid": 0, "group": "root", "md5sum": "1c978baa6e3453cca63bcbed6d20d232", "mode": "0644", "owner": "root", "size": 17, "src": "/root/.ansible/tmp/ansible-tmp-1407201133.17-273344189894207/source", "state": "file", "uid": 0}

NOTIFIED: [update timezone] *************************************************** 
changed: [10.52.20.106] =&gt; {"changed": true, "cmd": ["dpkg-reconfigure", "--frontend", "noninteractive", "tzdata"], "delta": "0:00:00.974934", "end": "2014-08-04 22:12:27.138238", "rc": 0, "start": "2014-08-04 22:12:26.163304", "stderr": "\nCurrent default time zone: 'America/Sao_Paulo'\nLocal time is now:      Mon Aug  4 22:12:26 BRT 2014.\nUniversal Time is now:  Tue Aug  5 01:12:26 UTC 2014.", "stdout": ""}
</code></pre></div>