fix(ufw): detect check mode without a command's skipped result
The probes in install.yml, orphan_rules.yml, service_rules.yml and sysctl.yml took a skipped `command` task as the sign of check mode. ansible-core 2.22 deprecates that: command.py marks its check-mode `r['skipped'] = True` for removal in 2.25, and the 2.22 changelog says "Returning skipped from a module or action plugin is deprecated and will be removed in ansible-core 2.25". The probe would then report ok, and the role would delete rules and edit sysctl.conf under --check. The probe now runs `echo ran` and reads its output: a command does not run in check mode, under --check or the check_mode keyword, so the output is empty there. Checked against ansible-core 2.22 and a copy with the skipped return removed, in a normal play, a check_mode play and --check. service_rules.yml had the same probe and is changed with the others. Assisted-by: Claude Code
This commit is contained in:
1 parent
39ec8e5b3c
commit
6fee0ea8b2
8 files changed
+26
-19
No files matched your search
@@ -7,9 +7,10 @@
|
||||
register: __ufw_install
|
||||
|
||||
# ansible_check_mode is not used: the play-level `check_mode: true` keyword does not set it inside
|
||||
# include_role tasks. A command task is skipped in both forms, the same probe as tasks/sysctl.yml.
|
||||
# include_role tasks. A command does not run in either form, so its output is missing; the same
|
||||
# probe as tasks/sysctl.yml. Not `is skipped`: ansible-core 2.25 drops that check-mode result.
|
||||
- name: Probe whether the run is in check mode
|
||||
ansible.builtin.command: "true"
|
||||
ansible.builtin.command: echo ran
|
||||
register: __ufw_install_probe
|
||||
changed_when: false
|
||||
|
||||
@@ -17,4 +18,4 @@
|
||||
# Undefined when this file's tags are skipped; the guards then default it to true.
|
||||
- name: Remember whether ufw can be configured
|
||||
ansible.builtin.set_fact:
|
||||
__ufw_can_configure: "{{ __ufw_install is not changed or __ufw_install_probe is not skipped }}"
|
||||
__ufw_can_configure: "{{ __ufw_install is not changed or __ufw_install_probe.stdout == 'ran' }}"
|
||||
@@ -64,16 +64,16 @@
|
||||
quiet: true
|
||||
|
||||
# ansible_check_mode is not used: the play-level `check_mode: true` keyword does not set
|
||||
# that magic variable inside include_role tasks (only --check does). A command task is
|
||||
# skipped in both forms and its result says so, which is the one signal that holds for both.
|
||||
# that magic variable inside include_role tasks (only --check does). A command does not run in
|
||||
# either form, so its output is missing. Not `is skipped`: ansible-core 2.25 drops that result.
|
||||
- name: Probe whether the run is in check mode
|
||||
ansible.builtin.command: "true"
|
||||
ansible.builtin.command: echo ran
|
||||
register: ufw_oa_probe
|
||||
changed_when: false
|
||||
|
||||
- name: Remember whether the run is in check mode
|
||||
ansible.builtin.set_fact:
|
||||
ufw_oa_check: "{{ ufw_oa_probe is skipped }}"
|
||||
ufw_oa_check: "{{ ufw_oa_probe.stdout != 'ran' }}"
|
||||
|
||||
- name: Read the firewall status
|
||||
become: true
|
||||
|
||||
@@ -122,16 +122,16 @@
|
||||
tags: [ufw, ufw_service_rules]
|
||||
block:
|
||||
# ansible_check_mode is not used: the play-level `check_mode: true` keyword does not set
|
||||
# that magic variable inside include_role tasks (only --check does). A command task is
|
||||
# skipped in both forms and its result says so, which is the one signal that holds for both.
|
||||
# that magic variable inside include_role tasks (only --check does). A command does not run in
|
||||
# either form, so its output is missing. Not `is skipped`: ansible-core 2.25 drops that result.
|
||||
- name: Probe whether the run is in check mode
|
||||
ansible.builtin.command: "true"
|
||||
ansible.builtin.command: echo ran
|
||||
register: ufw_sr_probe
|
||||
changed_when: false
|
||||
|
||||
- name: Remember whether the run is in check mode
|
||||
ansible.builtin.set_fact:
|
||||
ufw_sr_check: "{{ ufw_sr_probe is skipped }}"
|
||||
ufw_sr_check: "{{ ufw_sr_probe.stdout != 'ran' }}"
|
||||
|
||||
- name: Read the firewall status
|
||||
become: true
|
||||
|
||||
@@ -8,17 +8,18 @@
|
||||
when: ufw_enabled and ufw_sysctl_overrides | length > 0
|
||||
|
||||
# ansible_check_mode is not used: the play-level `check_mode: true` keyword does not set that
|
||||
# magic variable inside include_role tasks (only --check does). A command task
|
||||
# is skipped in both forms and its result says so, the same probe as tasks/service_rules.yml.
|
||||
# magic variable inside include_role tasks (only --check does). A command does not run in either
|
||||
# form, so its output is missing; the same probe as tasks/service_rules.yml. Not `is skipped`:
|
||||
# ansible-core 2.25 drops that check-mode result.
|
||||
- name: Probe whether the run is in check mode
|
||||
ansible.builtin.command: "true"
|
||||
ansible.builtin.command: echo ran
|
||||
register: ufw_sysctl_probe
|
||||
changed_when: false
|
||||
when: ufw_enabled and ufw_sysctl_overrides | length > 0
|
||||
|
||||
- name: Remember whether the run is in check mode
|
||||
ansible.builtin.set_fact:
|
||||
ufw_sysctl_check: "{{ ufw_sysctl_probe is skipped }}"
|
||||
ufw_sysctl_check: "{{ ufw_sysctl_probe.stdout != 'ran' }}"
|
||||
when: ufw_enabled and ufw_sysctl_overrides | length > 0
|
||||
|
||||
# In check mode on a fresh host ufw is not installed yet, so the file is absent.
|
||||
|
||||
Reference in new issue
Block a user