mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-25 11:51:26 -07:00
Keep track of role dependencies across plays
Also fixes a bug in which tags specified on top-level roles were not being passed down to dependent roles. Fixes #4656
This commit is contained in:
parent
ca4ff261eb
commit
73c883c122
3 changed files with 25 additions and 3 deletions
|
@ -6,6 +6,7 @@ Ansible Changes By Release
|
||||||
Major features/changes:
|
Major features/changes:
|
||||||
|
|
||||||
* The deprecated legacy variable templating system has been finally removed. Use {{ foo }} always not $foo or ${foo}.
|
* The deprecated legacy variable templating system has been finally removed. Use {{ foo }} always not $foo or ${foo}.
|
||||||
|
* Role dependencies are now tracked across multiple plays, making common roles easier to include in dependencies without any special variable tricks.
|
||||||
|
|
||||||
New Modules:
|
New Modules:
|
||||||
|
|
||||||
|
|
|
@ -240,13 +240,20 @@ class PlayBook(object):
|
||||||
plays = []
|
plays = []
|
||||||
matched_tags_all = set()
|
matched_tags_all = set()
|
||||||
unmatched_tags_all = set()
|
unmatched_tags_all = set()
|
||||||
|
included_roles = []
|
||||||
|
|
||||||
# loop through all patterns and run them
|
# loop through all patterns and run them
|
||||||
self.callbacks.on_start()
|
self.callbacks.on_start()
|
||||||
for (play_ds, play_basedir) in zip(self.playbook, self.play_basedirs):
|
for (play_ds, play_basedir) in zip(self.playbook, self.play_basedirs):
|
||||||
play = Play(self, play_ds, play_basedir, vault_password=self.vault_password)
|
play = Play(self, play_ds, play_basedir, included_roles=included_roles, vault_password=self.vault_password)
|
||||||
assert play is not None
|
assert play is not None
|
||||||
|
|
||||||
|
# add any new roles brought in by this play to the
|
||||||
|
# global list of roles we're tracking
|
||||||
|
for role in play.included_roles:
|
||||||
|
if role not in included_roles:
|
||||||
|
included_roles.append(role)
|
||||||
|
|
||||||
matched_tags, unmatched_tags = play.compare_tags(self.only_tags)
|
matched_tags, unmatched_tags = play.compare_tags(self.only_tags)
|
||||||
matched_tags_all = matched_tags_all | matched_tags
|
matched_tags_all = matched_tags_all | matched_tags
|
||||||
unmatched_tags_all = unmatched_tags_all | unmatched_tags
|
unmatched_tags_all = unmatched_tags_all | unmatched_tags
|
||||||
|
|
|
@ -49,7 +49,7 @@ class Play(object):
|
||||||
|
|
||||||
# *************************************************
|
# *************************************************
|
||||||
|
|
||||||
def __init__(self, playbook, ds, basedir, vault_password=None):
|
def __init__(self, playbook, ds, basedir, included_roles=[], vault_password=None):
|
||||||
''' constructor loads from a play datastructure '''
|
''' constructor loads from a play datastructure '''
|
||||||
|
|
||||||
for x in ds.keys():
|
for x in ds.keys():
|
||||||
|
@ -81,7 +81,7 @@ class Play(object):
|
||||||
self._update_vars_files_for_host(None)
|
self._update_vars_files_for_host(None)
|
||||||
|
|
||||||
# now we load the roles into the datastructure
|
# now we load the roles into the datastructure
|
||||||
self.included_roles = []
|
self.included_roles = included_roles
|
||||||
ds = self._load_roles(self.roles, ds)
|
ds = self._load_roles(self.roles, ds)
|
||||||
|
|
||||||
# and finally re-process the vars files as they may have
|
# and finally re-process the vars files as they may have
|
||||||
|
@ -227,6 +227,20 @@ class Play(object):
|
||||||
if meta_data:
|
if meta_data:
|
||||||
allow_dupes = utils.boolean(meta_data.get('allow_duplicates',''))
|
allow_dupes = utils.boolean(meta_data.get('allow_duplicates',''))
|
||||||
|
|
||||||
|
# if any tags were specified as role/dep variables, merge
|
||||||
|
# them into the passed_vars so they're passed on to any
|
||||||
|
# further dependencies too, and so we only have one place
|
||||||
|
# (passed_vars) to look for tags going forward
|
||||||
|
def __merge_tags(var_obj):
|
||||||
|
old_tags = passed_vars.get('tags', [])
|
||||||
|
new_tags = var_obj.get('tags', [])
|
||||||
|
if isinstance(new_tags, basestring):
|
||||||
|
new_tags = [new_tags, ]
|
||||||
|
return list(set(old_tags + new_tags))
|
||||||
|
|
||||||
|
passed_vars['tags'] = __merge_tags(role_vars)
|
||||||
|
passed_vars['tags'] = __merge_tags(dep_vars)
|
||||||
|
|
||||||
# if tags are set from this role, merge them
|
# if tags are set from this role, merge them
|
||||||
# into the tags list for the dependent role
|
# into the tags list for the dependent role
|
||||||
if "tags" in passed_vars:
|
if "tags" in passed_vars:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue