From 207d31b4d04bcc5712298e48e5d18717ca833a26 Mon Sep 17 00:00:00 2001 From: Till Maas Date: Mon, 15 Oct 2018 22:19:17 +0200 Subject: [PATCH 1/2] tests: Use vars: with include_tasks Specifying vars as foo=bar does not work anymore with Ansible 2.7. Specify the vars using a dictionary instead. This fixes #89 --- tests/tests_ethernet.yml | 8 ++++++-- tests/tests_helpers-and-asserts.yml | 5 ++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/tests/tests_ethernet.yml b/tests/tests_ethernet.yml index cb4459f..25f117d 100644 --- a/tests/tests_ethernet.yml +++ b/tests/tests_ethernet.yml @@ -19,7 +19,9 @@ type: "{{ type }}" interface: "{{ interface }}" - include_tasks: tasks/show-interfaces.yml - - include_tasks: tasks/manage-test-interface.yml state=present + - include_tasks: tasks/manage-test-interface.yml + vars: + state: present - include_tasks: tasks/assert-device_present.yml - name: Test static interface up @@ -54,5 +56,7 @@ - name: Remove interfaces hosts: all tasks: - - include_tasks: tasks/manage-test-interface.yml state=absent + - include_tasks: tasks/manage-test-interface.yml + vars: + state: absent - include_tasks: tasks/assert-device_absent.yml diff --git a/tests/tests_helpers-and-asserts.yml b/tests/tests_helpers-and-asserts.yml index 33f3e84..36f02c2 100644 --- a/tests/tests_helpers-and-asserts.yml +++ b/tests/tests_helpers-and-asserts.yml @@ -17,7 +17,10 @@ # FIXME: when: does not seem to work with include_tasks, therefore this cannot be safely tested for now # - name: test tap interfaces -# include_tasks: tasks/create-and-remove-interface.yml type=tap interface=tap1298 +# include_tasks: tasks/create-and-remove-interface.yml +# vars: +# - type: tap +# - interface: tap1298 # when: ansible_distribution_major_version > 6 # # ip tuntap does not exist on RHEL6 # # FIXME: Maybe use some other tool to manage devices, openvpn can do this, From 49c7c6a0f46827625d11156aa153029c7cb3ce5a Mon Sep 17 00:00:00 2001 From: Till Maas Date: Mon, 15 Oct 2018 22:20:16 +0200 Subject: [PATCH 2/2] tests: Properly set the name of assert tasks Otherwise it breaks with Ansible 2.7 or does not show the name with previous Ansible versions. --- tests/tasks/assert-device_absent.yml | 4 ++-- tests/tasks/assert-device_present.yml | 4 ++-- tests/tasks/assert-profile_absent.yml | 4 ++-- tests/tasks/assert-profile_present.yml | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/tasks/assert-device_absent.yml b/tests/tasks/assert-device_absent.yml index 06be2b6..f7ca03c 100644 --- a/tests/tasks/assert-device_absent.yml +++ b/tests/tasks/assert-device_absent.yml @@ -1,7 +1,7 @@ # SPDX-License-Identifier: BSD-3-Clause --- - setup: -- assert: - name: "assert that {{ interface }} is absent" +- name: "assert that {{ interface }} is absent" + assert: that: "{{ not interface in ansible_interfaces }}" msg: "{{ interface }} is in ansible_interfaces: {{ ansible_interfaces }}" diff --git a/tests/tasks/assert-device_present.yml b/tests/tasks/assert-device_present.yml index 5c09bd3..e11a2a7 100644 --- a/tests/tasks/assert-device_present.yml +++ b/tests/tasks/assert-device_present.yml @@ -2,7 +2,7 @@ --- # need to run setup again when this is just a task to make sure ansible_interfaces is correct - setup: -- assert: - name: "assert that {{ interface }} is present" +- name: "assert that {{ interface }} is present" + assert: that: "{{ interface in ansible_interfaces }}" msg: "{{ interface }} is not in ansible_interfaces: {{ ansible_interfaces }}" diff --git a/tests/tasks/assert-profile_absent.yml b/tests/tasks/assert-profile_absent.yml index 16d5b6a..91aebaa 100644 --- a/tests/tasks/assert-profile_absent.yml +++ b/tests/tasks/assert-profile_absent.yml @@ -8,7 +8,7 @@ path: "{{ profile_path }}" register: profile_stat -- assert: - name: "assert that {{ profile }} is absent" +- name: "assert that {{ profile }} is absent" + assert: that: not profile_stat.stat.exists msg: "profile {{ profile_path }} does exist" diff --git a/tests/tasks/assert-profile_present.yml b/tests/tasks/assert-profile_present.yml index 7324698..35bd04e 100644 --- a/tests/tasks/assert-profile_present.yml +++ b/tests/tasks/assert-profile_present.yml @@ -8,7 +8,7 @@ path: "{{ profile_path }}" register: profile_stat -- assert: - name: "assert that {{ profile }} is present" +- name: "assert that {{ profile }} is present" + assert: that: profile_stat.stat.exists msg: "profile {{ profile_path }} does not exist"