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
39 changes: 39 additions & 0 deletions tests/tasks/run_role_with_clear_facts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
# Task file: save facts, clear_facts, run linux-system-roles.certificate, then restore facts.
# Include this with include_tasks or import_tasks; ensure tests/library is in module search path.
# 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
# Output:
# - ansible_facts: merged saved ansible_facts with ansible_facts modified by the role, if any
- 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.certificate
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.certificate
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_ipa.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
- name: Test using IPA to issue certs
hosts: all
gather_facts: true
become: true
tags:
- tests::slow
Expand All @@ -27,8 +26,7 @@
import_tasks: tasks/setup_ipa.yml

- name: Issue IPA signed certificates
include_role:
name: linux-system-roles.certificate
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
certificate_requests:
- name: mycert_basic_ipa
Expand Down
5 changes: 3 additions & 2 deletions tests/tests_basic_self_signed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
- name: mycert_basic_self_signed
dns: www.example.com
ca: self-sign
roles:
- linux-system-roles.certificate
tasks:
- name: Run the role
include_tasks: tasks/run_role_with_clear_facts.yml

- name: Verify certificate
hosts: all
Expand Down
6 changes: 3 additions & 3 deletions tests/tests_default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
---
- name: Ensure that the role runs with default parameters
hosts: all
gather_facts: false # check that the role works with this
roles:
- linux-system-roles.certificate
tasks:
- name: Run the role
include_tasks: tasks/run_role_with_clear_facts.yml
5 changes: 3 additions & 2 deletions tests/tests_dns_ip_email.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
- sysadmin@example.com
- support@example.com
ca: self-sign
roles:
- linux-system-roles.certificate
tasks:
- name: Run the role
include_tasks: tasks/run_role_with_clear_facts.yml

- name: Verify certificate
hosts: all
Expand Down
6 changes: 2 additions & 4 deletions tests/tests_fs_attrs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@
when: not __bootc_validation | d(false)

- name: Issue certificate setting user/group
include_role:
name: linux-system-roles.certificate
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
certificate_requests:
- name: mycert_fs_attrs
Expand Down Expand Up @@ -87,8 +86,7 @@
mode: "0640"

- name: Issue certificate setting user/group/mode
include_role:
name: linux-system-roles.certificate
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
certificate_requests:
- name: mycert_fs_attrs_mode
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
3 changes: 1 addition & 2 deletions tests/tests_key_size.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
- name: Include role, ignore fail if certmonger version is not supported
block:
- name: Request certificate with key size
ansible.builtin.include_role:
name: linux-system-roles.certificate
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
certificate_requests:
- name: mycert_key_size
Expand Down
8 changes: 2 additions & 6 deletions tests/tests_key_size_reissue.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@
- name: Test re-issue certificate if key size changes
hosts: all
become: false
gather_facts: false

tasks:
- name: Include role, ignore fail if certmonger version is not supported
block:
- name: Request certificate with key size
ansible.builtin.include_role:
name: linux-system-roles.certificate
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
certificate_requests:
- name: mycert_key_size
Expand Down Expand Up @@ -55,8 +52,7 @@
meta: end_play

- name: Request certificate with key size 3072
ansible.builtin.include_role:
name: linux-system-roles.certificate
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
certificate_requests:
- name: mycert_key_size
Expand Down
5 changes: 3 additions & 2 deletions tests/tests_key_usage_and_extended_key_usage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
- id-kp-ipsecTunnel
- 1.3.6.1.5.2.3.5
ca: self-sign
roles:
- linux-system-roles.certificate
tasks:
- name: Run the role
include_tasks: tasks/run_role_with_clear_facts.yml

- name: Verify certificate
hosts: all
Expand Down
3 changes: 1 addition & 2 deletions tests/tests_many_self_signed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

tasks:
- name: Run the role
include_role:
name: linux-system-roles.certificate
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
certificate_requests:
- name: mycert_many_self_signed
Expand Down
5 changes: 3 additions & 2 deletions tests/tests_no_auto_renew.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
- name: defaultcert
dns: www.example.com
ca: self-sign
roles:
- linux-system-roles.certificate
tasks:
- name: Run the role
include_tasks: tasks/run_role_with_clear_facts.yml

- name: Verify certificate
pre_tasks:
Expand Down
5 changes: 3 additions & 2 deletions tests/tests_not_wait_for_cert.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
- name: mycert_not_wait_for_cert
dns: www.example.com
ca: self-sign
roles:
- linux-system-roles.certificate
tasks:
- name: Run the role
include_tasks: tasks/run_role_with_clear_facts.yml

- name: Verify certificate
hosts: all
Expand Down
8 changes: 4 additions & 4 deletions tests/tests_principal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
dns: www.example.com
principal: HTTP/www.example.com@EXAMPLE.COM
ca: self-sign
roles:
- linux-system-roles.certificate
tasks:
- name: Run the role
include_tasks: tasks/run_role_with_clear_facts.yml

- name: Verify certificate
hosts: all
Expand Down Expand Up @@ -57,8 +58,7 @@
It should be formatted as 'primary/instance@REALM'
block:
- name: Import certificate role
import_role:
name: linux-system-roles.certificate
include_tasks: tasks/run_role_with_clear_facts.yml
- name: Failed
fail:
msg: "certificate with invalid principal"
Expand Down
5 changes: 3 additions & 2 deletions tests/tests_provider.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
dns: www.example.com
ca: self-sign
provider: certmonger
roles:
- linux-system-roles.certificate
tasks:
- name: Run the role
include_tasks: tasks/run_role_with_clear_facts.yml

- name: Verify certificate
hosts: all
Expand Down
5 changes: 3 additions & 2 deletions tests/tests_run_hooks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
touch /etc/pki/before_cert.tmp
run_after: >
touch /etc/pki/after_cert.tmp
roles:
- linux-system-roles.certificate
tasks:
- name: Run the role
include_tasks: tasks/run_role_with_clear_facts.yml

- name: Verify certificate
hosts: all
Expand Down
5 changes: 3 additions & 2 deletions tests/tests_subject.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
organization: Red Hat
organizational_unit: Linux
ca: self-sign
roles:
- linux-system-roles.certificate
tasks:
- name: Run the role
include_tasks: tasks/run_role_with_clear_facts.yml

- name: Verify certificate
hosts: all
Expand Down
6 changes: 3 additions & 3 deletions tests/tests_subject_complex.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
common_name: '# \\Every"thing+that,ne;eds<escap>ing\0 '
contact_email: admin@example.com
ca: self-sign
roles:
- linux-system-roles.certificate
tasks:
- name: Run the role
include_tasks: tasks/run_role_with_clear_facts.yml

- name: Verify certificate
hosts: all
Expand All @@ -21,7 +22,6 @@
tasks_from: set_vars.yml
public: true
become: true
gather_facts: true
vars:
certificates:
- path: "{{ __certificate_default_directory }}/certs/mycert_subject_complex.crt"
Expand Down
3 changes: 1 addition & 2 deletions tests/tests_test_mode.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
certificate_test_remove_files: true
tasks:
- name: Run the role in test mode
include_role:
name: linux-system-roles.certificate
include_tasks: tasks/run_role_with_clear_facts.yml

- name: Verify test data
assert:
Expand Down
3 changes: 1 addition & 2 deletions tests/tests_wrong_provider.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
Chosen provider 'fake-provider' is not available.
block:
- name: Import certificate role
import_role:
name: linux-system-roles.certificate
include_tasks: tasks/run_role_with_clear_facts.yml
- name: Failed
fail:
msg: "Certificate issued with nonexistent provider 'fake-provider'."
Expand Down
Loading