nickjj / ansible-docker

Install / Configure Docker and Docker Compose using Ansible.
MIT License
750 stars 224 forks source link

Add rescue option for OS upgrade failure + test via docker build #121

Open compscidr opened 2 years ago

compscidr commented 2 years ago

A first pass at trying to solve: https://github.com/nickjj/ansible-docker/issues/117

I was able to reproduce the failure mode reliably with the added Dockerfile.

You can try it out by running: docker build -f tests/Dockerifle . from the main folder of the repo.

The dockerfile uses multistage builds. In the first stage, it uses Ubuntu20.04, applies the playbook. Then in the next stage, it starts from Ubuntu22.04, and then copies the virtualenv from the previous stage, as if an upgrade had been done without cleaning this up. It then tries to run the playbook again and then fails.

I converted the failing task to a block and rescue, and then when the rescue happens, it clobbers the virtual env and then just tries to apply the playbook again. This appears to work succesfully.

The only hangup I had, was trying to apply the playbook during a docker build - there is no systemd and docker can't run in a service while building, so I just added a couple of new default variables that toggle off the restart handlers.

Might not be the best way to do it, but open to suggestions!