In my Ansible playbook I've been running into intermittent failures with apt
tasks due to failures to obtain a lock.
I'm thinking of using some retry logic as described in this answer. e.g.
- name: install packages
apt:
name:
- nginx
- git
register: result
until: result is not failed
retries: 7
delay: 9
The playbook includes multiple apt
tasks so I'm wondering if there's a way that I can avoid repeating the register
, retries
, until
for each apt
task i.e. some way to make these defaults, or to define my own apt-with-retries
?
My playbook is for provisioning DigitalOcean droplets. I've got several apt
tasks due to:
Breaking down the playbook into logic steps i.e. apt install a few things, followed by a few other steps, followed by apt installing another group of packages...
I've extracted a couple of roles into their own self-contained files e.g. a
postgres_server
role.
The goals here are the usual reasons for wanting to avoid duplication/repetition. e.g. avoid having to make changes in multiple places, avoid having to remember to copy and paste when adding another apt task in the future.
I looked into using module_defaults
, but these properties are on the task itself rather than the apt
module so I don't think they can be used for this scenario.