diff --git a/examples/playbooks/roletest.yml b/examples/playbooks/roletest.yml index 9a7cede6a60..5370c004ebc 100644 --- a/examples/playbooks/roletest.yml +++ b/examples/playbooks/roletest.yml @@ -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 }}' + + diff --git a/lib/ansible/playbook/play.py b/lib/ansible/playbook/play.py index 82e87eced17..b1fc697611b 100644 --- a/lib/ansible/playbook/play.py +++ b/lib/ansible/playbook/play.py @@ -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 diff --git a/lib/ansible/utils/plugins.py b/lib/ansible/utils/plugins.py index e756e3bcd56..7a58775d4a6 100644 --- a/lib/ansible/utils/plugins.py +++ b/lib/ansible/utils/plugins.py @@ -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 '''