diff options
Diffstat (limited to 'lib/ansible/playbook/role_include.py')
-rw-r--r-- | lib/ansible/playbook/role_include.py | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/lib/ansible/playbook/role_include.py b/lib/ansible/playbook/role_include.py index 75d26fb8..cdf86c0f 100644 --- a/lib/ansible/playbook/role_include.py +++ b/lib/ansible/playbook/role_include.py @@ -23,7 +23,6 @@ from os.path import basename import ansible.constants as C from ansible.errors import AnsibleParserError from ansible.playbook.attribute import NonInheritableFieldAttribute -from ansible.playbook.block import Block from ansible.playbook.task_include import TaskInclude from ansible.playbook.role import Role from ansible.playbook.role.include import RoleInclude @@ -50,10 +49,10 @@ class IncludeRole(TaskInclude): # ================================================================================= # ATTRIBUTES + public = NonInheritableFieldAttribute(isa='bool', default=None, private=False, always_post_validate=True) # private as this is a 'module options' vs a task property allow_duplicates = NonInheritableFieldAttribute(isa='bool', default=True, private=True, always_post_validate=True) - public = NonInheritableFieldAttribute(isa='bool', default=False, private=True, always_post_validate=True) rolespec_validate = NonInheritableFieldAttribute(isa='bool', default=True, private=True, always_post_validate=True) def __init__(self, block=None, role=None, task_include=None): @@ -89,22 +88,18 @@ class IncludeRole(TaskInclude): # build role actual_role = Role.load(ri, myplay, parent_role=self._parent_role, from_files=from_files, - from_include=True, validate=self.rolespec_validate) + from_include=True, validate=self.rolespec_validate, public=self.public, static=self.statically_loaded) actual_role._metadata.allow_duplicates = self.allow_duplicates - if self.statically_loaded or self.public: - myplay.roles.append(actual_role) + # add role to play + myplay.roles.append(actual_role) # save this for later use self._role_path = actual_role._role_path # compile role with parent roles as dependencies to ensure they inherit # variables - if not self._parent_role: - dep_chain = [] - else: - dep_chain = list(self._parent_role._parents) - dep_chain.append(self._parent_role) + dep_chain = actual_role.get_dep_chain() p_block = self.build_parent_block() @@ -118,7 +113,7 @@ class IncludeRole(TaskInclude): b.collections = actual_role.collections # updated available handlers in play - handlers = actual_role.get_handler_blocks(play=myplay) + handlers = actual_role.get_handler_blocks(play=myplay, dep_chain=dep_chain) for h in handlers: h._parent = p_block myplay.handlers = myplay.handlers + handlers @@ -137,6 +132,7 @@ class IncludeRole(TaskInclude): if ir._role_name is None: raise AnsibleParserError("'name' is a required field for %s." % ir.action, obj=data) + # public is only valid argument for includes, imports are always 'public' (after they run) if 'public' in ir.args and ir.action not in C._ACTION_INCLUDE_ROLE: raise AnsibleParserError('Invalid options for %s: public' % ir.action, obj=data) @@ -145,7 +141,7 @@ class IncludeRole(TaskInclude): if bad_opts: raise AnsibleParserError('Invalid options for %s: %s' % (ir.action, ','.join(list(bad_opts))), obj=data) - # build options for role includes + # build options for role include/import tasks for key in my_arg_names.intersection(IncludeRole.FROM_ARGS): from_key = key.removesuffix('_from') args_value = ir.args.get(key) @@ -153,6 +149,7 @@ class IncludeRole(TaskInclude): raise AnsibleParserError('Expected a string for %s but got %s instead' % (key, type(args_value))) ir._from_files[from_key] = basename(args_value) + # apply is only valid for includes, not imports as they inherit directly apply_attrs = ir.args.get('apply', {}) if apply_attrs and ir.action not in C._ACTION_INCLUDE_ROLE: raise AnsibleParserError('Invalid options for %s: apply' % ir.action, obj=data) |