diff --git a/tests/tasks/run_role_with_clear_facts.yml b/tests/tasks/run_role_with_clear_facts.yml new file mode 100644 index 00000000..4a625608 --- /dev/null +++ b/tests/tasks/run_role_with_clear_facts.yml @@ -0,0 +1,37 @@ +--- +# Task file: clear_facts, run linux-system-roles.tlog. +# Include this with include_tasks or import_tasks +# 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 +- 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.tlog + 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.tlog + tasks_from: "{{ __sr_tasks_from | default('main') }}" + public: "{{ __sr_public | default(false) }}" + when: __sr_failed_when | d(true) diff --git a/tests/tests_cockpit.yml b/tests/tests_cockpit.yml index 1a6d0cf2..1a051ff5 100644 --- a/tests/tests_cockpit.yml +++ b/tests/tests_cockpit.yml @@ -20,8 +20,9 @@ state: absent - name: Test role without cockpit - import_role: - name: linux-system-roles.tlog + include_tasks: tasks/run_role_with_clear_facts.yml + vars: + __sr_public: true - name: Get the rpm package facts without cockpit installed package_facts: @@ -36,8 +37,9 @@ state: present - name: Test role with cockpit - import_role: - name: linux-system-roles.tlog + include_tasks: tasks/run_role_with_clear_facts.yml + vars: + __sr_public: true - name: Get the rpm package facts with cockpit installed package_facts: diff --git a/tests/tests_default.yml b/tests/tests_default.yml index 37fd6f32..654ed191 100644 --- a/tests/tests_default.yml +++ b/tests/tests_default.yml @@ -1,9 +1,9 @@ --- - name: Ensure that the role runs with default parameters hosts: all - roles: - - linux-system-roles.tlog - gather_facts: false pre_tasks: - name: Test setup and check for ostree include_tasks: tasks/setup.yml + tasks: + - name: Run the role + include_tasks: tasks/run_role_with_clear_facts.yml diff --git a/tests/tests_default_vars.yml b/tests/tests_default_vars.yml index 4c73c309..8199c7a3 100644 --- a/tests/tests_default_vars.yml +++ b/tests/tests_default_vars.yml @@ -1,12 +1,14 @@ --- - name: Ensure that the role declares all parameters in defaults hosts: all - roles: - - linux-system-roles.tlog pre_tasks: - name: Test setup and check for ostree include_tasks: tasks/setup.yml tasks: + - name: Run the role + include_tasks: tasks/run_role_with_clear_facts.yml + vars: + __sr_public: true - name: Check that all variables are defined assert: that: "vars[item] is defined" diff --git a/tests/tests_example.yml b/tests/tests_example.yml index f60b3088..961d6461 100644 --- a/tests/tests_example.yml +++ b/tests/tests_example.yml @@ -1,8 +1,6 @@ --- - name: Ensure that the README example play runs hosts: all - roles: - - linux-system-roles.tlog vars: tlog_scope_sssd: some tlog_users_sssd: @@ -10,3 +8,6 @@ pre_tasks: - name: Test setup and check for ostree include_tasks: tasks/setup.yml + tasks: + - name: Run the role + include_tasks: tasks/run_role_with_clear_facts.yml diff --git a/tests/tests_sssd.yml b/tests/tests_sssd.yml index 8f65b1b5..83209f85 100644 --- a/tests/tests_sssd.yml +++ b/tests/tests_sssd.yml @@ -7,10 +7,18 @@ include_tasks: tasks/setup.yml - name: Run role with default sssd settings - import_role: - name: linux-system-roles.tlog + include_tasks: tasks/run_role_with_clear_facts.yml + vars: + __sr_public: true when: not __bootc_validation | d(false) + - name: Run role only to load facts and role private variables for bootc validation + include_role: + name: linux-system-roles.tlog + tasks_from: set_vars.yml + public: true + when: __bootc_validation | d(false) + - name: Create QEMU deployment during bootc end-to-end test delegate_to: localhost become: false @@ -26,8 +34,9 @@ tlog_scope_sssd: all block: - name: Run role - import_role: - name: linux-system-roles.tlog + include_tasks: tasks/run_role_with_clear_facts.yml + vars: + __sr_public: true - name: Check sssd authselect with tlog setup properly import_tasks: check_sssd_with_tlog.yml @@ -49,8 +58,9 @@ - students block: - name: Run role - import_role: - name: linux-system-roles.tlog + include_tasks: tasks/run_role_with_clear_facts.yml + vars: + __sr_public: true - name: Run sssd tests import_tasks: run_sssd_tests.yml @@ -65,8 +75,9 @@ - admins block: - name: Run role - import_role: - name: linux-system-roles.tlog + include_tasks: tasks/run_role_with_clear_facts.yml + vars: + __sr_public: true - name: Run sssd tests import_tasks: run_sssd_tests.yml