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.postfix.
# 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.postfix
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.postfix
tasks_from: "{{ __sr_tasks_from | default('main') }}"
public: "{{ __sr_public | default(false) }}"
when: __sr_failed_when | d(true)
6 changes: 2 additions & 4 deletions tests/tests_default.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
---
- name: Ensure that the rule runs with default parameters
hosts: all
gather_facts: false
tasks:
- name: Run the postfix role
include_role:
name: linux-system-roles.postfix
public: true
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
__sr_public: true
postfix_manage_firewall: true
postfix_manage_selinux: true

Expand Down
7 changes: 3 additions & 4 deletions tests/tests_disable_ipv6.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
hosts: all
tags:
- tests::reboot
gather_facts: false
tasks:
- name: Disable IPv6
include_role:
Expand All @@ -20,9 +19,9 @@
meta: flush_handlers

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

- name: Enable IPv6
include_role:
Expand Down
13 changes: 5 additions & 8 deletions tests/tests_previous_replaced.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
hosts: all
tasks:
- name: Run the role with previous=replaced only
include_role:
name: linux-system-roles.postfix
public: true
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
__sr_public: true
postfix_manage_firewall: true
postfix_manage_selinux: false
postfix_conf:
Expand All @@ -16,10 +15,9 @@
include_tasks: check_firewall_selinux.yml

- name: Run the role to configure relay_domains and relayhost
include_role:
name: linux-system-roles.postfix
public: true
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
__sr_public: true
postfix_manage_firewall: true
postfix_manage_selinux: true
postfix_conf:
Expand All @@ -39,8 +37,7 @@
__fingerprint: "system_role:postfix"

- name: Reset all settings and configure relay_domains
include_role:
name: linux-system-roles.postfix
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
postfix_conf:
previous: replaced
Expand Down
6 changes: 3 additions & 3 deletions tests/tests_set_banner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

tasks:
- name: Run the role with test smtpd_banner
include_role:
name: linux-system-roles.postfix
public: true
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
__sr_public: true

- name: Get smtpd banner
command: postconf smtpd_banner
Expand Down
17 changes: 10 additions & 7 deletions tests/tests_set_file.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

tasks:
- name: Run the role with test postmap file
include_role:
name: linux-system-roles.postfix
public: true
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
__sr_public: true

- name: Check if postmap file exists
stat:
Expand All @@ -27,16 +27,19 @@
assert:
that: test_file.stat.exists

- name: Set fact for relay_domains check (ansible version)
set_fact:
__sr_when_relay_domains_check: "{{ ansible_version['major'] > 2 or ansible_version['minor'] > 9 }}"

- name: Check relay_domains
when: ansible_version["major"] > 2 or ansible_version["minor"] > 9
when: __sr_when_relay_domains_check
block:
# cannot use postfix_default_database_type with postfix_conf
# in ansible 2.9
- name: Run the role to test postfix_default_database_type
include_role:
name: linux-system-roles.postfix
public: true
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
__sr_public: true
postfix_conf:
relay_domains: "{{
postfix_default_database_type }}:/etc/postfix/relay_domains"
Expand Down
Loading