mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-05-22 08:59:08 -07:00
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.
This commit is contained in:
parent
b442706b54
commit
a9f24e097f
9 changed files with 135 additions and 1 deletions
|
@ -0,0 +1,2 @@
|
|||
# Continuation of special_vars integration tests to test special variables set on role inclusion.
|
||||
hidden
|
|
@ -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"
|
|
@ -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"
|
|
@ -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"
|
|
@ -1 +1,2 @@
|
|||
shippable/posix/group2
|
||||
needs/target/include_parent_role_vars
|
||||
|
|
|
@ -56,3 +56,45 @@
|
|||
assert:
|
||||
that:
|
||||
- "(ansible_play_role_names + ansible_dependent_role_names)|unique|sort|list == ansible_role_names|sort|list"
|
||||
|
||||
- name: check that ansible_parent_role_names is normally unset when not included/imported (before including other roles)
|
||||
assert:
|
||||
that:
|
||||
- "ansible_parent_role_names is undefined"
|
||||
- "ansible_parent_role_paths is undefined"
|
||||
|
||||
- name: ansible_parent_role_names - test functionality by including another role
|
||||
include_role:
|
||||
name: include_parent_role_vars
|
||||
tasks_from: included_by_other_role.yml
|
||||
|
||||
- name: check that ansible_parent_role_names is normally unset when not included/imported (after including other role)
|
||||
assert:
|
||||
that:
|
||||
- "ansible_parent_role_names is undefined"
|
||||
- "ansible_parent_role_paths is undefined"
|
||||
|
||||
- name: ansible_parent_role_names - test functionality by importing another role
|
||||
import_role:
|
||||
name: include_parent_role_vars
|
||||
tasks_from: included_by_other_role.yml
|
||||
|
||||
- name: check that ansible_parent_role_names is normally unset when not included/imported (after importing other role)
|
||||
assert:
|
||||
that:
|
||||
- "ansible_parent_role_names is undefined"
|
||||
- "ansible_parent_role_paths is undefined"
|
||||
|
||||
- name: ansible_parent_role_names - test functionality by including another role
|
||||
include_role:
|
||||
name: include_parent_role_vars
|
||||
|
||||
- name: check that ansible_parent_role_names is normally unset when not included/imported (after both import and inlcude)
|
||||
assert:
|
||||
that:
|
||||
- "ansible_parent_role_names is undefined"
|
||||
- "ansible_parent_role_paths is undefined"
|
||||
|
||||
- name: ansible_parent_role_names - test functionality by importing another role
|
||||
import_role:
|
||||
name: include_parent_role_vars
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue