From d327e3d11a3c7092327630541d01b04e8450b335 Mon Sep 17 00:00:00 2001 From: James Tanner Date: Thu, 20 Mar 2014 11:55:46 -0400 Subject: [PATCH] Fixes #5622 included tasks in roles now inherit tags from the role --- lib/ansible/playbook/play.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/lib/ansible/playbook/play.py b/lib/ansible/playbook/play.py index e3e5fefcfda..914af951f78 100644 --- a/lib/ansible/playbook/play.py +++ b/lib/ansible/playbook/play.py @@ -142,6 +142,8 @@ class Play(object): self._tasks = self._load_tasks(self._ds.get('tasks', []), load_vars) self._handlers = self._load_tasks(self._ds.get('handlers', []), load_vars) + # apply any missing tags to role tasks + self._late_merge_role_tags() if self.sudo_user != 'root': self.sudo = True @@ -712,6 +714,31 @@ class Play(object): # ************************************************* + def _late_merge_role_tags(self): + # build a local dict of tags for roles + role_tags = {} + for task in self._ds['tasks']: + if 'role_name' in task: + this_role = task['role_name'] + + if this_role not in role_tags: + role_tags[this_role] = [] + + if 'tags' in task['vars']: + if isinstance(task['vars']['tags'], basestring): + role_tags[task['role_name']] += shlex.split(task['vars']['tags']) + else: + role_tags[task['role_name']] += task['vars']['tags'] + + # apply each role's tags to it's tasks + for idx, val in enumerate(self._tasks): + if hasattr(val, 'role_name'): + this_role = val.role_name + if this_role in role_tags: + self._tasks[idx].tags = sorted(set(self._tasks[idx].tags + role_tags[this_role])) + + # ************************************************* + def _has_vars_in(self, msg): return "$" in msg or "{{" in msg