mirror of https://github.com/ansible/ansible.git
Role fixes (#82339)
* Various fixes to roles - static property is now properly set - role_names and other magic vars now have full list - role public/private var loading is now done when adding to play.roles instead of on each var query - added tests Co-authored-by: Felix Fontein <felix@fontein.de>pull/82465/head
parent
fa92228b50
commit
55065c0042
@ -0,0 +1,3 @@
|
|||||||
|
bugfixes:
|
||||||
|
- roles, the ``static`` property is now correctly set, this will fix issues with ``public`` and ``DEFAULT_PRIVATE_ROLE_VARS`` controls on exporting vars.
|
||||||
|
- roles, code cleanup and performance optimization of dependencies, now cached, and ``public`` setting is now determined once, at role instantiation.
|
@ -0,0 +1,82 @@
|
|||||||
|
# use this to debug issues
|
||||||
|
#- debug: msg={{ is_private ~ ', ' ~ is_default ~ ', ' ~ privacy|default('nope')}}
|
||||||
|
|
||||||
|
- hosts: localhost
|
||||||
|
name: test global privacy setting
|
||||||
|
gather_facts: false
|
||||||
|
roles:
|
||||||
|
- a
|
||||||
|
pre_tasks:
|
||||||
|
|
||||||
|
- name: 'test roles: privacy'
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- is_private and privacy is undefined or not is_private and privacy is defined
|
||||||
|
- not is_default or is_default and privacy is defined
|
||||||
|
|
||||||
|
- hosts: localhost
|
||||||
|
name: test import_role privacy
|
||||||
|
gather_facts: false
|
||||||
|
tasks:
|
||||||
|
- import_role: name=a
|
||||||
|
|
||||||
|
- name: role is private, var should be undefined
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- is_private and privacy is undefined or not is_private and privacy is defined
|
||||||
|
- not is_default or is_default and privacy is defined
|
||||||
|
|
||||||
|
- hosts: localhost
|
||||||
|
name: test public no always overrides global on import_role
|
||||||
|
gather_facts: false
|
||||||
|
tasks:
|
||||||
|
- import_role: name=a public=no
|
||||||
|
|
||||||
|
- name: role is private, var should be undefined
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- privacy is undefined
|
||||||
|
|
||||||
|
- hosts: localhost
|
||||||
|
name: test public yes always overrides global on import_role
|
||||||
|
gather_facts: false
|
||||||
|
tasks:
|
||||||
|
- import_role: name=a public=yes
|
||||||
|
|
||||||
|
- name: role is private, var should be undefined
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- privacy is defined
|
||||||
|
|
||||||
|
- hosts: localhost
|
||||||
|
name: test global privacy setting on includes
|
||||||
|
gather_facts: false
|
||||||
|
tasks:
|
||||||
|
- include_role: name=a
|
||||||
|
|
||||||
|
- name: test include_role privacy
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- not is_default and (is_private and privacy is undefined or not is_private and privacy is defined) or is_default and privacy is undefined
|
||||||
|
|
||||||
|
- hosts: localhost
|
||||||
|
name: test public yes always overrides global privacy setting on includes
|
||||||
|
gather_facts: false
|
||||||
|
tasks:
|
||||||
|
- include_role: name=a public=yes
|
||||||
|
|
||||||
|
- name: test include_role privacy
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- privacy is defined
|
||||||
|
|
||||||
|
- hosts: localhost
|
||||||
|
name: test public no always overrides global privacy setting on includes
|
||||||
|
gather_facts: false
|
||||||
|
tasks:
|
||||||
|
- include_role: name=a public=no
|
||||||
|
|
||||||
|
- name: test include_role privacy
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- privacy is undefined
|
@ -0,0 +1 @@
|
|||||||
|
privacy: in role a
|
@ -0,0 +1,2 @@
|
|||||||
|
is_private: "{{lookup('config', 'DEFAULT_PRIVATE_ROLE_VARS')}}"
|
||||||
|
is_default: "{{lookup('env', 'ANSIBLE_PRIVATE_ROLE_VARS') == ''}}"
|
Loading…
Reference in New Issue