From bf07ef74c38f320ca706b66d5fa66bb570f658a8 Mon Sep 17 00:00:00 2001 From: Jeremy Lecour Date: Thu, 11 Jan 2024 16:51:20 +0100 Subject: [PATCH] =?UTF-8?q?nginx:=20take=20care=20of=20=C2=AB=20already=20?= =?UTF-8?q?defined=20=C2=BB=20and=20=C2=AB=20not=20yet=20defined=20=C2=BB?= =?UTF-8?q?=20server=20status=20suffix=20in=20check=20mode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 2 +- nginx/tasks/server_status_read.yml | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c184cf59..bc4929fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -81,7 +81,7 @@ The **patch** part changes is incremented if multiple releases happen the same m * webapps/nextcloud: fix misplaced gid attribute * webapps/nextcloud: fix missing gid * nginx: fix mistake between "check_mode: no" and "when: not ansible_check_mode" (fail in check mode) -* nginx: add "when: not ansible_check_mode" in various tasks to prevent fail in check mode +* nginx: take care of « already defined » and « not yet defined » server status suffix in check mode * dovecot: fix plugin dovecot1 ### Removed diff --git a/nginx/tasks/server_status_read.yml b/nginx/tasks/server_status_read.yml index b334a729..eddc3fe8 100644 --- a/nginx/tasks/server_status_read.yml +++ b/nginx/tasks/server_status_read.yml @@ -18,23 +18,28 @@ - name: generate random string for server-status suffix ansible.builtin.shell: - cmd: "apg -a 1 -M N -n 1 > {{ nginx_serverstatus_suffix_file }}" - args: + cmd: "apg -a 1 -M N -n 1 | tee {{ nginx_serverstatus_suffix_file }}" creates: "{{ nginx_serverstatus_suffix_file }}" + register: generated_nginx_serverstatus_suffix + +- name: check if nginx suffix file exists + ansible.builtin.stat: + path: "{{ nginx_serverstatus_suffix_file }}" + register: nginx_serverstatus_suffix_file_check - name: read nginx server status suffix ansible.builtin.command: cmd: "tail -n 1 {{ nginx_serverstatus_suffix_file }}" changed_when: False - when: not ansible_check_mode - register: new_nginx_serverstatus_suffix + check_mode: no + when: nginx_serverstatus_suffix_file_check.stat.exists + register: read_nginx_serverstatus_suffix +# If the file exists and the read value is not empty, then use it, otherwhise use the generated value - name: overwrite nginx_serverstatus_suffix ansible.builtin.set_fact: - nginx_serverstatus_suffix: "{{ new_nginx_serverstatus_suffix.stdout }}" - when: not ansible_check_mode + nginx_serverstatus_suffix: "{{ (nginx_serverstatus_suffix_file_check.stat.exists and (read_nginx_serverstatus_suffix.stdout | length > 0)) | ternary(read_nginx_serverstatus_suffix.stdout, generated_nginx_serverstatus_suffix.stdout) }}" - ansible.builtin.debug: var: nginx_serverstatus_suffix verbosity: 1 - when: not ansible_check_mode