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 module fails to do apt-upgrade with cache_valid_time set and update_cache=yes #76210

Open
1 task done
pfaffman opened this issue Nov 3, 2021 · 2 comments
Open
1 task done
Labels
affects_2.11 affects_2.13 bug This issue/PR relates to a bug. module This issue/PR relates to a module. needs_verified This issue needs to be verified/reproduced by maintainer P3 Priority 3 - Approved, No Time Limitation support:core This issue/PR relates to code supported by the Ansible Engineering Team.

Comments

@pfaffman
Copy link

pfaffman commented Nov 3, 2021

Summary

Running an apt upgrade fails because the apt cache is out of date:

    - name: do an apt upgrade
      apt:
        name: "*"
        state: latest
        update_cache: yes
        force_apt_get: True
        cache_valid_time: 600
      become: yes
      register: apt_action
      retries: 100

When I do an apt update by hand and then re-run the playbook it works. I suppose it could be that the 10 minute valid time is at issue; I don't think it's the case that I've been so unlucky as to have had this problem multiple times over multiple days. But I suppose that's possible.

Issue Type

Bug Report

Component Name

apt

Ansible Version

[DEPRECATION WARNING]: Ansible will require Python 3.8 or newer on the controller starting with Ansible 2.12. Current version: 3.7.3 (default, Jan 22 2021, 20:04:44) [GCC 8.3.0]. This
 feature will be removed from ansible-core in version 2.12. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.
ansible [core 2.11.6] 
  config file = None
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.7/dist-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.7.3 (default, Jan 22 2021, 20:04:44) [GCC 8.3.0]
  jinja version = 3.0.2
  libyaml = True

Configuration

s[DEPRECATION WARNING]: Ansible will require Python 3.8 or newer on the controller starting with Ansible 2.12. Current version: 3.7.3 (default, Jan 22 2021, 20:04:44) [GCC 8.3.0]. This
 feature will be removed from ansible-core in version 2.12. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.

OS / Environment

Debian GNU/Linux 10 \n \l

Steps to Reproduce

        - name: do an apt upgrade
          apt:
            name: "*"
            state: latest
            update_cache: yes
            force_apt_get: True
            cache_valid_time: 600
          become: yes
          register: apt_action
          retries: 100
          until: apt_action is success or ('Failed to lock apt for exclusive operation' not in apt_action.msg and '/var/lib/dpkg/lock' not in apt_action.msg)
          when: ansible_distribution == 'Ubuntu' or ansible_distribution == 'Ubuntu'

Expected Results

I expected a successful apt upgrade

Actual Results

fatal: [167.71.88.47]: FAILED! => {"attempts": 1, "changed": false, "msg": "'/usr/bin/apt-get upgrade --with-new-pkgs ' failed: E: Failed to fetch http://mirrors.digitalocean.com/ubuntu/pool/universe/o/open-vm-tools/open-vm-tools_11.3.0-2ubuntu0~ubuntu20.04.1_amd64.deb  404  Not Found [IP: 104.21.29.13 80]
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
", "rc": 100, "stdout": "Reading package lists...
Building dependency tree...
Reading state information...
Calculating upgrade...
The following packages will be upgraded:
  open-vm-tools
1 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Need to get 648 kB of archives.
After this operation, 950 kB of additional disk space will be used.
Err:1 http://mirrors.digitalocean.com/ubuntu focal-updates/universe amd64 open-vm-tools amd64 2:11.3.0-2ubuntu0~ubuntu20.04.1
  404  Not Found [IP: 104.21.29.13 80]
", "stdout_lines": ["Reading package lists...", "Building dependency tree...", "Reading state information...", "Calculating upgrade...", "The following packages will be upgraded:", "  open-vm-tools", "1 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.", "Need to get 648 kB of archives.", "After this operation, 950 kB of additional disk space will be used.", "Err:1 http://mirrors.digitalocean.com/ubuntu focal-updates/universe amd64 open-vm-tools amd64 2:11.3.0-2ubuntu0~ubuntu20.04.1", "  404  Not Found [IP: 104.21.29.13 80]"]}

Code of Conduct

  • I agree to follow the Ansible Code of Conduct
@ansibot
Copy link
Contributor

ansibot commented Nov 3, 2021

Files identified in the description:

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

click here for bot help

@ansibot ansibot added affects_2.13 bug This issue/PR relates to a bug. 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 Nov 3, 2021
@bcoca bcoca added needs_verified This issue needs to be verified/reproduced by maintainer P3 Priority 3 - Approved, No Time Limitation and removed needs_triage Needs a first human triage before being processed. labels Nov 4, 2021
@jameslivulpi
Copy link
Contributor

jameslivulpi commented Dec 4, 2021

I ran some tests on my digital ocean droplet and don't think this is a bug:

Basically since you have cache_valid_time: 600 it won't update the cache for the 600 seconds (10 mins) like you mentioned. The code checks the mtime on:

APT_LISTS_PATH = "/var/lib/apt/lists"
APT_UPDATE_SUCCESS_STAMP_PATH = "/var/lib/apt/periodic/update-success-stamp"

so if the mtime on these is less than 600 seconds from running the play (datetime.datetime.now()) then the cache doesn't get updated thus hitting the error, so to me this looks expected. I also waited till after 600 seconds and ran your play and it executed as it should (i.e., updated cache and runs the update).

Hope this helps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects_2.11 affects_2.13 bug This issue/PR relates to a bug. module This issue/PR relates to a module. needs_verified This issue needs to be verified/reproduced by maintainer P3 Priority 3 - Approved, No Time Limitation support:core This issue/PR relates to code supported by the Ansible Engineering Team.
Projects
None yet
Development

No branches or pull requests

4 participants