Issue 1:
From @Plazik on 2016-11-03T13:19:28Z

ISSUE TYPE

Bug Report

COMPONENT NAME

apt

ANSIBLE VERSION

ansible 2.2.0.0
config file = /home/vagrant/my/ansible.cfg
configured module search path = Default w/o overrides

CONFIGURATION

ansible.cfg:

[defaults]

hostfile = hosts

OS / ENVIRONMENT

OS you are running Ansible from: Ubuntu 16.04

OS you are managing: Ubuntu 16.04

SUMMARY

After upgradig to ansible 2.2 I always get changes in apt module because it ignore cache_valid_time value.

STEPS TO REPRODUCE

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

EXPECTED RESULTS

Update apt cache on first run, skip updating cache on second run.

ACTUAL RESULTS

Always changes.

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
<192.168.60.4> ESTABLISH SSH CONNECTION FOR USER: vagrant
<192.168.60.4> 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 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1478178800.59-26361197346329 `" && echo ansible-tmp-1478178800.59-26361197346329="` echo $HOME/.ansible/tmp/ansible-tmp-1478178800.59-26361197346329 `" ) && sleep 0'"'"''
<192.168.60.4> PUT /tmp/tmpGz1Eb9 TO /home/vagrant/.ansible/tmp/ansible-tmp-1478178800.59-26361197346329/setup.py
<192.168.60.4> 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]'
<192.168.60.4> ESTABLISH SSH CONNECTION FOR USER: vagrant
<192.168.60.4> 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 && sleep 0'"'"''
<192.168.60.4> ESTABLISH SSH CONNECTION FOR USER: vagrant
<192.168.60.4> 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/" > /dev/null 2>&1'"'"'"'"'"'"'"'"' && 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
<192.168.60.4> ESTABLISH SSH CONNECTION FOR USER: vagrant
<192.168.60.4> 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 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1478178801.29-209769775274469 `" && echo ansible-tmp-1478178801.29-209769775274469="` echo $HOME/.ansible/tmp/ansible-tmp-1478178801.29-209769775274469 `" ) && sleep 0'"'"''
<192.168.60.4> PUT /tmp/tmpb8HOiL TO /home/vagrant/.ansible/tmp/ansible-tmp-1478178801.29-209769775274469/apt.py
<192.168.60.4> 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]'
<192.168.60.4> ESTABLISH SSH CONNECTION FOR USER: vagrant
<192.168.60.4> 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 && sleep 0'"'"''
<192.168.60.4> ESTABLISH SSH CONNECTION FOR USER: vagrant
<192.168.60.4> 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/" > /dev/null 2>&1'"'"'"'"'"'"'"'"' && sleep 0'"'"''
changed: [192.168.60.4] => {
"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
<192.168.60.4> ESTABLISH SSH CONNECTION FOR USER: vagrant
<192.168.60.4> 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 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1478178871.45-218992397586023 `" && echo ansible-tmp-1478178871.45-218992397586023="` echo $HOME/.ansible/tmp/ansible-tmp-1478178871.45-218992397586023 `" ) && sleep 0'"'"''
<192.168.60.4> PUT /tmp/tmpv9o0e3 TO /home/vagrant/.ansible/tmp/ansible-tmp-1478178871.45-218992397586023/setup.py
<192.168.60.4> 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]'
<192.168.60.4> ESTABLISH SSH CONNECTION FOR USER: vagrant
<192.168.60.4> 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 && sleep 0'"'"''
<192.168.60.4> ESTABLISH SSH CONNECTION FOR USER: vagrant
<192.168.60.4> 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/" > /dev/null 2>&1'"'"'"'"'"'"'"'"' && 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
<192.168.60.4> ESTABLISH SSH CONNECTION FOR USER: vagrant
<192.168.60.4> 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 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1478178872.37-148384000832646 `" && echo ansible-tmp-1478178872.37-148384000832646="` echo $HOME/.ansible/tmp/ansible-tmp-1478178872.37-148384000832646 `" ) && sleep 0'"'"''
<192.168.60.4> PUT /tmp/tmp3rCfzf TO /home/vagrant/.ansible/tmp/ansible-tmp-1478178872.37-148384000832646/apt.py
<192.168.60.4> 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]'
<192.168.60.4> ESTABLISH SSH CONNECTION FOR USER: vagrant
<192.168.60.4> 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 && sleep 0'"'"''
<192.168.60.4> ESTABLISH SSH CONNECTION FOR USER: vagrant
<192.168.60.4> 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/" > /dev/null 2>&1'"'"'"'"'"'"'"'"' && sleep 0'"'"''
changed: [192.168.60.4] => {
"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

It seems cache_update_time didn't updated.

Copied from original issue: ansible/ansible-modules-core#5468

Issue 2:
From @ahes on 2016-11-08T16:10:24Z

ISSUE TYPE

Bug Report

COMPONENT NAME

apt

ANSIBLE VERSION

ansible 2.2.0.0

CONFIGURATION

Default

OS / ENVIRONMENT

Debian Jessie 64 GNU/Linux

SUMMARY

When installing packages and using update_cache option apt module always returns state CHANGED even if packages are already installed.

In my opinion expected behavior would be:

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.

when using update_cache without installing any package(s) return status CHANGED when cache has been updated.

STEPS TO REPRODUCE

---
- hosts: localhost
gather_facts: no
become: yes
tasks:
- apt:
name: htop
update_cache: yes

EXPECTED RESULTS

As in ansible 2.1:

PLAY [localhost] ***************************************************************

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

PLAY RECAP *********************************************************************
localhost : ok=1 changed=0 unreachable=0 failed=0

Part of debug output:

ok: [localhost] => {"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"}}

ACTUAL RESULTS

PLAY [localhost] ***************************************************************

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

PLAY RECAP *********************************************************************
localhost : ok=1 changed=1 unreachable=0 failed=0

Part of debug output:

changed: [localhost] => {
"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"
}
}

Copied from original issue: ansible/ansible-modules-core#5532