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'
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.
Click below to sign up and get $100 of credit to try our products over 60 days!