allow include_role to specify vars/defaults files

pull/17272/head
Brian Coca 8 years ago
parent 4b679ffd84
commit 4e6a7a9e01

@ -85,7 +85,7 @@ class Role(Base, Become, Conditional, Taggable):
if from_files is None:
from_files = {}
self._tasks_from = from_files.get('tasks')
self._from_files = from_files
super(Role, self).__init__()
@ -174,7 +174,7 @@ class Role(Base, Become, Conditional, Taggable):
else:
self._metadata = RoleMetadata()
task_data = self._load_role_yaml('tasks', main=self._tasks_from)
task_data = self._load_role_yaml('tasks', main=self._from_files.get('tasks'))
if task_data:
try:
self._task_blocks = load_list_of_blocks(task_data, play=self._play, role=self, loader=self._loader, variable_manager=self._variable_manager)
@ -189,13 +189,13 @@ class Role(Base, Become, Conditional, Taggable):
raise AnsibleParserError("The handlers/main.yml file for role '%s' must contain a list of tasks" % self._role_name , obj=handler_data)
# vars and default vars are regular dictionaries
self._role_vars = self._load_role_yaml('vars')
self._role_vars = self._load_role_yaml('vars', main=self._from_files.get('vars'))
if self._role_vars is None:
self._role_vars = dict()
elif not isinstance(self._role_vars, dict):
raise AnsibleParserError("The vars/main.yml file for role '%s' must contain a dictionary of variables" % self._role_name)
self._default_vars = self._load_role_yaml('defaults')
self._default_vars = self._load_role_yaml('defaults', main=self._from_files.get('defaults'))
if self._default_vars is None:
self._default_vars = dict()
elif not isinstance(self._default_vars, dict):

@ -63,8 +63,10 @@ class IncludeRole(Task):
# build options for roles
from_files = {}
if args.get('tasks_from'):
from_files['tasks'] = basename(args.get('tasks_from'))
for key in ['tasks', 'vars', 'defaults']:
from_key = key + '_from'
if args.get(from_key):
from_files[key] = basename(args.get(from_key))
#build role
actual_role = Role.load(ri, block._play, parent_role=role, from_files=from_files)

Loading…
Cancel
Save