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
7 changes: 3 additions & 4 deletions tests/setup-snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
__snapshot_gather_vars: true
tasks:
- name: Set platform/version specific variables
include_role:
name: linux-system-roles.logging
public: true

include_tasks: tasks/run_role_with_clear_facts.yml
vars:
__sr_public: true
- name: Install test packages
package:
# not really invalid - see https://github.com/ansible/ansible-lint/issues/4702
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.logging.
# 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.logging
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.logging
tasks_from: "{{ __sr_tasks_from | default('main') }}"
public: "{{ __sr_public | default(false) }}"
when: __sr_failed_when | d(true)
52 changes: 14 additions & 38 deletions tests/tests_basics_files.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,8 @@
logging_inputs:
- name: basic_input
type: basics
include_role:
name: linux-system-roles.logging
public: true

# notify Restart rsyslogd is executed at the end of this test task.
# thus we have to force to invoke handlers
__sr_public: true
include_tasks: tasks/run_role_with_clear_facts.yml
- name: "Force all notified handlers to run at this point,
not waiting for normal sync points"
meta: flush_handlers
Expand Down Expand Up @@ -92,10 +88,8 @@
logging_inputs: []
logging_outputs: []
logging_flows: []
include_role:
name: linux-system-roles.logging
public: true

__sr_public: true
include_tasks: tasks/run_role_with_clear_facts.yml
- name: Check ports managed by firewall and selinux - 2
include_tasks: tasks/check_firewall_selinux.yml

Expand Down Expand Up @@ -125,12 +119,8 @@
- name: flows0
inputs: [basic_input]
outputs: [files_output0]
include_role:
name: linux-system-roles.logging
public: true

# notify Restart rsyslogd is executed at the end of this test task.
# thus we have to force to invoke handlers
__sr_public: true
include_tasks: tasks/run_role_with_clear_facts.yml
- name: "Force all notified handlers to run at this point,
not waiting for normal sync points - 3"
meta: flush_handlers
Expand Down Expand Up @@ -178,10 +168,8 @@
logging_inputs: []
logging_outputs: []
logging_flows: []
include_role:
name: linux-system-roles.logging
public: true

__sr_public: true
include_tasks: tasks/run_role_with_clear_facts.yml
- name: Check ports managed by firewall and selinux - 4
include_tasks: tasks/check_firewall_selinux.yml

Expand Down Expand Up @@ -235,9 +223,7 @@
- files_output1
- files_output2
- files_output3
include_role:
name: linux-system-roles.logging

include_tasks: tasks/run_role_with_clear_facts.yml
- name: Unreachable task
fail:
msg: UNREACH
Expand All @@ -256,11 +242,7 @@
logging_inputs: []
logging_outputs: []
logging_flows: []
include_role:
name: linux-system-roles.logging

# notify Restart rsyslogd is executed at the end of this test task.
# thus we have to force to invoke handlers
include_tasks: tasks/run_role_with_clear_facts.yml
- name: "Force all notified handlers to run at this point,
not waiting for normal sync points - 5"
meta: flush_handlers
Expand Down Expand Up @@ -322,12 +304,8 @@
property(name="timestamp" dateFormat="rfc3339")
constant(value=" ThisIsBasicTestFormat\n")
}
include_role:
name: linux-system-roles.logging
public: true

# notify Restart rsyslogd is executed at the end of this test task.
# thus we have to force to invoke handlers
__sr_public: true
include_tasks: tasks/run_role_with_clear_facts.yml
- name: "Force all notified handlers to run at this point,
not waiting for normal sync points - 6"
meta: flush_handlers
Expand Down Expand Up @@ -407,10 +385,8 @@
logging_inputs: []
logging_outputs: []
logging_flows: []
include_role:
name: linux-system-roles.logging
public: true

__sr_public: true
include_tasks: tasks/run_role_with_clear_facts.yml
- name: Check ports managed by firewall and selinux - 6
include_tasks: tasks/check_firewall_selinux.yml

Expand Down
48 changes: 9 additions & 39 deletions tests/tests_basics_forwards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,8 @@
- forwards_no_severity_and_facility_protocol_port
- forwards_no_severity_and_facility_protocol_port_target
- default_files
include_role:
name: linux-system-roles.logging
public: true

# notify Restart rsyslogd is executed at the end of this test task.
# thus we have to force to invoke handlers
__sr_public: true
include_tasks: tasks/run_role_with_clear_facts.yml
- name: "Force all notified handlers to run at this point,
not waiting for normal sync points"
meta: flush_handlers
Expand Down Expand Up @@ -299,11 +295,7 @@
logging_inputs: []
logging_outputs: []
logging_flows: []
include_role:
name: linux-system-roles.logging

# notify Restart rsyslogd is executed at the end of this test task.
# thus we have to force to invoke handlers
include_tasks: tasks/run_role_with_clear_facts.yml
- name: "Force all notified handlers to run at this point,
not waiting for normal sync points"
meta: flush_handlers
Expand Down Expand Up @@ -343,11 +335,7 @@
- name: flows0
inputs: [basic_input]
outputs: [forwards_severity_and_facility]
include_role:
name: linux-system-roles.logging

# notify Restart rsyslogd is executed at the end of this test task.
# thus we have to force to invoke handlers
include_tasks: tasks/run_role_with_clear_facts.yml
- name: "Force all notified handlers to run at this point,
not waiting for normal sync points"
meta: flush_handlers
Expand Down Expand Up @@ -403,11 +391,7 @@
logging_inputs: []
logging_outputs: []
logging_flows: []
include_role:
name: linux-system-roles.logging

# notify Restart rsyslogd is executed at the end of this test task.
# thus we have to force to invoke handlers
include_tasks: tasks/run_role_with_clear_facts.yml
- name: "Force all notified handlers to run at this point,
not waiting for normal sync points"
meta: flush_handlers
Expand Down Expand Up @@ -457,11 +441,7 @@
- name: flows0
inputs: [basic_input]
outputs: [forwards_severity_and_facility]
include_role:
name: linux-system-roles.logging

# notify Restart rsyslogd is executed at the end of this test task.
# thus we have to force to invoke handlers
include_tasks: tasks/run_role_with_clear_facts.yml
- name: "Force all notified handlers to run at this point,
not waiting for normal sync points"
meta: flush_handlers
Expand Down Expand Up @@ -523,11 +503,7 @@
logging_inputs: []
logging_outputs: []
logging_flows: []
include_role:
name: linux-system-roles.logging

# notify Restart rsyslogd is executed at the end of this test task.
# thus we have to force to invoke handlers
include_tasks: tasks/run_role_with_clear_facts.yml
- name: "Force all notified handlers to run at this point,
not waiting for normal sync points"
meta: flush_handlers
Expand Down Expand Up @@ -577,9 +553,7 @@
- name: flows0
inputs: [basic_input]
outputs: [forwards_severity_and_facility]
include_role:
name: linux-system-roles.logging

include_tasks: tasks/run_role_with_clear_facts.yml
- name: Unreachable task
fail:
msg: UNREACH
Expand All @@ -599,11 +573,7 @@
logging_inputs: []
logging_outputs: []
logging_flows: []
include_role:
name: linux-system-roles.logging

# notify Restart rsyslogd is executed at the end of this test task.
# thus we have to force to invoke handlers
include_tasks: tasks/run_role_with_clear_facts.yml
- name: "Force all notified handlers to run at this point,
not waiting for normal sync points"
meta: flush_handlers
Expand Down
4 changes: 1 addition & 3 deletions tests/tests_cert_container.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
- name: logging_cert
dns: ['localhost', 'www.example.com']
ca: self-sign
include_role:
name: linux-system-roles.logging

include_tasks: tasks/run_role_with_clear_facts.yml
- name: Unreachable task
fail:
msg: UNREACH
Expand Down
Loading
Loading