Interview Prep/Ansible/Playbook Design, Handlers and Idempotency

How would you ensure a package is at an exact version and never upgraded accidentally?

IntermediateScenarioPlaybook Design, Handlers and Idempotency
Answer

Situation read → Version pinning.

What I'd do →

- ansible.builtin.apt:
    name: nginx=1.24.0-2ubuntu7
    state: present
    allow_downgrade: true
- ansible.builtin.dpkg_selections:
    name: nginx
    selection: hold

Why → The version string pins the install and hold blocks upgrades from apt upgrade.

Interview tip → On RHEL use dnf with name: nginx-1.24.0 and the versionlock plugin.

All Ansible questions Roadmap: Ansible

More on Playbook Design, Handlers and Idempotency