Skip to content

Commit e1e91d6

Browse files
SET-626 Olympus - Ensure Ansible updates Nginx images
1 parent 804420c commit e1e91d6

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

roles/nginx/tasks/nginx_update.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
- name: Gather info on a current nginx image
3+
containers.podman.podman_image_info:
4+
name: "{{ files.name }}"
5+
register: local_image_tags
6+
with_items: "{{ podman.images.remotes }}"
7+
loop_control:
8+
loop_var: files
9+
10+
- name: Store current nginx image value in a variable
11+
set_fact:
12+
nginx_latest_image_tag: "{{ local_image_tags.results[0].images[0].RepoTags[0] }}"
13+
14+
- name: Pull the latest Nginx image
15+
shell: "podman pull {{ nginx.latest_image }}"
16+
register: nginx_latest_image_result
17+
when: "nginx.latest_image not in nginx_latest_image_tag"
18+
19+
- name: Get current Nginx container info
20+
command: podman ps --format "{{ '{{.Names}}' }}" --filter ancestor="{{ nginx_latest_image_tag }}"
21+
register: nginx_container_info
22+
when: nginx_latest_image_result.changed # Only execute if the image was updated
23+
24+
- name: Extract current container name
25+
set_fact:
26+
container_name: "{{ nginx_container_info.stdout_lines | first }}"
27+
when: nginx_latest_image_result.changed
28+
29+
- name: Stop and remove the current container
30+
containers.podman.podman_container:
31+
name: "{{ container_name }}"
32+
state: absent
33+
ignore_errors: true # Ignore errors if the container doesn't exist
34+
35+
- name: Start the latest Nginx container
36+
containers.podman.podman_container:
37+
name: "{{ container_name }}"
38+
image: "{{ nginx.latest_image }}"
39+
state: started
40+
when: nginx_latest_image_result.changed
41+
notify:
42+
- restart nginx

roles/podman/tasks/images.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@
3232
loop_control:
3333
loop_var: files
3434

35+
- name: "Update nginx image if required"
36+
ansible.builtin.include_role:
37+
name: nginx
38+
tasks_from: nginx_update.yml
39+
3540
- name: "Ensure local images are successfully build"
3641
containers.podman.podman_image:
3742
name: "{{ files.tag }}"

0 commit comments

Comments
 (0)