1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Make adding tags to a playbook work as shorthand to tagging all tasks in the play.

This commit is contained in:
Michael DeHaan 2012-07-12 00:58:48 -04:00
parent cf313cde96
commit 611e5b0c90
2 changed files with 32 additions and 4 deletions

View file

@ -6,14 +6,27 @@
# try this with: # try this with:
# --tags foo # --tags foo
# --tags bar # --tags bar
# --tags extra
# #
# note the include syntax to tag all tasks included below # the value of a 'tags:' element can be a string or list
# it is a short hand over adding "tag:" to each task entry # of tag names. Variables are not usable in tag names.
- name: example play one - name: example play one
hosts: all hosts: all
user: root user: root
# any tags applied to the play are shorthand to applying
# the tag to all tasks in it. Here, each task is given
# the tag extra
tags:
- extra
tasks: tasks:
# this task will run if you don't specify any tags,
# if you specify 'foo' or if you specify 'extra'
- name: hi - name: hi
tags: foo tags: foo
action: shell echo "first task ran" action: shell echo "first task ran"
@ -23,7 +36,9 @@
user: root user: root
tasks: tasks:
- name: hi - name: hi
tags: bar tags:
- bar
action: shell echo "second task ran" action: shell echo "second task ran"
- include: tasks/base.yml tags=base - include: tasks/base.yml tags=base

View file

@ -29,7 +29,7 @@ class Play(object):
'hosts', 'name', 'vars', 'vars_prompt', 'vars_files', 'hosts', 'name', 'vars', 'vars_prompt', 'vars_files',
'handlers', 'remote_user', 'remote_port', 'handlers', 'remote_user', 'remote_port',
'sudo', 'sudo_user', 'transport', 'playbook', 'sudo', 'sudo_user', 'transport', 'playbook',
'_ds', '_handlers', '_tasks' 'tags', '_ds', '_handlers', '_tasks'
] ]
# ************************************************* # *************************************************
@ -62,9 +62,17 @@ class Play(object):
self.sudo = ds.get('sudo', self.playbook.sudo) self.sudo = ds.get('sudo', self.playbook.sudo)
self.sudo_user = ds.get('sudo_user', self.playbook.sudo_user) self.sudo_user = ds.get('sudo_user', self.playbook.sudo_user)
self.transport = ds.get('connection', self.playbook.transport) self.transport = ds.get('connection', self.playbook.transport)
self.tags = ds.get('tags', None)
self._tasks = self._load_tasks(self._ds, 'tasks') self._tasks = self._load_tasks(self._ds, 'tasks')
self._handlers = self._load_tasks(self._ds, 'handlers') self._handlers = self._load_tasks(self._ds, 'handlers')
if self.tags is None:
self.tags = []
elif type(self.tags) in [ str, unicode ]:
self.tags = [ self.tags ]
elif type(self.tags) != list:
self.tags = []
if self.sudo_user != 'root': if self.sudo_user != 'root':
self.sudo = True self.sudo = True
@ -99,6 +107,11 @@ class Play(object):
mv = task_vars.copy() mv = task_vars.copy()
mv['item'] = item mv['item'] = item
results.append(Task(self,y,module_vars=mv)) results.append(Task(self,y,module_vars=mv))
for x in results:
if self.tags is not None:
x.tags.extend(self.tags)
return results return results
# ************************************************* # *************************************************