Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions tasks/main-blivet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,10 @@
extra_pkgs:
- kpartx

- name: Get service facts
service_facts:
when: storage_skip_checks is not defined or
not "service_facts" in storage_skip_checks

# rejectattr required because the fix to service_facts is on Ansible > 2.12 only
# https://github.com/ansible/ansible/pull/75326
- name: Set storage_cryptsetup_services
set_fact:
- name: Manage storage devices and check for errors
vars:
# rejectattr required because the fix to service_facts is on Ansible > 2.12 only
# https://github.com/ansible/ansible/pull/75326
storage_cryptsetup_services: "{{
ansible_facts.services.values() |
selectattr('name', 'defined') |
Comment on lines 62 to 64
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): Using a block-level vars for storage_cryptsetup_services prevents it from seeing services gathered by service_facts in the same block

Because block-level vars are evaluated before any tasks in the block run, storage_cryptsetup_services is computed once, when ansible_facts still lacks services. It becomes [] via the if 'services' in ansible_facts else [] guard and is never recomputed after service_facts populates ansible_facts.services, so the later systemd masking step sees an empty list and is a no-op on the first run.

To have storage_cryptsetup_services use the newly gathered service facts, either move this expression into a set_fact that runs after service_facts, or define it as task-level vars on the systemd (or other consuming) tasks so it evaluates after service_facts has executed. Otherwise, cryptsetup services will be skipped when service facts weren’t pre-existing.

Expand All @@ -72,10 +67,15 @@
rejectattr('status', 'match', '^failed$') |
map(attribute='name') |
select('match', '^systemd-cryptsetup@') |
list }}"

- name: Manage storage devices and check for errors
list
if 'services' in ansible_facts else [] }}"
block:
- name: Get service facts
service_facts:
when:
- not "services" in ansible_facts
- not "cryptsetup_services" in storage_skip_checks | d([])

- name: Mask the systemd cryptsetup services
systemd:
name: "{{ item }}"
Expand Down
39 changes: 39 additions & 0 deletions tests/tasks/run_role_with_clear_facts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
# Task file: save facts, clear_facts, run linux-system-roles.storage, then restore facts.
# Include this with include_tasks or import_tasks; ensure tests/library is in module search path.
# Input:
# - __sr_tasks_from: tasks_from to run - same as tasks_from in include_role
# - __sr_public: export private vars from role - same as public in include_role
# - __sr_failed_when: set to false to ignore role errors - same as failed_when in include_role
# Output:
# - ansible_facts: merged saved ansible_facts with ansible_facts modified by the role, if any
- name: Clear facts
meta: clear_facts

# note that you can use failed_when with import_role but not with include_role
# so this simulates the __sr_failed_when false case
# Q: Why do we need a separate task to run the role normally? Why not just
# run the role in the block and rethrow the error in the rescue block?
# A: Because you cannot rethrow the error in exactly the same way as the role does.
# It might be possible to exactly reconstruct ansible_failed_result but it's not worth the effort.
- name: Run the role with __sr_failed_when false
when:
- __sr_failed_when is defined
- not __sr_failed_when
block:
- name: Run the role
include_role:
name: linux-system-roles.storage
tasks_from: "{{ __sr_tasks_from | default('main') }}"
public: "{{ __sr_public | default(false) }}"
rescue:
- name: Ignore the failure when __sr_failed_when is false
debug:
msg: Ignoring failure when __sr_failed_when is false

- name: Run the role normally
include_role:
name: linux-system-roles.storage
tasks_from: "{{ __sr_tasks_from | default('main') }}"
public: "{{ __sr_public | default(false) }}"
when: __sr_failed_when | d(true)
16 changes: 5 additions & 11 deletions tests/tests_change_disk_fs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
else 'ext4' }}"
tasks:
- name: Run the role
include_role:
name: linux-system-roles.storage
include_tasks: tasks/run_role_with_clear_facts.yml

- name: Mark tasks to be skipped
set_fact:
Expand All @@ -22,7 +21,6 @@
- "{{ (lookup('env',
'SYSTEM_ROLES_REMOVE_CLOUD_INIT') in ['', 'false']) |
ternary('packages_installed', '') }}"
- service_facts

- name: Get unused disks
include_tasks: get_unused_disk.yml
Expand All @@ -31,8 +29,7 @@
max_return: 1

- name: Create a disk device with the default file system type
include_role:
name: linux-system-roles.storage
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
storage_volumes:
- name: test1
Expand All @@ -44,8 +41,7 @@
include_tasks: verify-role-results.yml

- name: Change the disk device file system type to {{ fs_type_after }}
include_role:
name: linux-system-roles.storage
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
storage_volumes:
- name: test1
Expand All @@ -58,8 +54,7 @@
include_tasks: verify-role-results.yml

- name: Repeat the previous invocation to verify idempotence
include_role:
name: linux-system-roles.storage
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
storage_volumes:
- name: test1
Expand All @@ -72,8 +67,7 @@
include_tasks: verify-role-results.yml

- name: Clean up
include_role:
name: linux-system-roles.storage
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
storage_volumes:
- name: test1
Expand Down
16 changes: 5 additions & 11 deletions tests/tests_change_disk_mount.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
changed_when: false

- name: Run the role
include_role:
name: linux-system-roles.storage
include_tasks: tasks/run_role_with_clear_facts.yml

- name: Mark tasks to be skipped
set_fact:
Expand All @@ -30,7 +29,6 @@
- "{{ (lookup('env',
'SYSTEM_ROLES_REMOVE_CLOUD_INIT') in ['', 'false']) |
ternary('packages_installed', '') }}"
- service_facts

- name: Get unused disks
include_tasks: get_unused_disk.yml
Expand All @@ -39,8 +37,7 @@
max_return: 1

- name: Create a disk device mounted at "{{ mount_location_before }}"
include_role:
name: linux-system-roles.storage
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
storage_volumes:
- name: test1
Expand All @@ -52,8 +49,7 @@
include_tasks: verify-role-results.yml

- name: Change the disk device mount location to {{ mount_location_after }}
include_role:
name: linux-system-roles.storage
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
storage_volumes:
- name: test1
Expand All @@ -65,8 +61,7 @@
include_tasks: verify-role-results.yml

- name: Repeat the previous invocation to verify idempotence
include_role:
name: linux-system-roles.storage
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
storage_volumes:
- name: test1
Expand All @@ -78,8 +73,7 @@
include_tasks: verify-role-results.yml

- name: Clean up
include_role:
name: linux-system-roles.storage
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
storage_volumes:
- name: test1
Expand Down
23 changes: 7 additions & 16 deletions tests/tests_change_fs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@

tasks:
- name: Run the role
include_role:
name: linux-system-roles.storage
include_tasks: tasks/run_role_with_clear_facts.yml

- name: Mark tasks to be skipped
set_fact:
Expand All @@ -24,7 +23,6 @@
- "{{ (lookup('env',
'SYSTEM_ROLES_REMOVE_CLOUD_INIT') in ['', 'false']) |
ternary('packages_installed', '') }}"
- service_facts

- name: Get unused disks
include_tasks: get_unused_disk.yml
Expand All @@ -33,8 +31,7 @@
max_return: 1

- name: Create a LVM logical volume with default fs_type
include_role:
name: linux-system-roles.storage
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
storage_pools:
- name: foo
Expand All @@ -48,8 +45,7 @@
include_tasks: verify-role-results.yml

- name: Change the file system signature on the logical volume created above
include_role:
name: linux-system-roles.storage
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
storage_pools:
- name: foo
Expand All @@ -64,8 +60,7 @@
include_tasks: verify-role-results.yml

- name: Re-run the role on the same volume without specifying fs_type
include_role:
name: linux-system-roles.storage
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
storage_pools:
- name: foo
Expand All @@ -86,8 +81,7 @@
include_tasks: verify-role-results.yml

- name: Repeat the previous invocation to verify idempotence
include_role:
name: linux-system-roles.storage
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
storage_pools:
- name: foo
Expand All @@ -102,8 +96,7 @@
include_tasks: verify-role-results.yml

- name: Remove the FS
include_role:
name: linux-system-roles.storage
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
storage_pools:
- name: foo
Expand All @@ -116,10 +109,8 @@
- name: Verify role results - 5
include_tasks: verify-role-results.yml


- name: Clean up
include_role:
name: linux-system-roles.storage
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
storage_pools:
- name: foo
Expand Down
16 changes: 5 additions & 11 deletions tests/tests_change_fs_use_partitions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
- tests::lvm
tasks:
- name: Run the role
include_role:
name: linux-system-roles.storage
include_tasks: tasks/run_role_with_clear_facts.yml

- name: Mark tasks to be skipped
set_fact:
Expand All @@ -25,7 +24,6 @@
- "{{ (lookup('env',
'SYSTEM_ROLES_REMOVE_CLOUD_INIT') in ['', 'false']) |
ternary('packages_installed', '') }}"
- service_facts

- name: Get unused disks
include_tasks: get_unused_disk.yml
Expand All @@ -34,8 +32,7 @@
max_return: 1

- name: Create an LVM partition with the default file system type
include_role:
name: linux-system-roles.storage
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
storage_pools:
- name: bar
Expand All @@ -49,8 +46,7 @@
include_tasks: verify-role-results.yml

- name: Change the LVM partition file system type to {{ fs_type_after }}
include_role:
name: linux-system-roles.storage
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
storage_pools:
- name: bar
Expand All @@ -65,8 +61,7 @@
include_tasks: verify-role-results.yml

- name: Repeat the previous invocation to verify idempotence
include_role:
name: linux-system-roles.storage
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
storage_pools:
- name: bar
Expand All @@ -81,8 +76,7 @@
include_tasks: verify-role-results.yml

- name: Clean up
include_role:
name: linux-system-roles.storage
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
storage_pools:
- name: bar
Expand Down
16 changes: 5 additions & 11 deletions tests/tests_change_mount.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@

tasks:
- name: Run the role
include_role:
name: linux-system-roles.storage
include_tasks: tasks/run_role_with_clear_facts.yml

- name: Mark tasks to be skipped
set_fact:
Expand All @@ -21,7 +20,6 @@
- "{{ (lookup('env',
'SYSTEM_ROLES_REMOVE_CLOUD_INIT') in ['', 'false']) |
ternary('packages_installed', '') }}"
- service_facts

- name: Get unused disks
include_tasks: get_unused_disk.yml
Expand All @@ -30,8 +28,7 @@
max_return: 1

- name: Create a LVM logical volume mounted at {{ mount_location_before }}
include_role:
name: linux-system-roles.storage
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
storage_pools:
- name: foo
Expand All @@ -45,8 +42,7 @@
include_tasks: verify-role-results.yml

- name: Change the mount location to {{ mount_location_after }}
include_role:
name: linux-system-roles.storage
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
storage_pools:
- name: foo
Expand All @@ -60,8 +56,7 @@
include_tasks: verify-role-results.yml

- name: Repeat the previous invocation to verify idempotence
include_role:
name: linux-system-roles.storage
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
storage_pools:
- name: foo
Expand All @@ -75,8 +70,7 @@
include_tasks: verify-role-results.yml

- name: Clean up
include_role:
name: linux-system-roles.storage
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
storage_pools:
- name: foo
Expand Down
Loading
Loading