Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I avoid ansible deployment failures due to dpkg lock file?

Tags:

ansible

It seems that getting failures due to /var/lib/dpkg/lock is something not very rare. Based on observations these are caused most of the time 9/10 due to state lock file or while a cron job was running.

This means that a retry mechanism combined with a removal of stale file could be the solution.

How can I do this in ansible?

like image 273
sorin Avatar asked Apr 14 '16 17:04

sorin


1 Answers

I'd try to solve this with until feature of ansible (http://docs.ansible.com/ansible/latest/playbooks_loops.html#do-until-loops)

- name: Apt for sure
  apt: name=foobar state=installed
  register: apt_status
  # 2018 syntax:
  # until: apt_status|success
  # 2020 syntax:
  until: apt_status is success
  delay: 6
  retries: 10
like image 62
George Shuklin Avatar answered Oct 19 '22 07:10

George Shuklin