PodWatch is an Ansible Playbook that examines container images on a host and updates the images if a newer version is available with the same tag (e.g. latest).
It was developed on the following infrastructure:
-
Intel NUC bare metal server
-
Fedora 33 Server
-
Ansible 2.10(.4)
The general logic flow in the playbook is:
-
Retrieve all container images on the machine
-
In a loop do the following
-
Check if there is a newer version of the image available. If so pull that image.
-
If a newer image has been found check if there is a running container using the old image. If so force restart the container to pick up the new image
-
-
Use
podman system prune
to clean up old, now unused, images.
-
In a directory of your choice clone this repo:
git clone https://github.com/wkulhanek/podwatch cd podwatch # Need to create a logs directory to use in the shell script later mkdir logs
-
Determine if your podman containers are running as regular users (using the user id you just cloned the repository with) or as root. The playbook is written for the case where the playbook runs as a regular user but the containers are running as root. It only works for these two cases and does not yet support individual users for each container. If the containers are running as root no change is necessary. If running as a regular user switch the line
become: true
tobecome:false
in the mainpodwatch.yml
playbook. -
Create a Python3 virtual environment to run the playbook in.
-
Make sure that Python3 and _virtualenv* are installed:
sudo dnf -y install python3 python3-virtualenv
-
Create a virtualenv for podwatch and install all prerequisites into the virtualenv.
-
mkdir $HOME/virtualenvs virtualenv -p $(which python3) $HOME/virtualenvs/podwatch source $HOME/virtualenvs/podwatch/bin/activate pip install -r ./requirements.txt
-
Install the Ansible collection(s) necessary to run the playbook.
ansible-galaxy install -r ./requirements.yml
-
Create a
crontab
file pointing to theupdate_containers.sh
script in your podwatch directory.0 3 * * * /home/kulhanek/podwatch/update_containers.sh
-
And finally set the crontab to use this file:
crontab crontab
-
Validate that your crontab is set properly:
crontab -l