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
6 changes: 3 additions & 3 deletions tests/tasks/install_and_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
- name: Test default settings
block:
- name: Run postgresql role
include_role:
name: linux-system-roles.postgresql
public: true
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
__sr_public: true
when: __run_role | d(true) | bool

- name: Run postgresql role to set vars only
Expand Down
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.postgresql.
# 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.postgresql
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.postgresql
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_bootc_e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@
hosts: all
tags:
- tests::bootc-e2e
gather_facts: false
tasks:
- name: Bootc image build preparation
when: ansible_connection | d("") == "buildah"
block:
- name: Run postgresql role
include_role:
name: linux-system-roles.postgresql
include_tasks: tasks/run_role_with_clear_facts.yml

- name: Create QEMU deployment
delegate_to: localhost
Expand Down
5 changes: 2 additions & 3 deletions tests/tests_config_files.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
- name: Run test and cleanup
block:
- name: Run role with given config
include_role:
name: linux-system-roles.postgresql
public: true
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
__sr_public: true
postgresql_pg_hba_conf:
- type: local
database: all
Expand Down
1 change: 0 additions & 1 deletion tests/tests_default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
---
- name: Ensure that the role runs with default parameters
hosts: all
gather_facts: false
tasks:
- name: Test default settings
include_tasks: tasks/install_and_check.yml
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: Run test
block:
Expand Down
6 changes: 2 additions & 4 deletions tests/tests_input_file.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
---
- name: Ensure that the role runs with input file
hosts: all
gather_facts: false
tasks:
- name: Run test and clean up
block:
- name: Run postgresql role with input file
include_role:
name: linux-system-roles.postgresql
public: true
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
__sr_public: true
postgresql_input_file: simple.sql

- name: Flush handlers
Expand Down
1 change: 0 additions & 1 deletion tests/tests_versions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
---
- name: Test installing and uninstalling all supported versions
hosts: all
gather_facts: true
tasks:
- name: Skip test if distro does not support multiple versions
meta: end_host
Expand Down
Loading