Interview Prep/Ansible/Privilege Escalation and Python Interpreter Issues

`Failed to lock apt for exclusive operation` or `Could not get lock /var/lib/dpkg/lock-frontend`

IntermediateTroubleshootingPrivilege Escalation and Python Interpreter Issues
Answer

Likely causes → unattended-upgrades, cloud-init or another apt process holds the lock, often right after boot.

Diagnose → fuser -v /var/lib/dpkg/lock-frontend, ps aux | grep -E 'apt|dpkg'.

Fix →

- ansible.builtin.apt:
    name: nginx
    lock_timeout: 300

Or wait for cloud-init: cloud-init status --wait.

Prevent → Use lock_timeout and disable unattended upgrades on build/bootstrap windows.

All Ansible questions Roadmap: Ansible

More on Privilege Escalation and Python Interpreter Issues