diff options
author | Xaroth <xaroth+github@xaroth.nl> | 2019-04-23 17:55:05 +0200 |
---|---|---|
committer | Sam Doran <sdoran@redhat.com> | 2019-04-23 17:55:05 +0200 |
commit | a9f24e097fd238e31be404f2046a954be88a4262 (patch) | |
tree | 0a58492444dbe28d0bc03a2e591dc8ba1c32dfcb /test/integration/targets/include_parent_role_vars/tasks | |
parent | Move missing library abort to use rather than import for netconf (#55384) (diff) | |
download | ansible-a9f24e097fd238e31be404f2046a954be88a4262.tar.xz ansible-a9f24e097fd238e31be404f2046a954be88a4262.zip |
Add ansible_parent_role_names magic variable (#46687)
-Add: Test cases for ansible_parent_role_names and ansible_parent_role_paths
-Add: ansible_parent_role_names/paths variables for when a role is being included by another role.
Diffstat (limited to 'test/integration/targets/include_parent_role_vars/tasks')
3 files changed, 72 insertions, 0 deletions
diff --git a/test/integration/targets/include_parent_role_vars/tasks/included_by_other_role.yml b/test/integration/targets/include_parent_role_vars/tasks/included_by_other_role.yml new file mode 100644 index 0000000000..79b7b1cbde --- /dev/null +++ b/test/integration/targets/include_parent_role_vars/tasks/included_by_other_role.yml @@ -0,0 +1,37 @@ +# Copyright 2019 Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +- name: ensure our parent role tree to contain only our direct parent item + assert: + that: + - "ansible_parent_role_names == ['special_vars']" + +- name: ensure that ansible_parent_role_paths has the same length as ansible_parent_role_names + assert: + that: + - "ansible_parent_role_names|length == ansible_parent_role_paths|length" + +- name: attempt to import ourselves + import_role: + name: "include_parent_role_vars" + tasks_from: "included_by_ourselves.yml" + +- name: ensure our parent role tree to contain only our direct parent item after importing + assert: + that: + - "ansible_parent_role_names == ['special_vars']" + +- name: attempt to include ourselves + include_role: + name: "include_parent_role_vars" + tasks_from: "included_by_ourselves.yml" + +- name: ensure our parent role tree to contain only our direct parent item after including + assert: + that: + - "ansible_parent_role_names == ['special_vars']" + +- name: ensure that ansible_parent_role_paths has the same length as ansible_parent_role_names + assert: + that: + - "ansible_parent_role_names|length == ansible_parent_role_paths|length" diff --git a/test/integration/targets/include_parent_role_vars/tasks/included_by_ourselves.yml b/test/integration/targets/include_parent_role_vars/tasks/included_by_ourselves.yml new file mode 100644 index 0000000000..3ea9300451 --- /dev/null +++ b/test/integration/targets/include_parent_role_vars/tasks/included_by_ourselves.yml @@ -0,0 +1,14 @@ +# Copyright 2019 Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +- name: check if the inclusion tree shows ourself twice as well as our initial parent + assert: + that: + - "ansible_parent_role_names|length == 2" + - "ansible_parent_role_names[0] == 'include_parent_role_vars'" # Since we included ourselves, we're the top level + - "ansible_parent_role_names[1] == 'special_vars'" + +- name: ensure that ansible_parent_role_paths has the same length as ansible_parent_role_names + assert: + that: + - "ansible_parent_role_names|length == ansible_parent_role_paths|length" diff --git a/test/integration/targets/include_parent_role_vars/tasks/main.yml b/test/integration/targets/include_parent_role_vars/tasks/main.yml new file mode 100644 index 0000000000..56a485bc25 --- /dev/null +++ b/test/integration/targets/include_parent_role_vars/tasks/main.yml @@ -0,0 +1,21 @@ +# Copyright 2019 Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + + +- name: ensure our parent role tree to contain only our direct parent item + assert: + that: + - "ansible_parent_role_names == ['special_vars']" + +- name: ensure that ansible_parent_role_paths has the same length as ansible_parent_role_names + assert: + that: + - "ansible_parent_role_names|length == ansible_parent_role_paths|length" + +# task importing should not affect ansible_parent_role_names +- name: test task-importing after we've been included by another role + import_tasks: "included_by_other_role.yml" + +# task inclusion should not affect ansible_parent_role_names +- name: test task-inclusion after we've been included by another role + include_tasks: "included_by_other_role.yml" |