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

Added a 'set_up' and 'tear_down' which are like tasks, but execute before and after roles.

This commit is contained in:
Michael DeHaan 2013-04-20 16:07:06 -04:00
parent e6bf01a6b0
commit d7623d1f91
3 changed files with 37 additions and 1 deletions

View file

@ -25,6 +25,12 @@
---
- hosts: all
set_up:
# set up tasks are executed prior to roles.
- local_action: shell echo "hi this is a setup step about {{ inventory_hostname }}"
roles:
# a role can be listed flat like this:
@ -51,4 +57,11 @@
- shell: echo 'this is a loose task'
tear_down:
# just to provide a syntactic mirroring to 'set_up', tear_down runs dead last in the play.
- local_action: shell echo 'this is a teardown task about {{ inventory_hostname }}'

View file

@ -40,7 +40,7 @@ class Play(object):
'hosts', 'name', 'vars', 'vars_prompt', 'vars_files',
'tasks', 'handlers', 'user', 'port', 'include',
'sudo', 'sudo_user', 'connection', 'tags', 'gather_facts', 'serial',
'any_errors_fatal', 'roles'
'any_errors_fatal', 'roles', 'set_up', 'tear_down'
]
# *************************************************
@ -135,6 +135,12 @@ class Play(object):
new_handlers = []
new_vars_files = []
set_up = ds.get('set_up', None)
if type(set_up) != list:
set_up = []
for x in set_up:
new_tasks.append(x)
# variables if the role was parameterized (i.e. given as a hash)
has_dict = {}
@ -180,15 +186,22 @@ class Play(object):
new_vars_files.append(vars_file)
tasks = ds.get('tasks', None)
tear_down = ds.get('tear_down', None)
handlers = ds.get('handlers', None)
vars_files = ds.get('vars_files', None)
if type(tasks) != list:
tasks = []
if type(handlers) != list:
handlers = []
if type(vars_files) != list:
vars_files = []
if type(tear_down) != list:
tear_down = []
new_tasks.extend(tasks)
new_tasks.extend(tear_down)
new_handlers.extend(handlers)
new_vars_files.extend(vars_files)
ds['tasks'] = new_tasks

View file

@ -61,6 +61,16 @@ class PluginLoader(object):
self._extra_dirs = []
def print_paths(self):
''' Returns a string suitable for printing of the search path '''
# Uses a list to get the order right
ret = []
for i in self._get_paths():
if i not in ret:
ret.append(i)
return os.pathsep.join(ret)
def _get_package_path(self):
''' Gets the path of a Python package '''