nginx: take care of « already defined » and « not yet defined » server status suffix in check mode
All checks were successful
Ansible Lint |Total|New|Outstanding|Fixed|Trend |:-:|:-:|:-:|:-:|:-: |2674|15|2659|9|:-1: Reference build: <a href="https://jenkins.evolix.org/job/gitea/job/ansible-roles/job/unstable/446//ansiblelint">Evolix » ansible-roles » unstable #446</a>
gitea/ansible-roles/pipeline/head This commit looks good

This commit is contained in:
Jérémy Lecour 2024-01-11 16:51:20 +01:00 committed by Jérémy Lecour
parent f5d5e84caf
commit bf07ef74c3
Signed by: jlecour
SSH key fingerprint: SHA256:h+5LgHRKwN9lS0SsdVR5yZPeFlJE4Mt+8UtL4CcP8dY
2 changed files with 13 additions and 8 deletions

View file

@ -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

View file

@ -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