Fixes #15915: New HandlerTaskInclude Class which can run TaskIncludes inside Handlers
This commit is contained in:
parent
4cabc94f09
commit
c1fe7aa322
2 changed files with 44 additions and 8 deletions
33
lib/ansible/playbook/handler_task_include.py
Normal file
33
lib/ansible/playbook/handler_task_include.py
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
# (c) 2012-2014, Michael DeHaan <michael.dehaan@gmail.com>
|
||||||
|
#
|
||||||
|
# This file is part of Ansible
|
||||||
|
#
|
||||||
|
# Ansible is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# Ansible is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# Make coding more python3-ish
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
from ansible.errors import AnsibleError
|
||||||
|
#from ansible.inventory.host import Host
|
||||||
|
from ansible.playbook.task_include import TaskInclude
|
||||||
|
from ansible.playbook.handler import Handler
|
||||||
|
|
||||||
|
class HandlerTaskInclude(Handler, TaskInclude):
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def load(data, block=None, role=None, task_include=None, variable_manager=None, loader=None):
|
||||||
|
t = HandlerTaskInclude(block=block, role=role, task_include=task_include)
|
||||||
|
return t.load_data(data, variable_manager=variable_manager, loader=loader)
|
||||||
|
|
|
@ -81,6 +81,7 @@ def load_list_of_tasks(ds, play, block=None, role=None, task_include=None, use_h
|
||||||
from ansible.playbook.handler import Handler
|
from ansible.playbook.handler import Handler
|
||||||
from ansible.playbook.task import Task
|
from ansible.playbook.task import Task
|
||||||
from ansible.playbook.task_include import TaskInclude
|
from ansible.playbook.task_include import TaskInclude
|
||||||
|
from ansible.playbook.handler_task_include import HandlerTaskInclude
|
||||||
from ansible.template import Templar
|
from ansible.template import Templar
|
||||||
|
|
||||||
assert isinstance(ds, list)
|
assert isinstance(ds, list)
|
||||||
|
@ -103,8 +104,10 @@ def load_list_of_tasks(ds, play, block=None, role=None, task_include=None, use_h
|
||||||
task_list.append(t)
|
task_list.append(t)
|
||||||
else:
|
else:
|
||||||
if 'include' in task_ds:
|
if 'include' in task_ds:
|
||||||
t = TaskInclude.load(task_ds, block=block, role=role, task_include=task_include, variable_manager=variable_manager, loader=loader)
|
if use_handlers:
|
||||||
|
t = HandlerTaskInclude.load(task_ds, block=block, role=role, task_include=task_include, variable_manager=variable_manager, loader=loader)
|
||||||
|
else:
|
||||||
|
t = TaskInclude.load(task_ds, block=block, role=role, task_include=task_include, variable_manager=variable_manager, loader=loader)
|
||||||
all_vars = variable_manager.get_vars(loader=loader, play=play, task=t)
|
all_vars = variable_manager.get_vars(loader=loader, play=play, task=t)
|
||||||
templar = Templar(loader=loader, variables=all_vars)
|
templar = Templar(loader=loader, variables=all_vars)
|
||||||
|
|
||||||
|
@ -233,11 +236,11 @@ def load_list_of_tasks(ds, play, block=None, role=None, task_include=None, use_h
|
||||||
task_list.extend(included_blocks)
|
task_list.extend(included_blocks)
|
||||||
else:
|
else:
|
||||||
task_list.append(t)
|
task_list.append(t)
|
||||||
elif use_handlers:
|
|
||||||
t = Handler.load(task_ds, block=block, role=role, task_include=task_include, variable_manager=variable_manager, loader=loader)
|
|
||||||
task_list.append(t)
|
|
||||||
else:
|
else:
|
||||||
t = Task.load(task_ds, block=block, role=role, task_include=task_include, variable_manager=variable_manager, loader=loader)
|
if use_handlers:
|
||||||
|
t = Handler.load(task_ds, block=block, role=role, task_include=task_include, variable_manager=variable_manager, loader=loader)
|
||||||
|
else:
|
||||||
|
t = Task.load(task_ds, block=block, role=role, task_include=task_include, variable_manager=variable_manager, loader=loader)
|
||||||
task_list.append(t)
|
task_list.append(t)
|
||||||
|
|
||||||
return task_list
|
return task_list
|
||||||
|
|
Loading…
Reference in a new issue