Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apt_repository never updates the APT cache on retry #36605

Closed
git-harry opened this issue Feb 22, 2018 · 4 comments · Fixed by #57266
Closed

apt_repository never updates the APT cache on retry #36605

git-harry opened this issue Feb 22, 2018 · 4 comments · Fixed by #57266
Labels
affects_2.4 This issue/PR affects Ansible v2.4 bug This issue/PR relates to a bug. has_pr This issue has an associated PR. module This issue/PR relates to a module. packaging Packaging category support:core This issue/PR relates to code supported by the Ansible Engineering Team. traceback This issue/PR includes a traceback.

Comments

@git-harry
Copy link

ISSUE TYPE
  • Bug Report
COMPONENT NAME

apt_repository

ANSIBLE VERSION
ansible 2.4.3.0
  config file = None
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python2.7/dist-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 2.7.12 (default, Dec  4 2017, 14:50:18) [GCC 5.4.0 20160609]
CONFIGURATION
OS / ENVIRONMENT

Distributor ID: Ubuntu
Description: Ubuntu 16.04.3 LTS
Release: 16.04
Codename: xenial

SUMMARY

On the first attempt apt_repository updates the configuration file and then tries to update the cache. If the cache update fails, and the task is set to retry, a second attempt is made to perform the task. This second attempt always succeeds however the cache is never updated.

The relevant block of code appears to be https://github.com/ansible/ansible/blob/v2.4.3.0-1/lib/ansible/modules/packaging/os/apt_repository.py#L540-L547. On the first attempt the configuration changes are saved, on the second attempt no changes are detected and so this block is skipped preventing the cache update being retried.

STEPS TO REPRODUCE
- hosts: localhost
  tasks:
    - apt_repository:
        repo: "deb http://repo.example.com/foo bar baz"
        update_cache: yes
      register: add_repo
      until: add_repo|success
      retries: 3
EXPECTED RESULTS

When the task is retried it should attempt to update the cache. With the above example the task should fail having exhausted all retries given the repository specified does not exist.

ACTUAL RESULTS

The task succeeds on the first retry even though the cache hasn't been updated.

# ansible-playbook test.yml -vvvv
ansible-playbook 2.4.3.0
  config file = None
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python2.7/dist-packages/ansible
  executable location = /usr/local/bin/ansible-playbook
  python version = 2.7.12 (default, Dec  4 2017, 14:50:18) [GCC 5.4.0 20160609]
No config file found; using defaults
setting up inventory plugins
 [WARNING]: Unable to parse /etc/ansible/hosts as an inventory source

 [WARNING]: No inventory was parsed, only implicit localhost is available

 [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

Loading callback plugin default of type stdout, v2.0 from /usr/local/lib/python2.7/dist-packages/ansible/plugins/callback/default.pyc

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

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

TASK [Gathering Facts] *************************************************************************************************************************************************************************************
Using module file /usr/local/lib/python2.7/dist-packages/ansible/modules/system/setup.py
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: root
<127.0.0.1> EXEC /bin/sh -c 'echo ~ && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /root/.ansible/tmp/ansible-tmp-1519337361.1-12167561870635 `" && echo ansible-tmp-1519337361.1-12167561870635="` echo /root/.ansible/tmp/ansible-tmp-1519337361.1-12167561870635 `" ) && sleep 0'
<127.0.0.1> PUT /tmp/tmpUtD8Aj TO /root/.ansible/tmp/ansible-tmp-1519337361.1-12167561870635/setup.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-tmp-1519337361.1-12167561870635/ /root/.ansible/tmp/ansible-tmp-1519337361.1-12167561870635/setup.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python /root/.ansible/tmp/ansible-tmp-1519337361.1-12167561870635/setup.py; rm -rf "/root/.ansible/tmp/ansible-tmp-1519337361.1-12167561870635/" > /dev/null 2>&1 && sleep 0'
ok: [localhost]
META: ran handlers

TASK [apt_repository] **************************************************************************************************************************************************************************************
task path: /root/test.yml:3
Using module file /usr/local/lib/python2.7/dist-packages/ansible/modules/packaging/os/apt_repository.py
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: root
<127.0.0.1> EXEC /bin/sh -c 'echo ~ && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /root/.ansible/tmp/ansible-tmp-1519337362.87-19000655109250 `" && echo ansible-tmp-1519337362.87-19000655109250="` echo /root/.ansible/tmp/ansible-tmp-1519337362.87-19000655109250 `" ) && sleep 0'
<127.0.0.1> PUT /tmp/tmpeeIaHe TO /root/.ansible/tmp/ansible-tmp-1519337362.87-19000655109250/apt_repository.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-tmp-1519337362.87-19000655109250/ /root/.ansible/tmp/ansible-tmp-1519337362.87-19000655109250/apt_repository.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python /root/.ansible/tmp/ansible-tmp-1519337362.87-19000655109250/apt_repository.py; rm -rf "/root/.ansible/tmp/ansible-tmp-1519337362.87-19000655109250/" > /dev/null 2>&1 && sleep 0'
FAILED - RETRYING: apt_repository (3 retries left).Result was: {
    "attempts": 1, 
    "changed": false, 
    "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_eGGoS0/ansible_module_apt_repository.py\", line 556, in <module>\n    main()\n  File \"/tmp/ansible_eGGoS0/ansible_module_apt_repository.py\", line 544, in main\n    cache.update()\n  File \"/usr/lib/python2.7/dist-packages/apt/cache.py\", line 456, in update\n    raise FetchFailedException()\napt.cache.FetchFailedException\n", 
    "module_stdout": "", 
    "msg": "MODULE FAILURE", 
    "rc": 0, 
    "retries": 4
}
Using module file /usr/local/lib/python2.7/dist-packages/ansible/modules/packaging/os/apt_repository.py
<127.0.0.1> EXEC /bin/sh -c 'echo ~ && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /root/.ansible/tmp/ansible-tmp-1519337371.12-4389313985762 `" && echo ansible-tmp-1519337371.12-4389313985762="` echo /root/.ansible/tmp/ansible-tmp-1519337371.12-4389313985762 `" ) && sleep 0'
<127.0.0.1> PUT /tmp/tmpiebQtl TO /root/.ansible/tmp/ansible-tmp-1519337371.12-4389313985762/apt_repository.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-tmp-1519337371.12-4389313985762/ /root/.ansible/tmp/ansible-tmp-1519337371.12-4389313985762/apt_repository.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python /root/.ansible/tmp/ansible-tmp-1519337371.12-4389313985762/apt_repository.py; rm -rf "/root/.ansible/tmp/ansible-tmp-1519337371.12-4389313985762/" > /dev/null 2>&1 && sleep 0'
ok: [localhost] => {
    "attempts": 2, 
    "changed": false, 
    "diff": {}, 
    "invocation": {
        "module_args": {
            "codename": null, 
            "filename": null, 
            "install_python_apt": true, 
            "mode": null, 
            "repo": "deb http://repo.example.com/foo bar baz", 
            "state": "present", 
            "update_cache": true, 
            "validate_certs": true
        }
    }, 
    "repo": "deb http://repo.example.com/foo bar baz", 
    "state": "present"
}
META: ran handlers
META: ran handlers

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

@ansibot
Copy link
Contributor

ansibot commented Feb 22, 2018

Files identified in the description:

If these files are inaccurate, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibot
Copy link
Contributor

ansibot commented Feb 22, 2018

cc @sashka
click here for bot help

@ansibot ansibot added affects_2.4 This issue/PR affects Ansible v2.4 bug_report module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Feb 22, 2018
@mkrizek mkrizek removed the needs_triage Needs a first human triage before being processed. label Feb 23, 2018
@ansibot ansibot added bug This issue/PR relates to a bug. and removed bug_report labels Mar 1, 2018
openstack-gerrit pushed a commit to openstack/openstack-ansible-tests that referenced this issue Mar 7, 2018
This rule is designed to prevent the Ansible module `apt_repository`
from being used to update the APT cache. There is a bug [1] in
`apt_repository` that prevents cache updates from being performed
whenever the module is retried. If the cache update fails at the first
attempt, it is skipped on the subsequent attempt of the task causing the
task to always complete successfully. Until this bug is addressed this
rule should prevent it from being introduced into OpenStack-Ansible.

Partial-bug: 1750656

[1] ansible/ansible#36605

Change-Id: If440ce129c31fb4e62a8e0ac5094195f4d4d7167
openstack-gerrit pushed a commit to openstack/openstack-ansible-tests that referenced this issue Mar 12, 2018
This rule is designed to prevent the Ansible module `apt_repository`
from being used to update the APT cache. There is a bug [1] in
`apt_repository` that prevents cache updates from being performed
whenever the module is retried. If the cache update fails at the first
attempt, it is skipped on the subsequent attempt of the task causing the
task to always complete successfully. Until this bug is addressed this
rule should prevent it from being introduced into OpenStack-Ansible.

Partial-bug: 1750656

[1] ansible/ansible#36605

Change-Id: If440ce129c31fb4e62a8e0ac5094195f4d4d7167
(cherry picked from commit 67bfc90)
openstack-gerrit pushed a commit to openstack/openstack-ansible-tests that referenced this issue Mar 12, 2018
This rule is designed to prevent the Ansible module `apt_repository`
from being used to update the APT cache. There is a bug [1] in
`apt_repository` that prevents cache updates from being performed
whenever the module is retried. If the cache update fails at the first
attempt, it is skipped on the subsequent attempt of the task causing the
task to always complete successfully. Until this bug is addressed this
rule should prevent it from being introduced into OpenStack-Ansible.

Partial-bug: 1750656

[1] ansible/ansible#36605

Change-Id: If440ce129c31fb4e62a8e0ac5094195f4d4d7167
(cherry picked from commit 67bfc90)
openstack-gerrit pushed a commit to openstack/openstack-ansible-tests that referenced this issue Mar 13, 2018
This rule is designed to prevent the Ansible module `apt_repository`
from being used to update the APT cache. There is a bug [1] in
`apt_repository` that prevents cache updates from being performed
whenever the module is retried. If the cache update fails at the first
attempt, it is skipped on the subsequent attempt of the task causing the
task to always complete successfully. Until this bug is addressed this
rule should prevent it from being introduced into OpenStack-Ansible.

Partial-bug: 1750656

[1] ansible/ansible#36605

Change-Id: If440ce129c31fb4e62a8e0ac5094195f4d4d7167
(cherry picked from commit 67bfc90)
@avoidik
Copy link

avoidik commented Mar 21, 2018

Same issue here, it seems that whole apt-* cache thing is broken, because it fails even with:

- name: refresh apt
  action: "apt"
  args:
    update_cache: yes
  register: cache_result
  until: cache_result|succeeded
  retries: 4

With

ansible-playbook 2.4.3.0

odyssey4me pushed a commit to odyssey4me/ansible-grafana that referenced this issue Mar 22, 2018
Given that updating the apt cache/keys is a network operation,
they are prone to transient failures and should therefore
include the use of retries on the task.

However, as noted in [1], if apt_repository fails to update
the apt cache after updating the configuration, retries do
not register there was a change and so no attempt is made
to update the cache by the module on the second attempt.
This failure can result in a failure to install packages.

This change adds an apt module task to update the cache if
the apt_repository tasks or the apt_key tasks register a
change. This means updating the cache will get retried on
failure and no longer fail silently.

The apt cache update is triggered on changes to the apt
repository configuration and to the keys to ensure that the
cache is always using the right config/key conbination.

[1] ansible/ansible#36605
@ansibot ansibot added the traceback This issue/PR includes a traceback. label May 24, 2018
@ansibot ansibot added the packaging Packaging category label Feb 17, 2019
@resmo
Copy link
Contributor

resmo commented May 25, 2019

this issue is address in the following PR and also implements multiple repos support.

resolved_by_pr #56951

@ansibot ansibot added the has_pr This issue has an associated PR. label Jul 28, 2019
@ansible ansible locked and limited conversation to collaborators Oct 1, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.4 This issue/PR affects Ansible v2.4 bug This issue/PR relates to a bug. has_pr This issue has an associated PR. module This issue/PR relates to a module. packaging Packaging category support:core This issue/PR relates to code supported by the Ansible Engineering Team. traceback This issue/PR includes a traceback.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants