0

As an Ansible newbie, I'm installing some packages on multiple Ubuntu machines using a loop, here's my playbook:

---
- name: Install Software 
  hosts: all             
  become: true    
  tasks:                 
    - name: Update package cache 
      package:                    # Use the package module
        name: "{{ item }}"        
        state: present            
      with_items:                 # Loop over the package list
        - vim                      
        - tree                     
        - figlet                   
      ignore_errors: yes         # Ignore errors if packages fail to install
      retries: 3                 # Number of retries if task fails
      delay: 10                  # Delay between retries in seconds

At the first run the playbook fails on one of the hosts, here's the error message:

failed: [serv01] (item=tree) => {"ansible_loop_var": "item", "cache_update_time": 1716373387, "cache_updated": false, "changed": false, "item": "tree", "msg": "'/usr/bin/apt-get -y -o "Dpkg::Options::=--force-confdef" -o "Dpkg::Options::=--force-confold" install 'tree=2.0.2-1'' failed: E: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1567 (apt-get)\nE: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it?\n", "rc": 100, "stderr": "E: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1567 (apt-get)\nE: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it?\n", "stderr_lines": ["E: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1567 (apt-get)", "E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it?"], "stdout": "", "stdout_lines": []} failed: [serv01] (item=figlet) => {"ansible_loop_var": "item", "cache_update_time": 1716373387, "cache_updated": false, "changed": false, "item": "figlet", "msg": "'/usr/bin/apt-get -y -o "Dpkg::Options::=--force-confdef" -o "Dpkg::Options::=--force-confold" install 'figlet=2.2.5-3'' failed: E: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1567 (apt-get)\nE: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it?\n", "rc": 100, "stderr": "E: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1567 (apt-get)\nE: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it?\n", "stderr_lines": ["E: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1567 (apt-get)", "E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it?"], "stdout": "", "stdout_lines": []} ...ignoring

When I run the playbook again, it is successful on all hosts.

How do I tell Ansible to wait til the lock is released? Or is it possible to install packages concurrently?

1
  • I would try killall apt apt-get to kill all processes from apt and apt get. Most of the time this fixes it Commented May 23, 2024 at 18:52

1 Answer 1

-3

The error message is pretty clear; this is not an ansible problem.

E: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1567 (apt-get)\nE: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it?

Connect to the server and find out what that process is doing. With the data provided and without access to the server that's the only possible advice.

If it's stuck (check using strace) kill it. Manually run e.g. aptitude afterwards to figure out what may have broken the previous (non-ansible controlled run). Once you've cleared the issues ansible will do its thing.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.