Skip to content

Commit 88ba965

Browse files
committed
Refactor conditional statements for improved readability in configuration checks
1 parent a1cc3de commit 88ba965

File tree

2 files changed

+30
-10
lines changed

2 files changed

+30
-10
lines changed

src/roles/configuration_checks/tasks/disks.yml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@
6363
| map('split', ':')
6464
| map('list'))
6565
}}
66-
when: device_lun_mapping_raw is defined and device_lun_mapping_raw.stdout_lines | length > 0
66+
when:
67+
- device_lun_mapping_raw is defined
68+
- device_lun_mapping_raw.stdout_lines | length > 0
6769

6870
- name: Set empty device_lun_map if no mapping found
6971
ansible.builtin.set_fact:
@@ -76,12 +78,16 @@
7678
verbosity: 1
7779

7880
- name: Extract disk names
79-
when: disks_metadata is not failed and disks_metadata.json is defined
81+
when:
82+
- disks_metadata is not failed
83+
- disks_metadata.json is defined
8084
ansible.builtin.set_fact:
8185
azure_disk_names: "{{ disks_metadata.json | map(attribute='name') | list }}"
8286

8387
- name: Collect detailed azure disks data (loop per disk defined in azure_disk_names)
84-
when: azure_disk_names is defined and azure_disk_names | length > 0
88+
when:
89+
- azure_disk_names is defined
90+
- azure_disk_names | length > 0
8591
register: azure_disks_metadata_results
8692
loop: "{{ azure_disk_names }}"
8793
delegate_to: localhost
@@ -148,7 +154,9 @@
148154
verbosity: 1
149155

150156
- name: Collect AFS storage data if NFS is used
151-
when: NFS_provider is defined and 'AFS' in NFS_provider
157+
when:
158+
- NFS_provider is defined
159+
- "'AFS' in NFS_provider"
152160
register: afs_storage_metadata_results
153161
delegate_to: localhost
154162
ansible.builtin.shell:

src/roles/configuration_checks/tasks/main.yml

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,9 @@
124124
when: command_checks is defined or azure_checks is defined or module_checks is defined
125125

126126
- name: "{{ check_type.name }} - Execute command-based configuration checks"
127-
when: command_checks is defined and command_checks | length > 0
127+
when:
128+
- command_checks is defined
129+
- command_checks | length > 0
128130
block:
129131
- name: "{{ check_type.name }} - Run command-based configuration checks"
130132
become: true
@@ -147,13 +149,17 @@
147149
msg: "Command-based configuration checks failed {{ command_check_results.msg }}"
148150

149151
- name: "{{ check_type.name }} - Debug the logs from configuration check python module"
150-
when: command_check_results is defined and command_check_results.log is defined
152+
when:
153+
- command_check_results is defined
154+
- command_check_results.log is defined
151155
ansible.builtin.debug:
152156
msg: "{{ command_check_results.log }}"
153157
verbosity: 1
154158

155159
- name: "{{ check_type.name }} - Execute Azure-based configuration checks"
156-
when: azure_checks is defined and azure_checks | length > 0
160+
when:
161+
- azure_checks is defined
162+
- azure_checks | length > 0
157163
block:
158164
- name: Run Azure-based configuration checks
159165
become: true
@@ -177,13 +183,17 @@
177183
msg: "Azure-based configuration checks failed but continuing {{ azure_check_results.msg }}"
178184

179185
- name: "{{ check_type.name }} - Debug the formatted filesystem info from configuration check python module"
180-
when: azure_check_results is defined and azure_check_results.formatted_filesystem_info is defined
186+
when:
187+
- azure_check_results is defined
188+
- azure_check_results.formatted_filesystem_info is defined
181189
ansible.builtin.debug:
182190
msg: "{{ azure_check_results.formatted_filesystem_info }}"
183191
verbosity: 1
184192

185193
- name: "{{ check_type.name }} - Execute module-based configuration checks"
186-
when: module_checks is defined and module_checks | length > 0
194+
when:
195+
- module_checks is defined
196+
- module_checks | length > 0
187197
block:
188198
- name: Run module-based configuration checks
189199
become: true
@@ -206,7 +216,9 @@
206216
msg: "Module-based configuration checks failed but continuing {{ module_check_results.msg }}"
207217

208218
- name: "{{ check_type.name }} - Debug the module check results"
209-
when: module_check_results is defined and module_check_results.check_results is defined
219+
when:
220+
- module_check_results is defined
221+
- module_check_results.check_results is defined
210222
ansible.builtin.debug:
211223
msg: "Module checks: {{ module_check_results.check_results | length }} results"
212224
verbosity: 1

0 commit comments

Comments
 (0)