Debian Codegraph @

lib/ansible/playbook/role/include.py

raw
1 # (c) 2014 Michael DeHaan, <[email protected]>
2 #
3 # This file is part of Ansible
4 #
5 # Ansible is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # Ansible is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with Ansible. If not, see <http://www.gnu.org/licenses/>.
17
18 from __future__ import annotations
19
20 from ansible.errors import AnsibleError, AnsibleParserError
21 from ansible.playbook.delegatable import Delegatable
22 from ansible.playbook.role.definition import RoleDefinition
23
24
25 __all__ = ['RoleInclude']
26
27
28 class RoleInclude(RoleDefinition, Delegatable):
29
30 """
31 A derivative of RoleDefinition, used by playbook code when a role
32 is included for execution in a play.
33 """
34
35 def __init__(self, play=None, role_basedir=None, variable_manager=None, loader=None, collection_list=None):
36 super(RoleInclude, self).__init__(play=play, role_basedir=role_basedir, variable_manager=variable_manager,
37 loader=loader, collection_list=collection_list)
38
39 @staticmethod
40 def load(data, play, current_role_path=None, parent_role=None, variable_manager=None, loader=None, collection_list=None):
41
42 if not (isinstance(data, str) or isinstance(data, dict)):
43 raise AnsibleParserError("Invalid role definition.", obj=data)
44
45 if isinstance(data, str) and ',' in data:
46 raise AnsibleError("Invalid old style role requirement: %s" % data)
47
48 ri = RoleInclude(play=play, role_basedir=current_role_path, variable_manager=variable_manager, loader=loader, collection_list=collection_list)
49 return ri.load_data(data, variable_manager=variable_manager, loader=loader)