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.ssh,.
# 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.ssh
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.ssh
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_additional_packages.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
- name: Verify default packages as well as additional are installed
hosts: all
gather_facts: true
vars:
additional_package: >-
{% if ansible_facts['distribution'] in [ 'RedHat', 'CentOS' ] and
Expand All @@ -16,8 +15,7 @@
{% endif %}
tasks:
- name: Run role
include_role:
name: linux-system-roles.ssh
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
ssh_additional_packages:
- "{{ additional_package | trim }}"
Expand Down
4 changes: 1 addition & 3 deletions tests/tests_all_options.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
- name: Test we can handle all configuration options documented in manual page
hosts: all
gather_facts: true
vars:
ssh_c: {}
pkg_mgr: "{{ (ansible_facts['distribution_version'] | int > 7) |
Expand Down Expand Up @@ -102,8 +101,7 @@
"{{ ssh_options.stdout_lines }}"

- name: Run role
include_role:
name: linux-system-roles.ssh
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
__ssh_supports_validate: false
ssh_config_file: /etc/test_ssh_config
Expand Down
6 changes: 2 additions & 4 deletions tests/tests_backup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
with_items: "{{ backup_files.files }}"

- name: Configure ssh without creating backup
ansible.builtin.include_role:
name: linux-system-roles.ssh
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
ssh_backup: false

Expand All @@ -34,8 +33,7 @@
register: no_backup

- name: Configure ssh again with different configuration and with backup
ansible.builtin.include_role:
name: linux-system-roles.ssh
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
ssh_ForwardX11Trusted: 'yes' # noqa var-naming
register: second_run
Expand Down
3 changes: 1 addition & 2 deletions tests/tests_custom_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
hosts: all
tasks:
- name: Run role
include_role:
name: linux-system-roles.ssh
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
ssh:
Compression: true
Expand Down
4 changes: 1 addition & 3 deletions tests/tests_custom_drop_in.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
- name: Test we can write any other configuration file as a drop-in
hosts: all
gather_facts: true
vars:
__ssh_test_backup_files:
- /tmp/ssh_config.d_00-ansible.conf
Expand All @@ -21,8 +20,7 @@
include_tasks: tasks/backup.yml

- name: Run role
include_role:
name: linux-system-roles.ssh
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
ssh:
Compression: true
Expand Down
3 changes: 1 addition & 2 deletions tests/tests_custom_with_defaults.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
hosts: all
tasks:
- name: Run role
include_role:
name: linux-system-roles.ssh
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
ssh:
Compression: true
Expand Down
8 changes: 5 additions & 3 deletions tests/tests_default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@

- name: Ensure that the role runs with default parameters
hosts: all
gather_facts: false
roles:
- linux-system-roles.ssh
tasks:
- name: Run role
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
__sr_public: true

- name: Restore configuration files
hosts: all
Expand Down
4 changes: 1 addition & 3 deletions tests/tests_global_config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
- name: Test we can write global config with default configuration
gather_facts: true
hosts: all
vars:
__ssh_test_backup_files:
Expand All @@ -12,8 +11,7 @@
include_tasks: tasks/backup.yml

- name: Run role
include_role:
name: linux-system-roles.ssh
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
# noqa var-naming
ssh:
Expand Down
4 changes: 1 addition & 3 deletions tests/tests_global_config_mode.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
- name: Test we can write global config with given permissions
hosts: all
gather_facts: true
vars:
__ssh_test_backup_files:
- /etc/ssh/ssh_config.d/00-ansible.conf
Expand All @@ -16,8 +15,7 @@
include_tasks: tasks/backup.yml

- name: Run role
include_role:
name: linux-system-roles.ssh
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
ssh:
Compression: true
Expand Down
4 changes: 1 addition & 3 deletions tests/tests_global_drop_in.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
- name: Test forced creation of the configuration snippet in drop in directory
hosts: all
gather_facts: true
vars:
__ssh_test_backup_files:
- /etc/ssh/ssh_config.d/99-last.conf
Expand All @@ -20,8 +19,7 @@
include_tasks: tasks/backup.yml

- name: Run role
include_role:
name: linux-system-roles.ssh
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
ssh_drop_in_name: 99-last
ssh:
Expand Down
23 changes: 12 additions & 11 deletions tests/tests_global_drop_in_role.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
- name: Test forced creation of the configuration snippet in drop in directory
hosts: all
gather_facts: true
vars:
__ssh_test_backup_files:
- /etc/ssh/ssh_config.d/99-last.conf
Expand All @@ -12,16 +11,18 @@

- name: Run role
hosts: all
roles:
- linux-system-roles.ssh
vars:
ssh_drop_in_name: 99-last
ssh:
GSSAPIAuthentication: false
Host:
Condition: example
Hostname: example.com
User: somebody
tasks:
- name: Run role
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
__sr_public: true
ssh_drop_in_name: 99-last
ssh:
GSSAPIAuthentication: false
Host:
Condition: example
Hostname: example.com
User: somebody

- name: Verify drop in file configuration
hosts: all
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 include variable override
hosts: all
gather_facts: true
tasks:
- name: Create var file in caller that can override the one in called role
delegate_to: localhost
Expand Down
4 changes: 1 addition & 3 deletions tests/tests_indentation.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
- name: Test indentation
gather_facts: true
hosts: all
vars:
ssh_config_file: /tmp/ssh_config
Expand All @@ -9,8 +8,7 @@
include_tasks: tasks/backup.yml

- name: Run role
include_role:
name: linux-system-roles.ssh
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
# noqa var-naming
ssh:
Expand Down
4 changes: 1 addition & 3 deletions tests/tests_match.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
- name: Verify Match and Host keywords are rendered as expected
hosts: all
gather_facts: true
vars:
__ssh_test_backup_files:
- /etc/ssh/ssh_config.d/00-ansible.conf
Expand All @@ -12,8 +11,7 @@
include_tasks: tasks/backup.yml

- name: Run role
include_role:
name: linux-system-roles.ssh
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
# noqa var-naming
ssh:
Expand Down
4 changes: 1 addition & 3 deletions tests/tests_no_skip_defaults.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
- name: Test we can write global config with default configuration
hosts: all
gather_facts: true
vars:
__ssh_test_backup_files:
- /etc/ssh/ssh_config.d/00-ansible.conf
Expand All @@ -22,8 +21,7 @@
include_tasks: tasks/backup.yml

- name: Run role
include_role:
name: linux-system-roles.ssh
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
ssh_skip_defaults: false
ssh_config_file: /tmp/ssh_config_with_defaults
Expand Down
4 changes: 1 addition & 3 deletions tests/tests_precedence.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
- name: Test options precedence when mixing ssh dict and ssh_* variables
hosts: all
gather_facts: true
vars:
__ssh_test_backup_files:
- /etc/ssh/ssh_config.d/00-ansible.conf
Expand All @@ -12,8 +11,7 @@
include_tasks: tasks/backup.yml

- name: Run role
include_role:
name: linux-system-roles.ssh
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
# noqa var-naming
ssh:
Expand Down
4 changes: 1 addition & 3 deletions tests/tests_regenerate_defaults.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
- name: Regenerate default configuration file
hosts: all
gather_facts: true
vars:
__ssh_test_backup_files:
- /etc/ssh/ssh_config.d/00-ansible.conf
Expand Down Expand Up @@ -36,8 +35,7 @@
path: /etc/ssh/ssh_config

- name: Run role
include_role:
name: linux-system-roles.ssh
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
ssh_config_file: /etc/ssh/ssh_config
ssh_skip_defaults: false
Expand Down
4 changes: 1 addition & 3 deletions tests/tests_user_config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
- name: Test a creation of configuration file in the user directory
hosts: all
gather_facts: true
vars:
__ssh_test_backup_files:
- /etc/ssh/ssh_config.d/00-ansible.conf
Expand All @@ -23,8 +22,7 @@
group: "{{ username }}"

- name: Run role
include_role:
name: linux-system-roles.ssh
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
ssh_user: "{{ username }}"
ssh:
Expand Down
Loading