LOGBOOK

HELP

Quiz Entry - updated: 2026.11.12

A package task on a Debian host fails with apt errors like Failed to fetch http://.../libpcre2-posix3_..._amd64.deb 404 Not Found and the hint "maybe run apt-get update". Why does this happen, and how do you fix it in the playbook?

The host's local package index is out of date: it still points to package versions the mirror has since replaced. Add update_cache: true to the package task, so Ansible runs the equivalent of apt-get update before installing.

A stale apt index asks the mirror for an old file name and gets 404; with update_cache the index is refreshed first and the current file is found

* update_cache refreshes the index before apt looks up the file names. *

apt does not ask the mirror "what is the current version of mariadb-server?" at install time. It reads its local index (/var/lib/apt/lists/), which records, for every package, the exact version and file path on the mirror as of the last apt-get update. When a security update replaces a package, the mirror drops the old .deb file. A host whose index predates that change asks for a file that no longer exists, and the mirror answers 404 Not Found. Fresh VMs and lab images are typical victims, because their index is as old as the image.

The fix is to refresh the index first:

- name: Latest version of necessary packages installed
  ansible.builtin.package:
    name:
      - "{{ mysql_pkg }}"
      - "{{ web_pkg }}"
    update_cache: true
    state: latest

update_cache is an argument of the apt module, yet it works here on the generic package module: package hands every argument to the package manager it detected on the host (next card). For playbooks that run often, cache_valid_time: 3600 (on apt) refreshes only if the index is older than an hour, which saves a network round trip on every run.

Go deeper:

From Quiz: ITIA / Ansible Variables, Secrets and Facts | Updated: Nov 12, 2026