From 88aea98e54ebf23763d6574d7361a55637532dee Mon Sep 17 00:00:00 2001 From: Jiri Kucera Date: Fri, 31 May 2019 13:07:48 +0200 Subject: [PATCH 1/2] Run tests_default both in normal and in check mode Add a playbook that works as a wrapper that runs tests of role with default parameters both in normal and in check mode. --- tests/inventory.yaml.j2 | 1 + tests/tests_default_wrapper.yml | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 tests/inventory.yaml.j2 create mode 100644 tests/tests_default_wrapper.yml diff --git a/tests/inventory.yaml.j2 b/tests/inventory.yaml.j2 new file mode 100644 index 0000000..0ef9a45 --- /dev/null +++ b/tests/inventory.yaml.j2 @@ -0,0 +1 @@ +{{ { 'all': { 'hosts': hostvars } } | to_yaml }} diff --git a/tests/tests_default_wrapper.yml b/tests/tests_default_wrapper.yml new file mode 100644 index 0000000..274b7d0 --- /dev/null +++ b/tests/tests_default_wrapper.yml @@ -0,0 +1,19 @@ + +- name: Create static inventory from hostvars + hosts: all + tasks: + - name: Create static inventory from hostvars + template: + src: inventory.yaml.j2 + dest: inventory.yaml + delegate_to: localhost + +- name: Run tests_default.yml normally + import_playbook: tests_default.yml + +- name: Run tests_default.yml in check_mode + hosts: all + tasks: + - name: Run ansible-playbook with tests_default.yml in check mode + command: ansible-playbook -vvv -i inventory.yaml --check tests_default.yml + delegate_to: localhost From ed52e3154f6138ce1d52569fbc6da4233efd534b Mon Sep 17 00:00:00 2001 From: Pavel Cahyna Date: Fri, 31 May 2019 22:37:57 +0200 Subject: [PATCH 2/2] Use a temporary file and cleanup at the end. XXX we must use delegate_to: localhost instead of hosts: localhost because of the braindamaged localhost group. --- tests/tests_default_wrapper.yml | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/tests/tests_default_wrapper.yml b/tests/tests_default_wrapper.yml index 274b7d0..a768f4c 100644 --- a/tests/tests_default_wrapper.yml +++ b/tests/tests_default_wrapper.yml @@ -1,13 +1,21 @@ - +--- - name: Create static inventory from hostvars hosts: all tasks: + - name: create temporary file + tempfile: + state: file + suffix: .inventory.yaml + register: tempinventory + delegate_to: localhost + - name: Create static inventory from hostvars template: src: inventory.yaml.j2 - dest: inventory.yaml + dest: "{{ tempinventory.path }}" delegate_to: localhost + - name: Run tests_default.yml normally import_playbook: tests_default.yml @@ -15,5 +23,12 @@ hosts: all tasks: - name: Run ansible-playbook with tests_default.yml in check mode - command: ansible-playbook -vvv -i inventory.yaml --check tests_default.yml + command: ansible-playbook -vvv -i {{ tempinventory.path }} --check tests_default.yml + delegate_to: localhost + + - name: remove the temporary file + file: + path: "{{ tempinventory.path }}" + state: absent + when: tempinventory.path is defined delegate_to: localhost