Join 1M+ other developers and:
- Get help and share knowledge in Q&A
- Subscribe to topics of interest
- Get courses & tools that help you grow as a developer or small business owner
Solved: How to wait for droplet agent to be installed to avoid apt lock issues
It took me several hours to figure out that the new droplet-agent is installed by apt on the first boot, which caused my Ansible playbook to fail due to not being able to get an apt lock.
The trick seems to be to wait until /etc/systemd/system/droplet-agent.service exists before trying to do anything with apt. The cloud install script grabs apt several times, so merely waiting to be able to use apt (as the apt-upgrade below will do) just results in a race condition where the cloud install script and mine were both working at the same time.
- name: Wait until cloud service is installed before continuing wait_for: path: /etc/systemd/system/droplet-agent.service
Here’s this too, though as mentioned above, it’s not sufficient
- name: do an apt upgrade apt: name: "*" state: latest update_cache: yes force_apt_get: True cache_valid_time: 3600 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'