2014-11-04 22:16:11 +01:00
|
|
|
# (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/>.
|
|
|
|
|
2015-04-13 22:28:01 +02:00
|
|
|
from __future__ import (absolute_import, division, print_function)
|
|
|
|
__metaclass__ = type
|
2014-11-06 20:14:38 +01:00
|
|
|
|
|
|
|
import os
|
|
|
|
|
2014-11-04 22:16:11 +01:00
|
|
|
from types import NoneType
|
|
|
|
|
2014-11-05 15:00:00 +01:00
|
|
|
from ansible.errors import AnsibleParserError
|
2015-04-03 19:02:42 +02:00
|
|
|
from ansible.parsing.yaml.objects import AnsibleBaseYAMLObject, AnsibleSequence
|
2014-11-04 22:16:11 +01:00
|
|
|
|
2014-11-06 20:14:38 +01:00
|
|
|
|
2015-04-30 18:13:43 +02:00
|
|
|
def load_list_of_blocks(ds, play, parent_block=None, role=None, task_include=None, use_handlers=False, variable_manager=None, loader=None):
|
2014-11-04 22:16:11 +01:00
|
|
|
'''
|
|
|
|
Given a list of mixed task/block data (parsed from YAML),
|
|
|
|
return a list of Block() objects, where implicit blocks
|
|
|
|
are created for each bare Task.
|
|
|
|
'''
|
2015-01-19 23:18:18 +01:00
|
|
|
|
2014-11-04 22:16:11 +01:00
|
|
|
# we import here to prevent a circular dependency with imports
|
|
|
|
from ansible.playbook.block import Block
|
|
|
|
|
2015-06-06 16:13:14 +02:00
|
|
|
if not isinstance(ds, (list, type(None))):
|
|
|
|
raise AnsibleParserError('block has bad type: "%s". Expecting "list"' % type(ds).__name__, obj=ds)
|
2014-11-04 22:16:11 +01:00
|
|
|
|
|
|
|
block_list = []
|
|
|
|
if ds:
|
|
|
|
for block in ds:
|
2014-11-14 23:14:08 +01:00
|
|
|
b = Block.load(
|
|
|
|
block,
|
2015-04-30 18:13:43 +02:00
|
|
|
play=play,
|
2014-11-14 23:14:08 +01:00
|
|
|
parent_block=parent_block,
|
|
|
|
role=role,
|
|
|
|
task_include=task_include,
|
|
|
|
use_handlers=use_handlers,
|
|
|
|
variable_manager=variable_manager,
|
|
|
|
loader=loader
|
|
|
|
)
|
2014-11-04 22:16:11 +01:00
|
|
|
block_list.append(b)
|
|
|
|
|
|
|
|
return block_list
|
|
|
|
|
2014-11-05 15:00:00 +01:00
|
|
|
|
2015-04-30 18:13:43 +02:00
|
|
|
def load_list_of_tasks(ds, play, block=None, role=None, task_include=None, use_handlers=False, variable_manager=None, loader=None):
|
2014-11-04 22:16:11 +01:00
|
|
|
'''
|
|
|
|
Given a list of task datastructures (parsed from YAML),
|
2014-11-05 15:00:00 +01:00
|
|
|
return a list of Task() or TaskInclude() objects.
|
2014-11-04 22:16:11 +01:00
|
|
|
'''
|
|
|
|
|
|
|
|
# we import here to prevent a circular dependency with imports
|
2015-03-25 19:51:40 +01:00
|
|
|
from ansible.playbook.block import Block
|
2014-11-14 23:14:08 +01:00
|
|
|
from ansible.playbook.handler import Handler
|
2014-11-04 22:16:11 +01:00
|
|
|
from ansible.playbook.task import Task
|
|
|
|
|
2015-06-06 16:13:14 +02:00
|
|
|
if not isinstance(ds, list):
|
|
|
|
raise AnsibleParserError('task has bad type: "%s". Expected "list"' % type(ds).__name__, obj=ds)
|
2014-11-04 22:16:11 +01:00
|
|
|
|
|
|
|
task_list = []
|
|
|
|
for task in ds:
|
2014-11-05 15:00:00 +01:00
|
|
|
if not isinstance(task, dict):
|
2015-06-06 16:13:14 +02:00
|
|
|
raise AnsibleParserError('task/handler has bad type: "%s". Expected "dict"' % type(task).__name__, obj=task)
|
2014-11-05 15:00:00 +01:00
|
|
|
|
2015-03-25 19:51:40 +01:00
|
|
|
if 'block' in task:
|
|
|
|
t = Block.load(
|
|
|
|
task,
|
2015-04-30 18:13:43 +02:00
|
|
|
play=play,
|
2015-03-25 19:51:40 +01:00
|
|
|
parent_block=block,
|
|
|
|
role=role,
|
|
|
|
task_include=task_include,
|
|
|
|
use_handlers=use_handlers,
|
|
|
|
variable_manager=variable_manager,
|
|
|
|
loader=loader,
|
|
|
|
)
|
|
|
|
else:
|
2014-11-14 23:14:08 +01:00
|
|
|
if use_handlers:
|
|
|
|
t = Handler.load(task, block=block, role=role, task_include=task_include, variable_manager=variable_manager, loader=loader)
|
|
|
|
else:
|
|
|
|
t = Task.load(task, block=block, role=role, task_include=task_include, variable_manager=variable_manager, loader=loader)
|
2014-11-05 15:00:00 +01:00
|
|
|
|
2014-11-04 22:16:11 +01:00
|
|
|
task_list.append(t)
|
|
|
|
|
|
|
|
return task_list
|
|
|
|
|
2014-11-05 15:00:00 +01:00
|
|
|
|
2015-08-03 22:25:08 +02:00
|
|
|
def load_list_of_roles(ds, play, current_role_path=None, variable_manager=None, loader=None):
|
2014-11-04 22:16:11 +01:00
|
|
|
'''
|
|
|
|
Loads and returns a list of RoleInclude objects from the datastructure
|
|
|
|
list of role definitions
|
|
|
|
'''
|
|
|
|
|
|
|
|
# we import here to prevent a circular dependency with imports
|
|
|
|
from ansible.playbook.role.include import RoleInclude
|
|
|
|
|
2015-06-06 16:13:14 +02:00
|
|
|
if not isinstance(ds, list):
|
|
|
|
raise AnsibleParserError('roles has bad type: "%s". Expectes "list"' % type(ds).__name__, obj=ds)
|
2014-11-04 22:16:11 +01:00
|
|
|
|
|
|
|
roles = []
|
|
|
|
for role_def in ds:
|
2015-08-03 22:25:08 +02:00
|
|
|
i = RoleInclude.load(role_def, play=play, current_role_path=current_role_path, variable_manager=variable_manager, loader=loader)
|
2014-11-04 22:16:11 +01:00
|
|
|
roles.append(i)
|
|
|
|
|
|
|
|
return roles
|
|
|
|
|