mirror of https://github.com/ansible/ansible.git
Add feature to expose vars/defaults with include/import_role (#41330)
* First pass at making 'private' work on include_role, imports are always public * Prevent dupe task execution and overwriting handlers * New functionality will use public instead of deprecated private * Add tests for public exposure * Validate vars before import/include to ensure they don't expose too early * Add porting guide docs about public argument and change to import_role * Add additional docs about public and vars exposure to module docs * Insert role handlers at parse time, exposing them globallypull/41163/head
parent
5864871fc1
commit
27b4d7ed31
@ -0,0 +1,56 @@
|
||||
---
|
||||
- hosts: testhost
|
||||
gather_facts: false
|
||||
roles:
|
||||
- regular
|
||||
tasks:
|
||||
- debug:
|
||||
msg: start tasks
|
||||
|
||||
- name: Static imports should expose vars at parse time, not at execution time
|
||||
assert:
|
||||
that:
|
||||
- static_defaults_var == 'static_defaults'
|
||||
- static_vars_var == 'static_vars'
|
||||
- import_role:
|
||||
name: static
|
||||
- assert:
|
||||
that:
|
||||
- static_tasks_var == 'static_tasks'
|
||||
- static_defaults_var == 'static_defaults'
|
||||
- static_vars_var == 'static_vars'
|
||||
|
||||
- include_role:
|
||||
name: dynamic_private
|
||||
- assert:
|
||||
that:
|
||||
- private_tasks_var == 'private_tasks'
|
||||
- private_defaults_var is undefined
|
||||
- private_vars_var is undefined
|
||||
|
||||
- name: Dynamic include should not expose vars until execution time
|
||||
assert:
|
||||
that:
|
||||
- dynamic_tasks_var is undefined
|
||||
- dynamic_defaults_var is undefined
|
||||
- dynamic_vars_var is undefined
|
||||
- include_role:
|
||||
name: dynamic
|
||||
public: true
|
||||
- assert:
|
||||
that:
|
||||
- dynamic_tasks_var == 'dynamic_tasks'
|
||||
- dynamic_defaults_var == 'dynamic_defaults'
|
||||
- dynamic_vars_var == 'dynamic_vars'
|
||||
|
||||
- include_role:
|
||||
name: from
|
||||
public: true
|
||||
tasks_from: from.yml
|
||||
vars_from: from.yml
|
||||
defaults_from: from.yml
|
||||
- assert:
|
||||
that:
|
||||
- from_tasks_var == 'from_tasks'
|
||||
- from_defaults_var == 'from_defaults'
|
||||
- from_vars_var == 'from_vars'
|
@ -0,0 +1 @@
|
||||
dynamic_defaults_var: dynamic_defaults
|
@ -0,0 +1,5 @@
|
||||
- debug:
|
||||
msg: dynamic
|
||||
|
||||
- set_fact:
|
||||
dynamic_tasks_var: dynamic_tasks
|
@ -0,0 +1 @@
|
||||
dynamic_vars_var: dynamic_vars
|
@ -0,0 +1 @@
|
||||
private_defaults_var: private_defaults
|
@ -0,0 +1,5 @@
|
||||
- debug:
|
||||
msg: private
|
||||
|
||||
- set_fact:
|
||||
private_tasks_var: private_tasks
|
@ -0,0 +1 @@
|
||||
private_vars_var: private_vars
|
@ -0,0 +1 @@
|
||||
from_defaults_var: from_defaults
|
@ -0,0 +1,5 @@
|
||||
- debug:
|
||||
msg: from
|
||||
|
||||
- set_fact:
|
||||
from_tasks_var: from_tasks
|
@ -0,0 +1 @@
|
||||
from_vars_var: from_vars
|
@ -0,0 +1 @@
|
||||
regular_defaults_var: regular_defaults
|
@ -0,0 +1,5 @@
|
||||
- debug:
|
||||
msg: regular
|
||||
|
||||
- set_fact:
|
||||
regular_tasks_var: regular_tasks
|
@ -0,0 +1 @@
|
||||
regular_vars_var: regular_vars
|
@ -0,0 +1 @@
|
||||
static_defaults_var: static_defaults
|
@ -0,0 +1,5 @@
|
||||
- debug:
|
||||
msg: static
|
||||
|
||||
- set_fact:
|
||||
static_tasks_var: static_tasks
|
@ -0,0 +1 @@
|
||||
static_vars_var: static_vars
|
Loading…
Reference in New Issue