<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>
<p dir="auto">So I have some playbooks here:  <a href="https://github.com/jsmartin/ansible-examples/tree/riak/riak">https://github.com/jsmartin/ansible-examples/tree/riak/riak</a></p>
<p dir="auto">As you will see, notifies for 10.42.0.6 seem to be ocurring twice.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible-playbook  -u vagrant site.yml -i ~/work/vms/ansible-riak/hosts -k
SSH password: 

PLAY [riak_cluster] *********************************************************** 

GATHERING FACTS *************************************************************** 
ok: [10.42.0.7]
ok: [10.42.0.8]
ok: [10.42.0.6]

TASK: [update pam configuration] ********************************************** 
changed: [10.42.0.8]
changed: [10.42.0.6]
changed: [10.42.0.7]

TASK: [mount the riak volume with optmized settings] ************************** 
changed: [10.42.0.8]
changed: [10.42.0.7]
changed: [10.42.0.6]

TASK: [remount the partition] ************************************************* 
changed: [10.42.0.8]
changed: [10.42.0.6]
changed: [10.42.0.7]

TASK: [confgure rc.local] ***************************************************** 
changed: [10.42.0.6]
changed: [10.42.0.8]
changed: [10.42.0.7]

TASK: [create sysctl.d] ******************************************************* 
ok: [10.42.0.6]
ok: [10.42.0.8]
ok: [10.42.0.7]

TASK: [configure sysctl] ****************************************************** 
changed: [10.42.0.6]
changed: [10.42.0.7]
changed: [10.42.0.8]

TASK: [update system ulimit settings] ***************************************** 
ok: [10.42.0.7]
ok: [10.42.0.8]
ok: [10.42.0.6]

NOTIFIED: [update sysctl] ***************************************************** 
changed: [10.42.0.6]
changed: [10.42.0.7]
changed: [10.42.0.8]

NOTIFIED: [source rclocal] **************************************************** 
changed: [10.42.0.8]
changed: [10.42.0.6]
changed: [10.42.0.7]

TASK: [group_by key={{ansible_distribution}}] ********************************* 
changed: [10.42.0.6]

NOTIFIED: [update sysctl] ***************************************************** 
changed: [10.42.0.6]

NOTIFIED: [source rclocal] **************************************************** 
changed: [10.42.0.6]

PLAY [Ubuntu] ***************************************************************** 

TASK: [set the riak ulimit] *************************************************** 
changed: [10.42.0.6]
changed: [10.42.0.7]
changed: [10.42.0.8]

TASK: [update pam configuration] ********************************************** 
changed: [10.42.0.8] =&gt; (item=/etc/pam.d/common-session)
changed: [10.42.0.6] =&gt; (item=/etc/pam.d/common-session)
changed: [10.42.0.7] =&gt; (item=/etc/pam.d/common-session)
changed: [10.42.0.8] =&gt; (item=/etc/pam.d/common-session-noninteractive)
changed: [10.42.0.6] =&gt; (item=/etc/pam.d/common-session-noninteractive)
changed: [10.42.0.7] =&gt; (item=/etc/pam.d/common-session-noninteractive)

TASK: [get the basho apt key] ************************************************* 
changed: [10.42.0.8]
changed: [10.42.0.6]
changed: [10.42.0.7]

TASK: [configure the basho repository] **************************************** 
changed: [10.42.0.6]
changed: [10.42.0.8]
changed: [10.42.0.7]

TASK: [install riak] ********************************************************** 
changed: [10.42.0.6]
changed: [10.42.0.8]
changed: [10.42.0.7]

TASK: [configure iptables] **************************************************** 
changed: [10.42.0.7]
changed: [10.42.0.6]
changed: [10.42.0.8]

NOTIFIED: [restore iptables] ************************************************** 
changed: [10.42.0.8]
changed: [10.42.0.6]
changed: [10.42.0.7]

NOTIFIED: [restore iptables] ************************************************** 
changed: [10.42.0.6]

PLAY [CentOS] ***************************************************************** 
skipping: no hosts matched

PLAY [riak_cluster] *********************************************************** 

TASK: [configure app.config] ************************************************** 
changed: [10.42.0.6]
changed: [10.42.0.8]
changed: [10.42.0.7]

TASK: [configure vm.args] ***************************************************** 
changed: [10.42.0.6]
changed: [10.42.0.7]
changed: [10.42.0.8]

TASK: [start riak] ************************************************************ 
changed: [10.42.0.7]
changed: [10.42.0.6]
changed: [10.42.0.8]

TASK: [wait for port to become active] **************************************** 
ok: [10.42.0.7]
ok: [10.42.0.6]
ok: [10.42.0.8]

TASK: [wait for riak_kv service to start] ************************************* 
ok: [10.42.0.8]
ok: [10.42.0.6]
ok: [10.42.0.7]

NOTIFIED: [restart riak] ****************************************************** 
changed: [10.42.0.7]
changed: [10.42.0.8]
changed: [10.42.0.6]

NOTIFIED: [wait for http] ***************************************************** 
ok: [10.42.0.8]
ok: [10.42.0.6]
ok: [10.42.0.7]

NOTIFIED: [wait for kv] ******************************************************* 
ok: [10.42.0.7]
ok: [10.42.0.6]
ok: [10.42.0.8]

NOTIFIED: [restart riak] ****************************************************** 
changed: [10.42.0.6]

NOTIFIED: [wait for http] ***************************************************** 
ok: [10.42.0.6]

NOTIFIED: [wait for kv] ******************************************************* 
ok: [10.42.0.6]

PLAY [riak_cluster] *********************************************************** 

TASK: [Create a group based on riak node type.] ******************************* 
changed: [10.42.0.6]

TASK: [collect riak facts] **************************************************** 
ok: [10.42.0.8]
ok: [10.42.0.6]
ok: [10.42.0.7]

PLAY [middle:last] ************************************************************ 

TASK: [debug msg='primary {{hostvars[groups['primary'][0]]['riak_outputs']['node_name']}}'] *** 
ok: [10.42.0.7]
ok: [10.42.0.8]

TASK: [join riak cluster] ***************************************************** 
changed: [10.42.0.8]
changed: [10.42.0.7]

PLAY [last] ******************************************************************* 

TASK: [plan cluster changes] ************************************************** 
changed: [10.42.0.8]

NOTIFIED: [commit cluster changes] ******************************************** 
&lt;job 374120038072&gt; polling, 590s remaining
&lt;job 374120038072&gt; polling, 580s remaining
&lt;job 374120038072&gt; polling, 570s remaining
&lt;job 374120038072&gt; polling, 560s remaining
&lt;job 374120038072&gt; polling, 550s remaining
&lt;job 374120038072&gt; polling, 540s remaining
&lt;job 374120038072&gt; polling, 530s remaining
ok: [10.42.0.8]
&lt;job 374120038072&gt; finished on 10.42.0.8

PLAY RECAP ******************************************************************** 
10.42.0.6                  : ok=34   changed=24   unreachable=0    failed=0   
10.42.0.7                  : ok=30   changed=21   unreachable=0    failed=0   
10.42.0.8                  : ok=33   changed=22   unreachable=0    failed=0   "><pre class="notranslate"><code class="notranslate">ansible-playbook  -u vagrant site.yml -i ~/work/vms/ansible-riak/hosts -k
SSH password: 

PLAY [riak_cluster] *********************************************************** 

GATHERING FACTS *************************************************************** 
ok: [10.42.0.7]
ok: [10.42.0.8]
ok: [10.42.0.6]

TASK: [update pam configuration] ********************************************** 
changed: [10.42.0.8]
changed: [10.42.0.6]
changed: [10.42.0.7]

TASK: [mount the riak volume with optmized settings] ************************** 
changed: [10.42.0.8]
changed: [10.42.0.7]
changed: [10.42.0.6]

TASK: [remount the partition] ************************************************* 
changed: [10.42.0.8]
changed: [10.42.0.6]
changed: [10.42.0.7]

TASK: [confgure rc.local] ***************************************************** 
changed: [10.42.0.6]
changed: [10.42.0.8]
changed: [10.42.0.7]

TASK: [create sysctl.d] ******************************************************* 
ok: [10.42.0.6]
ok: [10.42.0.8]
ok: [10.42.0.7]

TASK: [configure sysctl] ****************************************************** 
changed: [10.42.0.6]
changed: [10.42.0.7]
changed: [10.42.0.8]

TASK: [update system ulimit settings] ***************************************** 
ok: [10.42.0.7]
ok: [10.42.0.8]
ok: [10.42.0.6]

NOTIFIED: [update sysctl] ***************************************************** 
changed: [10.42.0.6]
changed: [10.42.0.7]
changed: [10.42.0.8]

NOTIFIED: [source rclocal] **************************************************** 
changed: [10.42.0.8]
changed: [10.42.0.6]
changed: [10.42.0.7]

TASK: [group_by key={{ansible_distribution}}] ********************************* 
changed: [10.42.0.6]

NOTIFIED: [update sysctl] ***************************************************** 
changed: [10.42.0.6]

NOTIFIED: [source rclocal] **************************************************** 
changed: [10.42.0.6]

PLAY [Ubuntu] ***************************************************************** 

TASK: [set the riak ulimit] *************************************************** 
changed: [10.42.0.6]
changed: [10.42.0.7]
changed: [10.42.0.8]

TASK: [update pam configuration] ********************************************** 
changed: [10.42.0.8] =&gt; (item=/etc/pam.d/common-session)
changed: [10.42.0.6] =&gt; (item=/etc/pam.d/common-session)
changed: [10.42.0.7] =&gt; (item=/etc/pam.d/common-session)
changed: [10.42.0.8] =&gt; (item=/etc/pam.d/common-session-noninteractive)
changed: [10.42.0.6] =&gt; (item=/etc/pam.d/common-session-noninteractive)
changed: [10.42.0.7] =&gt; (item=/etc/pam.d/common-session-noninteractive)

TASK: [get the basho apt key] ************************************************* 
changed: [10.42.0.8]
changed: [10.42.0.6]
changed: [10.42.0.7]

TASK: [configure the basho repository] **************************************** 
changed: [10.42.0.6]
changed: [10.42.0.8]
changed: [10.42.0.7]

TASK: [install riak] ********************************************************** 
changed: [10.42.0.6]
changed: [10.42.0.8]
changed: [10.42.0.7]

TASK: [configure iptables] **************************************************** 
changed: [10.42.0.7]
changed: [10.42.0.6]
changed: [10.42.0.8]

NOTIFIED: [restore iptables] ************************************************** 
changed: [10.42.0.8]
changed: [10.42.0.6]
changed: [10.42.0.7]

NOTIFIED: [restore iptables] ************************************************** 
changed: [10.42.0.6]

PLAY [CentOS] ***************************************************************** 
skipping: no hosts matched

PLAY [riak_cluster] *********************************************************** 

TASK: [configure app.config] ************************************************** 
changed: [10.42.0.6]
changed: [10.42.0.8]
changed: [10.42.0.7]

TASK: [configure vm.args] ***************************************************** 
changed: [10.42.0.6]
changed: [10.42.0.7]
changed: [10.42.0.8]

TASK: [start riak] ************************************************************ 
changed: [10.42.0.7]
changed: [10.42.0.6]
changed: [10.42.0.8]

TASK: [wait for port to become active] **************************************** 
ok: [10.42.0.7]
ok: [10.42.0.6]
ok: [10.42.0.8]

TASK: [wait for riak_kv service to start] ************************************* 
ok: [10.42.0.8]
ok: [10.42.0.6]
ok: [10.42.0.7]

NOTIFIED: [restart riak] ****************************************************** 
changed: [10.42.0.7]
changed: [10.42.0.8]
changed: [10.42.0.6]

NOTIFIED: [wait for http] ***************************************************** 
ok: [10.42.0.8]
ok: [10.42.0.6]
ok: [10.42.0.7]

NOTIFIED: [wait for kv] ******************************************************* 
ok: [10.42.0.7]
ok: [10.42.0.6]
ok: [10.42.0.8]

NOTIFIED: [restart riak] ****************************************************** 
changed: [10.42.0.6]

NOTIFIED: [wait for http] ***************************************************** 
ok: [10.42.0.6]

NOTIFIED: [wait for kv] ******************************************************* 
ok: [10.42.0.6]

PLAY [riak_cluster] *********************************************************** 

TASK: [Create a group based on riak node type.] ******************************* 
changed: [10.42.0.6]

TASK: [collect riak facts] **************************************************** 
ok: [10.42.0.8]
ok: [10.42.0.6]
ok: [10.42.0.7]

PLAY [middle:last] ************************************************************ 

TASK: [debug msg='primary {{hostvars[groups['primary'][0]]['riak_outputs']['node_name']}}'] *** 
ok: [10.42.0.7]
ok: [10.42.0.8]

TASK: [join riak cluster] ***************************************************** 
changed: [10.42.0.8]
changed: [10.42.0.7]

PLAY [last] ******************************************************************* 

TASK: [plan cluster changes] ************************************************** 
changed: [10.42.0.8]

NOTIFIED: [commit cluster changes] ******************************************** 
&lt;job 374120038072&gt; polling, 590s remaining
&lt;job 374120038072&gt; polling, 580s remaining
&lt;job 374120038072&gt; polling, 570s remaining
&lt;job 374120038072&gt; polling, 560s remaining
&lt;job 374120038072&gt; polling, 550s remaining
&lt;job 374120038072&gt; polling, 540s remaining
&lt;job 374120038072&gt; polling, 530s remaining
ok: [10.42.0.8]
&lt;job 374120038072&gt; finished on 10.42.0.8

PLAY RECAP ******************************************************************** 
10.42.0.6                  : ok=34   changed=24   unreachable=0    failed=0   
10.42.0.7                  : ok=30   changed=21   unreachable=0    failed=0   
10.42.0.8                  : ok=33   changed=22   unreachable=0    failed=0   
</code></pre></div>