How to get the user to repeat the "apt" task if it failed?

I have ansible games running on many machines. In this playbook, I have several packages that I try to install using apt , but sometimes they fail, either due to the launch of other playbooks, periodic updates, or any other apt instance running in parallel and lock capture.

I basically want to add a repetition loop before giving up, but I couldn’t do it, because repetitions are not supported for apt , apparently: I looked at the apt module page in the ANSI documentation and even tried to actually use it, although it is there no (which obviously failed).

In any case, I need an idea on how to configure ANSI to retry, say, 3 times, with a delay of 30 seconds, but only if the package installation fails.

+10
source share
1 answer

There are universal tests for task results , so you can use:

 - apt: name: build-essential state: present register: apt_res retries: 5 until: apt_res is success 

In Ansible 2.4 and earlier, use the filter syntax - this is deprecated in Ansible 2.5 and will be removed from 2.9

 until: apt_res | success 
+11
source

Source: https://habr.com/ru/post/1273734/


All Articles