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
37 changes: 37 additions & 0 deletions tests/tasks/run_role_with_clear_facts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
# Task file: clear_facts, run linux-system-roles.ad_integration
# 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.ad_integration
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.ad_integration
tasks_from: "{{ __sr_tasks_from | default('main') }}"
public: "{{ __sr_public | default(false) }}"
when: __sr_failed_when | d(true)
4 changes: 1 addition & 3 deletions tests/tests_basic_join.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
---
- name: Ensure that the role runs with mandatory parameters populated
hosts: all,!ad
gather_facts: false # test that role works in this case
vars:
# sample realm that will skip joining realm step
ad_integration_realm: "{{ __ad_integration_sample_realm }}"
Expand All @@ -14,8 +13,7 @@
__ad_integration_sample_realm: MiXeD.cAsE

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

- name: Test - Check packages are present
block:
Expand Down
4 changes: 1 addition & 3 deletions tests/tests_default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
---
- name: Ensure role behaviour with default parameters
hosts: all,!ad
gather_facts: false # test that role works in this case
tasks:
- name: Verify that the role fails without ad_integration_realm variable
block:
- name: Include the role
include_role:
name: linux-system-roles.ad_integration
include_tasks: tasks/run_role_with_clear_facts.yml

rescue:
- name: Assert that user is notified about missing variables
Expand Down
9 changes: 3 additions & 6 deletions tests/tests_dyndns.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

- name: Ensure that the role configures dynamic dns
hosts: all,!ad
gather_facts: true
vars:
# if we don't have a real AD server, just verify the config
# file is written properly
Expand All @@ -38,10 +37,9 @@
when: __ad_integration_test_sssd_config_only

- name: Test - Run the system role with bogus vars
include_role:
name: linux-system-roles.ad_integration
public: true
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
__sr_public: true
ad_dyndns_iface: TESTING
ad_dyndns_server: 127.0.0.1
ad_dyndns_auth: GSS-TSIG
Expand Down Expand Up @@ -82,8 +80,7 @@
when: sssd_log.stdout | length > 0

- name: Test - Re-run the system role to remove vars
include_role:
name: linux-system-roles.ad_integration
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
ad_dyndns_iface: null
ad_dyndns_server: null
Expand Down
6 changes: 3 additions & 3 deletions tests/tests_full_integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@
block:

- name: Test run the system role
include_role:
name: linux-system-roles.ad_integration
public: true
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
__sr_public: true
register: role_run

- name: Debug role_run
Expand Down
6 changes: 3 additions & 3 deletions tests/tests_full_integration_dc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@
block:

- name: Test run the system role
include_role:
name: linux-system-roles.ad_integration
public: true
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
__sr_public: true
register: role_run

- name: Debug role_run
Expand Down
8 changes: 2 additions & 6 deletions tests/tests_full_integration_dyndns.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

- name: Configure DynDNS on AD
hosts: ad
gather_facts: true
tasks:
- name: Get AD address
set_fact:
Expand Down Expand Up @@ -62,7 +61,6 @@

- name: Ensure that the role configures dynamic dns
hosts: client
gather_facts: true
tasks:
- name: Run the integration
when: "'ad' in groups and groups['ad']"
Expand All @@ -73,10 +71,9 @@
Interface {{ _ad_dyndns_iface | default(ansible_facts['default_ipv4']['interface']) }} and server
: {{ hostvars[groups['ad'][0]].ansible_host }}
- name: Run the system role with proper config
include_role:
name: linux-system-roles.ad_integration
public: true
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
__sr_public: true
ad_dyndns_server: "{{ hostvars[groups['ad'][0]].ansible_host }}"
ad_dyndns_iface: "{{ _ad_dyndns_iface | default(ansible_facts['default_ipv4']['interface']) }}"
ad_dyndns_auth: "none"
Expand Down Expand Up @@ -126,7 +123,6 @@

- name: Check hosts on AD
hosts: ad
gather_facts: true
tasks:
- name: Get network for zone
set_fact:
Expand Down
9 changes: 4 additions & 5 deletions tests/tests_full_integration_force_rejoin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@
block:

- name: Test run the system role
include_role:
name: linux-system-roles.ad_integration
public: true
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
__sr_public: true
register: role_run

- name: Debug role_run
Expand Down Expand Up @@ -98,8 +98,7 @@
changed_when: false

- name: Test run the system role with force rejoin
include_role:
name: linux-system-roles.ad_integration
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
ad_integration_force_rejoin: true
register: role_run_rejoin
Expand Down
1 change: 0 additions & 1 deletion tests/tests_include_vars_from_parent.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
- name: Test role inclusion variable overrides
hosts: all,!ad
gather_facts: true
tasks:
- name: Create var file in caller that can override the one in called role
delegate_to: localhost
Expand Down
3 changes: 1 addition & 2 deletions tests/tests_manage_packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@

# role will fail if ad_integration_manage_packages is not handled correctly
- name: Run the role with ad_integration_manage_packages
include_role:
name: linux-system-roles.ad_integration
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
ad_integration_manage_packages: false

Expand Down
4 changes: 1 addition & 3 deletions tests/tests_migrate_sssd_settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
---
- name: Ensure that the role migrates sssd domain settings depending on case
hosts: all,!ad
gather_facts: true
vars:
ad_integration_realm: MIGRATE.REALM.COM
__ad_integration_test_sssd_config_only: true
Expand Down Expand Up @@ -58,8 +57,7 @@
__ad_integration_realm_list: "domain-name: {{ ad_integration_realm }}"

- name: Test - Run the system role merging duplicate sssd domain sections
include_role:
name: linux-system-roles.ad_integration
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
ad_integration_sssd_custom_settings: "{{ __ad_integration_sssd_custom_settings +
__ad_integration_sssd_custom_settings2 + __ad_integration_sssd_custom_settings3 }}"
Expand Down
4 changes: 1 addition & 3 deletions tests/tests_preserve_authselect.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
---
- name: Ensure that the role ad_integration_preserve_authselect_profile works
hosts: all,!ad
gather_facts: false # test that role works in this case
vars:
# sample realm that will skip joining realm step
ad_integration_realm: "{{ __ad_integration_sample_realm }}"
Expand All @@ -11,8 +10,7 @@

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

- name: Test - Check that realmd config is present
stat:
Expand Down
10 changes: 4 additions & 6 deletions tests/tests_sssd_custom_settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

- name: Ensure that the role configures dynamic dns
hosts: all,!ad
gather_facts: true
vars:
ad_integration_realm: sssd-custom-sample-realm.com
__ad_integration_test_sssd_config_only: true
Expand All @@ -22,9 +21,9 @@
__manage_fake_realm: setup

- name: Test - Run the system role with bogus vars
include_role:
name: linux-system-roles.ad_integration
public: true
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
__sr_public: true

- name: Check custom SSSD settings
community.general.ini_file:
Expand Down Expand Up @@ -59,8 +58,7 @@
map('combine', {'state': 'absent'}) | list }}"

- name: Test - Re-run the system role to remove vars
include_role:
name: linux-system-roles.ad_integration
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
ad_integration_sssd_custom_settings: "{{ update_list }}"

Expand Down
10 changes: 4 additions & 6 deletions tests/tests_sssd_settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

- name: Ensure that the role configures dynamic dns
hosts: all,!ad
gather_facts: false # test that role works in this case
vars:
ad_integration_realm: sample-realm.com
__ad_integration_test_sssd_config_only: true
Expand All @@ -15,9 +14,9 @@

tasks:
- name: Test - Run the system role with bogus vars
include_role:
name: linux-system-roles.ad_integration
public: true
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
__sr_public: true

- name: Check SSSD settings
community.general.ini_file:
Expand Down Expand Up @@ -52,8 +51,7 @@
map('combine', {'state': 'absent'}) | list }}"

- name: Test - Re-run the system role to remove vars
include_role:
name: linux-system-roles.ad_integration
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
ad_integration_sssd_settings: "{{ update_list }}"

Expand Down
Loading