<p dir="auto">From <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/Plazik/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/Plazik">@Plazik</a> on 2016-11-03T13:19:28Z</p>

<h5 dir="auto">ISSUE TYPE</h5>

<ul dir="auto">
<li>Bug Report</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>

<p dir="auto">apt</p>
<h5 dir="auto">ANSIBLE VERSION</h5>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible 2.2.0.0
  config file = /home/vagrant/my/ansible.cfg
  configured module search path = Default w/o overrides
"><pre class="notranslate"><code class="notranslate">ansible 2.2.0.0
  config file = /home/vagrant/my/ansible.cfg
  configured module search path = Default w/o overrides

</code></pre></div>
<h5 dir="auto">CONFIGURATION</h5>

<p dir="auto">ansible.cfg:<br>
[defaults]<br>
hostfile = hosts</p>
<h5 dir="auto">OS / ENVIRONMENT</h5>

<p dir="auto">OS you are running Ansible from: Ubuntu 16.04<br>
OS you are managing: Ubuntu 16.04</p>
<h5 dir="auto">SUMMARY</h5>

<p dir="auto">After upgradig to ansible 2.2 I always get changes in apt module because it ignore <strong>cache_valid_time</strong> value.</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>


<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="test.yml:

---
- hosts: localvm
  become: yes

  tasks:
  - name: Only run &quot;update_cache=yes&quot; if the last one is more than 3600 seconds ago
    apt:
      update_cache: yes
      cache_valid_time: 3600


vagrant@ans-contrl:~/my$ ansible-playbook test.yml -vvv"><pre class="notranslate"><code class="notranslate">test.yml:

---
- hosts: localvm
  become: yes

  tasks:
  - name: Only run "update_cache=yes" if the last one is more than 3600 seconds ago
    apt:
      update_cache: yes
      cache_valid_time: 3600


vagrant@ans-contrl:~/my$ ansible-playbook test.yml -vvv
</code></pre></div>

<h5 dir="auto">EXPECTED RESULTS</h5>

<p dir="auto">Update apt cache on first run, skip updating cache on second run.</p>
<h5 dir="auto">ACTUAL RESULTS</h5>

<p dir="auto">Always changes.</p>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="vagrant@ans-contrl:~/my$ ansible-playbook test.yml -vvv
Using /home/vagrant/my/ansible.cfg as config file

PLAYBOOK: test.yml *************************************************************
1 plays in test.yml

PLAY [localvm] *****************************************************************

TASK [setup] *******************************************************************
Using module file /usr/lib/python2.7/dist-packages/ansible/modules/core/system/setup.py
&lt;192.168.60.4&gt; ESTABLISH SSH CONNECTION FOR USER: vagrant
&lt;192.168.60.4&gt; SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=vagrant -o ConnectTimeout=10 -o ControlPath=/home/vagrant/.ansible/cp/ansible-ssh-%h-%p-%r 192.168.60.4 '/bin/sh -c '&quot;'&quot;'( umask 77 &amp;&amp; mkdir -p &quot;` echo $HOME/.ansible/tmp/ansible-tmp-1478178800.59-26361197346329 `&quot; &amp;&amp; echo ansible-tmp-1478178800.59-26361197346329=&quot;` echo $HOME/.ansible/tmp/ansible-tmp-1478178800.59-26361197346329 `&quot; ) &amp;&amp; sleep 0'&quot;'&quot;''
&lt;192.168.60.4&gt; PUT /tmp/tmpGz1Eb9 TO /home/vagrant/.ansible/tmp/ansible-tmp-1478178800.59-26361197346329/setup.py
&lt;192.168.60.4&gt; SSH: EXEC sftp -b - -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=vagrant -o ConnectTimeout=10 -o ControlPath=/home/vagrant/.ansible/cp/ansible-ssh-%h-%p-%r '[192.168.60.4]'
&lt;192.168.60.4&gt; ESTABLISH SSH CONNECTION FOR USER: vagrant
&lt;192.168.60.4&gt; SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=vagrant -o ConnectTimeout=10 -o ControlPath=/home/vagrant/.ansible/cp/ansible-ssh-%h-%p-%r 192.168.60.4 '/bin/sh -c '&quot;'&quot;'chmod u+x /home/vagrant/.ansible/tmp/ansible-tmp-1478178800.59-26361197346329/ /home/vagrant/.ansible/tmp/ansible-tmp-1478178800.59-26361197346329/setup.py &amp;&amp; sleep 0'&quot;'&quot;''
&lt;192.168.60.4&gt; ESTABLISH SSH CONNECTION FOR USER: vagrant
&lt;192.168.60.4&gt; SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=vagrant -o ConnectTimeout=10 -o ControlPath=/home/vagrant/.ansible/cp/ansible-ssh-%h-%p-%r -tt 192.168.60.4 '/bin/sh -c '&quot;'&quot;'sudo -H -S -n -u root /bin/sh -c '&quot;'&quot;'&quot;'&quot;'&quot;'&quot;'&quot;'&quot;'echo BECOME-SUCCESS-bblyfpmawwxwihkyhdzgsrwimfkjlzuk; /usr/bin/python /home/vagrant/.ansible/tmp/ansible-tmp-1478178800.59-26361197346329/setup.py; rm -rf &quot;/home/vagrant/.ansible/tmp/ansible-tmp-1478178800.59-26361197346329/&quot; &gt; /dev/null 2&gt;&amp;1'&quot;'&quot;'&quot;'&quot;'&quot;'&quot;'&quot;'&quot;' &amp;&amp; sleep 0'&quot;'&quot;''
ok: [192.168.60.4]

TASK [Only run &quot;update_cache=yes&quot; if the last one is more than 3600 seconds ago] ***
task path: /home/vagrant/my/test.yml:6
Using module file /usr/lib/python2.7/dist-packages/ansible/modules/core/packaging/os/apt.py
&lt;192.168.60.4&gt; ESTABLISH SSH CONNECTION FOR USER: vagrant
&lt;192.168.60.4&gt; SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=vagrant -o ConnectTimeout=10 -o ControlPath=/home/vagrant/.ansible/cp/ansible-ssh-%h-%p-%r 192.168.60.4 '/bin/sh -c '&quot;'&quot;'( umask 77 &amp;&amp; mkdir -p &quot;` echo $HOME/.ansible/tmp/ansible-tmp-1478178801.29-209769775274469 `&quot; &amp;&amp; echo ansible-tmp-1478178801.29-209769775274469=&quot;` echo $HOME/.ansible/tmp/ansible-tmp-1478178801.29-209769775274469 `&quot; ) &amp;&amp; sleep 0'&quot;'&quot;''
&lt;192.168.60.4&gt; PUT /tmp/tmpb8HOiL TO /home/vagrant/.ansible/tmp/ansible-tmp-1478178801.29-209769775274469/apt.py
&lt;192.168.60.4&gt; SSH: EXEC sftp -b - -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=vagrant -o ConnectTimeout=10 -o ControlPath=/home/vagrant/.ansible/cp/ansible-ssh-%h-%p-%r '[192.168.60.4]'
&lt;192.168.60.4&gt; ESTABLISH SSH CONNECTION FOR USER: vagrant
&lt;192.168.60.4&gt; SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=vagrant -o ConnectTimeout=10 -o ControlPath=/home/vagrant/.ansible/cp/ansible-ssh-%h-%p-%r 192.168.60.4 '/bin/sh -c '&quot;'&quot;'chmod u+x /home/vagrant/.ansible/tmp/ansible-tmp-1478178801.29-209769775274469/ /home/vagrant/.ansible/tmp/ansible-tmp-1478178801.29-209769775274469/apt.py &amp;&amp; sleep 0'&quot;'&quot;''
&lt;192.168.60.4&gt; ESTABLISH SSH CONNECTION FOR USER: vagrant
&lt;192.168.60.4&gt; SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=vagrant -o ConnectTimeout=10 -o ControlPath=/home/vagrant/.ansible/cp/ansible-ssh-%h-%p-%r -tt 192.168.60.4 '/bin/sh -c '&quot;'&quot;'sudo -H -S -n -u root /bin/sh -c '&quot;'&quot;'&quot;'&quot;'&quot;'&quot;'&quot;'&quot;'echo BECOME-SUCCESS-soyskgemfitdsrhonujvdopjieqzexmq; /usr/bin/python /home/vagrant/.ansible/tmp/ansible-tmp-1478178801.29-209769775274469/apt.py; rm -rf &quot;/home/vagrant/.ansible/tmp/ansible-tmp-1478178801.29-209769775274469/&quot; &gt; /dev/null 2&gt;&amp;1'&quot;'&quot;'&quot;'&quot;'&quot;'&quot;'&quot;'&quot;' &amp;&amp; sleep 0'&quot;'&quot;''
changed: [192.168.60.4] =&gt; {
    &quot;cache_update_time&quot;: 1478170123,
    &quot;cache_updated&quot;: true,
    &quot;changed&quot;: true,
    &quot;invocation&quot;: {
        &quot;module_args&quot;: {
            &quot;allow_unauthenticated&quot;: false,
            &quot;autoremove&quot;: false,
            &quot;cache_valid_time&quot;: 3600,
            &quot;deb&quot;: null,
            &quot;default_release&quot;: null,
            &quot;dpkg_options&quot;: &quot;force-confdef,force-confold&quot;,
            &quot;force&quot;: false,
            &quot;install_recommends&quot;: null,
            &quot;only_upgrade&quot;: false,
            &quot;package&quot;: null,
            &quot;purge&quot;: false,
            &quot;state&quot;: &quot;present&quot;,
            &quot;update_cache&quot;: true,
            &quot;upgrade&quot;: null
        },
        &quot;module_name&quot;: &quot;apt&quot;
    }
}

PLAY RECAP *********************************************************************
192.168.60.4               : ok=2    changed=1    unreachable=0    failed=0

vagrant@ans-contrl:~/my$ ansible-playbook test.yml -vvv
Using /home/vagrant/my/ansible.cfg as config file

PLAYBOOK: test.yml *************************************************************
1 plays in test.yml

PLAY [localvm] *****************************************************************

TASK [setup] *******************************************************************
Using module file /usr/lib/python2.7/dist-packages/ansible/modules/core/system/setup.py
&lt;192.168.60.4&gt; ESTABLISH SSH CONNECTION FOR USER: vagrant
&lt;192.168.60.4&gt; SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=vagrant -o ConnectTimeout=10 -o ControlPath=/home/vagrant/.ansible/cp/ansible-ssh-%h-%p-%r 192.168.60.4 '/bin/sh -c '&quot;'&quot;'( umask 77 &amp;&amp; mkdir -p &quot;` echo $HOME/.ansible/tmp/ansible-tmp-1478178871.45-218992397586023 `&quot; &amp;&amp; echo ansible-tmp-1478178871.45-218992397586023=&quot;` echo $HOME/.ansible/tmp/ansible-tmp-1478178871.45-218992397586023 `&quot; ) &amp;&amp; sleep 0'&quot;'&quot;''
&lt;192.168.60.4&gt; PUT /tmp/tmpv9o0e3 TO /home/vagrant/.ansible/tmp/ansible-tmp-1478178871.45-218992397586023/setup.py
&lt;192.168.60.4&gt; SSH: EXEC sftp -b - -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=vagrant -o ConnectTimeout=10 -o ControlPath=/home/vagrant/.ansible/cp/ansible-ssh-%h-%p-%r '[192.168.60.4]'
&lt;192.168.60.4&gt; ESTABLISH SSH CONNECTION FOR USER: vagrant
&lt;192.168.60.4&gt; SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=vagrant -o ConnectTimeout=10 -o ControlPath=/home/vagrant/.ansible/cp/ansible-ssh-%h-%p-%r 192.168.60.4 '/bin/sh -c '&quot;'&quot;'chmod u+x /home/vagrant/.ansible/tmp/ansible-tmp-1478178871.45-218992397586023/ /home/vagrant/.ansible/tmp/ansible-tmp-1478178871.45-218992397586023/setup.py &amp;&amp; sleep 0'&quot;'&quot;''
&lt;192.168.60.4&gt; ESTABLISH SSH CONNECTION FOR USER: vagrant
&lt;192.168.60.4&gt; SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=vagrant -o ConnectTimeout=10 -o ControlPath=/home/vagrant/.ansible/cp/ansible-ssh-%h-%p-%r -tt 192.168.60.4 '/bin/sh -c '&quot;'&quot;'sudo -H -S -n -u root /bin/sh -c '&quot;'&quot;'&quot;'&quot;'&quot;'&quot;'&quot;'&quot;'echo BECOME-SUCCESS-lwuttqhzswvnqlvkfcbraivcbuceisuz; /usr/bin/python /home/vagrant/.ansible/tmp/ansible-tmp-1478178871.45-218992397586023/setup.py; rm -rf &quot;/home/vagrant/.ansible/tmp/ansible-tmp-1478178871.45-218992397586023/&quot; &gt; /dev/null 2&gt;&amp;1'&quot;'&quot;'&quot;'&quot;'&quot;'&quot;'&quot;'&quot;' &amp;&amp; sleep 0'&quot;'&quot;''
ok: [192.168.60.4]

TASK [Only run &quot;update_cache=yes&quot; if the last one is more than 3600 seconds ago] ***
task path: /home/vagrant/my/test.yml:6
Using module file /usr/lib/python2.7/dist-packages/ansible/modules/core/packaging/os/apt.py
&lt;192.168.60.4&gt; ESTABLISH SSH CONNECTION FOR USER: vagrant
&lt;192.168.60.4&gt; SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=vagrant -o ConnectTimeout=10 -o ControlPath=/home/vagrant/.ansible/cp/ansible-ssh-%h-%p-%r 192.168.60.4 '/bin/sh -c '&quot;'&quot;'( umask 77 &amp;&amp; mkdir -p &quot;` echo $HOME/.ansible/tmp/ansible-tmp-1478178872.37-148384000832646 `&quot; &amp;&amp; echo ansible-tmp-1478178872.37-148384000832646=&quot;` echo $HOME/.ansible/tmp/ansible-tmp-1478178872.37-148384000832646 `&quot; ) &amp;&amp; sleep 0'&quot;'&quot;''
&lt;192.168.60.4&gt; PUT /tmp/tmp3rCfzf TO /home/vagrant/.ansible/tmp/ansible-tmp-1478178872.37-148384000832646/apt.py
&lt;192.168.60.4&gt; SSH: EXEC sftp -b - -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=vagrant -o ConnectTimeout=10 -o ControlPath=/home/vagrant/.ansible/cp/ansible-ssh-%h-%p-%r '[192.168.60.4]'
&lt;192.168.60.4&gt; ESTABLISH SSH CONNECTION FOR USER: vagrant
&lt;192.168.60.4&gt; SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=vagrant -o ConnectTimeout=10 -o ControlPath=/home/vagrant/.ansible/cp/ansible-ssh-%h-%p-%r 192.168.60.4 '/bin/sh -c '&quot;'&quot;'chmod u+x /home/vagrant/.ansible/tmp/ansible-tmp-1478178872.37-148384000832646/ /home/vagrant/.ansible/tmp/ansible-tmp-1478178872.37-148384000832646/apt.py &amp;&amp; sleep 0'&quot;'&quot;''
&lt;192.168.60.4&gt; ESTABLISH SSH CONNECTION FOR USER: vagrant
&lt;192.168.60.4&gt; SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=vagrant -o ConnectTimeout=10 -o ControlPath=/home/vagrant/.ansible/cp/ansible-ssh-%h-%p-%r -tt 192.168.60.4 '/bin/sh -c '&quot;'&quot;'sudo -H -S -n -u root /bin/sh -c '&quot;'&quot;'&quot;'&quot;'&quot;'&quot;'&quot;'&quot;'echo BECOME-SUCCESS-xhjxsxornuzelhyvlsiksuindfcmjlpx; /usr/bin/python /home/vagrant/.ansible/tmp/ansible-tmp-1478178872.37-148384000832646/apt.py; rm -rf &quot;/home/vagrant/.ansible/tmp/ansible-tmp-1478178872.37-148384000832646/&quot; &gt; /dev/null 2&gt;&amp;1'&quot;'&quot;'&quot;'&quot;'&quot;'&quot;'&quot;'&quot;' &amp;&amp; sleep 0'&quot;'&quot;''
changed: [192.168.60.4] =&gt; {
    &quot;cache_update_time&quot;: 1478170123,
    &quot;cache_updated&quot;: true,
    &quot;changed&quot;: true,
    &quot;invocation&quot;: {
        &quot;module_args&quot;: {
            &quot;allow_unauthenticated&quot;: false,
            &quot;autoremove&quot;: false,
            &quot;cache_valid_time&quot;: 3600,
            &quot;deb&quot;: null,
            &quot;default_release&quot;: null,
            &quot;dpkg_options&quot;: &quot;force-confdef,force-confold&quot;,
            &quot;force&quot;: false,
            &quot;install_recommends&quot;: null,
            &quot;only_upgrade&quot;: false,
            &quot;package&quot;: null,
            &quot;purge&quot;: false,
            &quot;state&quot;: &quot;present&quot;,
            &quot;update_cache&quot;: true,
            &quot;upgrade&quot;: null
        },
        &quot;module_name&quot;: &quot;apt&quot;
    }
}

PLAY RECAP *********************************************************************
192.168.60.4               : ok=2    changed=1    unreachable=0    failed=0
"><pre class="notranslate"><code class="notranslate">vagrant@ans-contrl:~/my$ ansible-playbook test.yml -vvv
Using /home/vagrant/my/ansible.cfg as config file

PLAYBOOK: test.yml *************************************************************
1 plays in test.yml

PLAY [localvm] *****************************************************************

TASK [setup] *******************************************************************
Using module file /usr/lib/python2.7/dist-packages/ansible/modules/core/system/setup.py
&lt;192.168.60.4&gt; ESTABLISH SSH CONNECTION FOR USER: vagrant
&lt;192.168.60.4&gt; SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=vagrant -o ConnectTimeout=10 -o ControlPath=/home/vagrant/.ansible/cp/ansible-ssh-%h-%p-%r 192.168.60.4 '/bin/sh -c '"'"'( umask 77 &amp;&amp; mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1478178800.59-26361197346329 `" &amp;&amp; echo ansible-tmp-1478178800.59-26361197346329="` echo $HOME/.ansible/tmp/ansible-tmp-1478178800.59-26361197346329 `" ) &amp;&amp; sleep 0'"'"''
&lt;192.168.60.4&gt; PUT /tmp/tmpGz1Eb9 TO /home/vagrant/.ansible/tmp/ansible-tmp-1478178800.59-26361197346329/setup.py
&lt;192.168.60.4&gt; SSH: EXEC sftp -b - -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=vagrant -o ConnectTimeout=10 -o ControlPath=/home/vagrant/.ansible/cp/ansible-ssh-%h-%p-%r '[192.168.60.4]'
&lt;192.168.60.4&gt; ESTABLISH SSH CONNECTION FOR USER: vagrant
&lt;192.168.60.4&gt; SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=vagrant -o ConnectTimeout=10 -o ControlPath=/home/vagrant/.ansible/cp/ansible-ssh-%h-%p-%r 192.168.60.4 '/bin/sh -c '"'"'chmod u+x /home/vagrant/.ansible/tmp/ansible-tmp-1478178800.59-26361197346329/ /home/vagrant/.ansible/tmp/ansible-tmp-1478178800.59-26361197346329/setup.py &amp;&amp; sleep 0'"'"''
&lt;192.168.60.4&gt; ESTABLISH SSH CONNECTION FOR USER: vagrant
&lt;192.168.60.4&gt; SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=vagrant -o ConnectTimeout=10 -o ControlPath=/home/vagrant/.ansible/cp/ansible-ssh-%h-%p-%r -tt 192.168.60.4 '/bin/sh -c '"'"'sudo -H -S -n -u root /bin/sh -c '"'"'"'"'"'"'"'"'echo BECOME-SUCCESS-bblyfpmawwxwihkyhdzgsrwimfkjlzuk; /usr/bin/python /home/vagrant/.ansible/tmp/ansible-tmp-1478178800.59-26361197346329/setup.py; rm -rf "/home/vagrant/.ansible/tmp/ansible-tmp-1478178800.59-26361197346329/" &gt; /dev/null 2&gt;&amp;1'"'"'"'"'"'"'"'"' &amp;&amp; sleep 0'"'"''
ok: [192.168.60.4]

TASK [Only run "update_cache=yes" if the last one is more than 3600 seconds ago] ***
task path: /home/vagrant/my/test.yml:6
Using module file /usr/lib/python2.7/dist-packages/ansible/modules/core/packaging/os/apt.py
&lt;192.168.60.4&gt; ESTABLISH SSH CONNECTION FOR USER: vagrant
&lt;192.168.60.4&gt; SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=vagrant -o ConnectTimeout=10 -o ControlPath=/home/vagrant/.ansible/cp/ansible-ssh-%h-%p-%r 192.168.60.4 '/bin/sh -c '"'"'( umask 77 &amp;&amp; mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1478178801.29-209769775274469 `" &amp;&amp; echo ansible-tmp-1478178801.29-209769775274469="` echo $HOME/.ansible/tmp/ansible-tmp-1478178801.29-209769775274469 `" ) &amp;&amp; sleep 0'"'"''
&lt;192.168.60.4&gt; PUT /tmp/tmpb8HOiL TO /home/vagrant/.ansible/tmp/ansible-tmp-1478178801.29-209769775274469/apt.py
&lt;192.168.60.4&gt; SSH: EXEC sftp -b - -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=vagrant -o ConnectTimeout=10 -o ControlPath=/home/vagrant/.ansible/cp/ansible-ssh-%h-%p-%r '[192.168.60.4]'
&lt;192.168.60.4&gt; ESTABLISH SSH CONNECTION FOR USER: vagrant
&lt;192.168.60.4&gt; SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=vagrant -o ConnectTimeout=10 -o ControlPath=/home/vagrant/.ansible/cp/ansible-ssh-%h-%p-%r 192.168.60.4 '/bin/sh -c '"'"'chmod u+x /home/vagrant/.ansible/tmp/ansible-tmp-1478178801.29-209769775274469/ /home/vagrant/.ansible/tmp/ansible-tmp-1478178801.29-209769775274469/apt.py &amp;&amp; sleep 0'"'"''
&lt;192.168.60.4&gt; ESTABLISH SSH CONNECTION FOR USER: vagrant
&lt;192.168.60.4&gt; SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=vagrant -o ConnectTimeout=10 -o ControlPath=/home/vagrant/.ansible/cp/ansible-ssh-%h-%p-%r -tt 192.168.60.4 '/bin/sh -c '"'"'sudo -H -S -n -u root /bin/sh -c '"'"'"'"'"'"'"'"'echo BECOME-SUCCESS-soyskgemfitdsrhonujvdopjieqzexmq; /usr/bin/python /home/vagrant/.ansible/tmp/ansible-tmp-1478178801.29-209769775274469/apt.py; rm -rf "/home/vagrant/.ansible/tmp/ansible-tmp-1478178801.29-209769775274469/" &gt; /dev/null 2&gt;&amp;1'"'"'"'"'"'"'"'"' &amp;&amp; sleep 0'"'"''
changed: [192.168.60.4] =&gt; {
    "cache_update_time": 1478170123,
    "cache_updated": true,
    "changed": true,
    "invocation": {
        "module_args": {
            "allow_unauthenticated": false,
            "autoremove": false,
            "cache_valid_time": 3600,
            "deb": null,
            "default_release": null,
            "dpkg_options": "force-confdef,force-confold",
            "force": false,
            "install_recommends": null,
            "only_upgrade": false,
            "package": null,
            "purge": false,
            "state": "present",
            "update_cache": true,
            "upgrade": null
        },
        "module_name": "apt"
    }
}

PLAY RECAP *********************************************************************
192.168.60.4               : ok=2    changed=1    unreachable=0    failed=0

vagrant@ans-contrl:~/my$ ansible-playbook test.yml -vvv
Using /home/vagrant/my/ansible.cfg as config file

PLAYBOOK: test.yml *************************************************************
1 plays in test.yml

PLAY [localvm] *****************************************************************

TASK [setup] *******************************************************************
Using module file /usr/lib/python2.7/dist-packages/ansible/modules/core/system/setup.py
&lt;192.168.60.4&gt; ESTABLISH SSH CONNECTION FOR USER: vagrant
&lt;192.168.60.4&gt; SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=vagrant -o ConnectTimeout=10 -o ControlPath=/home/vagrant/.ansible/cp/ansible-ssh-%h-%p-%r 192.168.60.4 '/bin/sh -c '"'"'( umask 77 &amp;&amp; mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1478178871.45-218992397586023 `" &amp;&amp; echo ansible-tmp-1478178871.45-218992397586023="` echo $HOME/.ansible/tmp/ansible-tmp-1478178871.45-218992397586023 `" ) &amp;&amp; sleep 0'"'"''
&lt;192.168.60.4&gt; PUT /tmp/tmpv9o0e3 TO /home/vagrant/.ansible/tmp/ansible-tmp-1478178871.45-218992397586023/setup.py
&lt;192.168.60.4&gt; SSH: EXEC sftp -b - -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=vagrant -o ConnectTimeout=10 -o ControlPath=/home/vagrant/.ansible/cp/ansible-ssh-%h-%p-%r '[192.168.60.4]'
&lt;192.168.60.4&gt; ESTABLISH SSH CONNECTION FOR USER: vagrant
&lt;192.168.60.4&gt; SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=vagrant -o ConnectTimeout=10 -o ControlPath=/home/vagrant/.ansible/cp/ansible-ssh-%h-%p-%r 192.168.60.4 '/bin/sh -c '"'"'chmod u+x /home/vagrant/.ansible/tmp/ansible-tmp-1478178871.45-218992397586023/ /home/vagrant/.ansible/tmp/ansible-tmp-1478178871.45-218992397586023/setup.py &amp;&amp; sleep 0'"'"''
&lt;192.168.60.4&gt; ESTABLISH SSH CONNECTION FOR USER: vagrant
&lt;192.168.60.4&gt; SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=vagrant -o ConnectTimeout=10 -o ControlPath=/home/vagrant/.ansible/cp/ansible-ssh-%h-%p-%r -tt 192.168.60.4 '/bin/sh -c '"'"'sudo -H -S -n -u root /bin/sh -c '"'"'"'"'"'"'"'"'echo BECOME-SUCCESS-lwuttqhzswvnqlvkfcbraivcbuceisuz; /usr/bin/python /home/vagrant/.ansible/tmp/ansible-tmp-1478178871.45-218992397586023/setup.py; rm -rf "/home/vagrant/.ansible/tmp/ansible-tmp-1478178871.45-218992397586023/" &gt; /dev/null 2&gt;&amp;1'"'"'"'"'"'"'"'"' &amp;&amp; sleep 0'"'"''
ok: [192.168.60.4]

TASK [Only run "update_cache=yes" if the last one is more than 3600 seconds ago] ***
task path: /home/vagrant/my/test.yml:6
Using module file /usr/lib/python2.7/dist-packages/ansible/modules/core/packaging/os/apt.py
&lt;192.168.60.4&gt; ESTABLISH SSH CONNECTION FOR USER: vagrant
&lt;192.168.60.4&gt; SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=vagrant -o ConnectTimeout=10 -o ControlPath=/home/vagrant/.ansible/cp/ansible-ssh-%h-%p-%r 192.168.60.4 '/bin/sh -c '"'"'( umask 77 &amp;&amp; mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1478178872.37-148384000832646 `" &amp;&amp; echo ansible-tmp-1478178872.37-148384000832646="` echo $HOME/.ansible/tmp/ansible-tmp-1478178872.37-148384000832646 `" ) &amp;&amp; sleep 0'"'"''
&lt;192.168.60.4&gt; PUT /tmp/tmp3rCfzf TO /home/vagrant/.ansible/tmp/ansible-tmp-1478178872.37-148384000832646/apt.py
&lt;192.168.60.4&gt; SSH: EXEC sftp -b - -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=vagrant -o ConnectTimeout=10 -o ControlPath=/home/vagrant/.ansible/cp/ansible-ssh-%h-%p-%r '[192.168.60.4]'
&lt;192.168.60.4&gt; ESTABLISH SSH CONNECTION FOR USER: vagrant
&lt;192.168.60.4&gt; SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=vagrant -o ConnectTimeout=10 -o ControlPath=/home/vagrant/.ansible/cp/ansible-ssh-%h-%p-%r 192.168.60.4 '/bin/sh -c '"'"'chmod u+x /home/vagrant/.ansible/tmp/ansible-tmp-1478178872.37-148384000832646/ /home/vagrant/.ansible/tmp/ansible-tmp-1478178872.37-148384000832646/apt.py &amp;&amp; sleep 0'"'"''
&lt;192.168.60.4&gt; ESTABLISH SSH CONNECTION FOR USER: vagrant
&lt;192.168.60.4&gt; SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=vagrant -o ConnectTimeout=10 -o ControlPath=/home/vagrant/.ansible/cp/ansible-ssh-%h-%p-%r -tt 192.168.60.4 '/bin/sh -c '"'"'sudo -H -S -n -u root /bin/sh -c '"'"'"'"'"'"'"'"'echo BECOME-SUCCESS-xhjxsxornuzelhyvlsiksuindfcmjlpx; /usr/bin/python /home/vagrant/.ansible/tmp/ansible-tmp-1478178872.37-148384000832646/apt.py; rm -rf "/home/vagrant/.ansible/tmp/ansible-tmp-1478178872.37-148384000832646/" &gt; /dev/null 2&gt;&amp;1'"'"'"'"'"'"'"'"' &amp;&amp; sleep 0'"'"''
changed: [192.168.60.4] =&gt; {
    "cache_update_time": 1478170123,
    "cache_updated": true,
    "changed": true,
    "invocation": {
        "module_args": {
            "allow_unauthenticated": false,
            "autoremove": false,
            "cache_valid_time": 3600,
            "deb": null,
            "default_release": null,
            "dpkg_options": "force-confdef,force-confold",
            "force": false,
            "install_recommends": null,
            "only_upgrade": false,
            "package": null,
            "purge": false,
            "state": "present",
            "update_cache": true,
            "upgrade": null
        },
        "module_name": "apt"
    }
}

PLAY RECAP *********************************************************************
192.168.60.4               : ok=2    changed=1    unreachable=0    failed=0

</code></pre></div>
<p dir="auto">It seems <strong>cache_update_time</strong> didn't updated.<br>
Copied from original issue: <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="187057383" data-permission-text="Title is private" data-url="https://github.com/ansible/ansible-modules-core/issues/5468" data-hovercard-type="issue" data-hovercard-url="/ansible/ansible-modules-core/issues/5468/hovercard" href="https://github.com/ansible/ansible-modules-core/issues/5468">ansible/ansible-modules-core#5468</a></p>
<p dir="auto">From <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/ahes/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/ahes">@ahes</a> on 2016-11-08T16:10:24Z</p>
<h5 dir="auto">ISSUE TYPE</h5>
<ul dir="auto">
<li>Bug Report</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>
<p dir="auto">apt</p>
<h5 dir="auto">ANSIBLE VERSION</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible 2.2.0.0"><pre class="notranslate"><code class="notranslate">ansible 2.2.0.0
</code></pre></div>
<h5 dir="auto">CONFIGURATION</h5>
<p dir="auto">Default</p>
<h5 dir="auto">OS / ENVIRONMENT</h5>
<p dir="auto">Debian Jessie 64 GNU/Linux</p>
<h5 dir="auto">SUMMARY</h5>
<p dir="auto">When installing packages and using update_cache option apt module always returns state CHANGED even if packages are already installed.</p>
<p dir="auto">In my opinion expected behavior would be:</p>
<ol dir="auto">
<li>when using update_cache AND installing package(s) return status CHANGED only when package has been installed or updated, no matter if cache has been updated or not.</li>
<li>when using update_cache without installing any package(s) return status CHANGED when cache has been updated.</li>
</ol>
<h5 dir="auto">STEPS TO REPRODUCE</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="
---
- hosts: localhost
  gather_facts: no
  become: yes
  tasks:
    - apt:
        name: htop
        update_cache: yes"><pre class="notranslate"><code class="notranslate">
---
- hosts: localhost
  gather_facts: no
  become: yes
  tasks:
    - apt:
        name: htop
        update_cache: yes
</code></pre></div>
<h5 dir="auto">EXPECTED RESULTS</h5>
<p dir="auto">As in ansible 2.1:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="PLAY [localhost] ***************************************************************

TASK [apt] *********************************************************************
ok: [localhost]

PLAY RECAP *********************************************************************
localhost                  : ok=1    changed=0    unreachable=0    failed=0"><pre class="notranslate"><code class="notranslate">PLAY [localhost] ***************************************************************

TASK [apt] *********************************************************************
ok: [localhost]

PLAY RECAP *********************************************************************
localhost                  : ok=1    changed=0    unreachable=0    failed=0
</code></pre></div>
<p dir="auto">Part of debug output:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ok: [localhost] =&gt; {&quot;cache_update_time&quot;: 1478621386, &quot;cache_updated&quot;: true, &quot;changed&quot;: false, &quot;invocation&quot;: {&quot;module_args&quot;: {&quot;allow_unauthenticated&quot;: false, &quot;autoremove&quot;: false, &quot;cache_valid_time&quot;: null, &quot;deb&quot;: null, &quot;default_release&quot;: null, &quot;dpkg_options&quot;: &quot;force-confdef,force-confold&quot;, &quot;force&quot;: false, &quot;install_recommends&quot;: null, &quot;name&quot;: &quot;htop&quot;, &quot;only_upgrade&quot;: false, &quot;package&quot;: [&quot;htop&quot;], &quot;purge&quot;: false, &quot;state&quot;: &quot;present&quot;, &quot;update_cache&quot;: true, &quot;upgrade&quot;: null}, &quot;module_name&quot;: &quot;apt&quot;}}"><pre class="notranslate"><code class="notranslate">ok: [localhost] =&gt; {"cache_update_time": 1478621386, "cache_updated": true, "changed": false, "invocation": {"module_args": {"allow_unauthenticated": false, "autoremove": false, "cache_valid_time": null, "deb": null, "default_release": null, "dpkg_options": "force-confdef,force-confold", "force": false, "install_recommends": null, "name": "htop", "only_upgrade": false, "package": ["htop"], "purge": false, "state": "present", "update_cache": true, "upgrade": null}, "module_name": "apt"}}
</code></pre></div>
<h5 dir="auto">ACTUAL RESULTS</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="PLAY [localhost] ***************************************************************

TASK [apt] *********************************************************************
changed: [localhost]

PLAY RECAP *********************************************************************
localhost                  : ok=1    changed=1    unreachable=0    failed=0"><pre class="notranslate"><code class="notranslate">PLAY [localhost] ***************************************************************

TASK [apt] *********************************************************************
changed: [localhost]

PLAY RECAP *********************************************************************
localhost                  : ok=1    changed=1    unreachable=0    failed=0
</code></pre></div>
<p dir="auto">Part of debug output:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="changed: [localhost] =&gt; {
    &quot;cache_update_time&quot;: 1478621193,
    &quot;cache_updated&quot;: true,
    &quot;changed&quot;: true,
    &quot;invocation&quot;: {
        &quot;module_args&quot;: {
            &quot;allow_unauthenticated&quot;: false,
            &quot;autoremove&quot;: false,
            &quot;cache_valid_time&quot;: 0,
            &quot;deb&quot;: null,
            &quot;default_release&quot;: null,
            &quot;dpkg_options&quot;: &quot;force-confdef,force-confold&quot;,
            &quot;force&quot;: false,
            &quot;install_recommends&quot;: null,
            &quot;name&quot;: &quot;htop&quot;,
            &quot;only_upgrade&quot;: false,
            &quot;package&quot;: [
                &quot;htop&quot;
            ],
            &quot;purge&quot;: false,
            &quot;state&quot;: &quot;present&quot;,
            &quot;update_cache&quot;: true,
            &quot;upgrade&quot;: null
        },
        &quot;module_name&quot;: &quot;apt&quot;
    }
}"><pre class="notranslate"><code class="notranslate">changed: [localhost] =&gt; {
    "cache_update_time": 1478621193,
    "cache_updated": true,
    "changed": true,
    "invocation": {
        "module_args": {
            "allow_unauthenticated": false,
            "autoremove": false,
            "cache_valid_time": 0,
            "deb": null,
            "default_release": null,
            "dpkg_options": "force-confdef,force-confold",
            "force": false,
            "install_recommends": null,
            "name": "htop",
            "only_upgrade": false,
            "package": [
                "htop"
            ],
            "purge": false,
            "state": "present",
            "update_cache": true,
            "upgrade": null
        },
        "module_name": "apt"
    }
}
</code></pre></div>
<p dir="auto">Copied from original issue: <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="188033702" data-permission-text="Title is private" data-url="https://github.com/ansible/ansible-modules-core/issues/5532" data-hovercard-type="issue" data-hovercard-url="/ansible/ansible-modules-core/issues/5532/hovercard" href="https://github.com/ansible/ansible-modules-core/issues/5532">ansible/ansible-modules-core#5532</a></p>