From ed05db52bafebd8e7c85f901b2303fbe95c2e343 Mon Sep 17 00:00:00 2001 From: James Cammarata Date: Wed, 28 Jan 2015 15:03:06 -0600 Subject: [PATCH] Fixing playbook includes in v2 where included paths are relative --- v2/ansible/playbook/__init__.py | 2 +- v2/ansible/playbook/playbook_include.py | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/v2/ansible/playbook/__init__.py b/v2/ansible/playbook/__init__.py index 30a8262abce..1c033559075 100644 --- a/v2/ansible/playbook/__init__.py +++ b/v2/ansible/playbook/__init__.py @@ -72,7 +72,7 @@ class Playbook: raise AnsibleParserError("playbook entries must be either a valid play or an include statement", obj=entry) if 'include' in entry: - pb = PlaybookInclude.load(entry, variable_manager=variable_manager, loader=self._loader) + pb = PlaybookInclude.load(entry, basedir=self._basedir, variable_manager=variable_manager, loader=self._loader) self._entries.extend(pb._entries) else: entry_obj = Play.load(entry, variable_manager=variable_manager, loader=self._loader) diff --git a/v2/ansible/playbook/playbook_include.py b/v2/ansible/playbook/playbook_include.py index 7512e3693c6..159c3d25da8 100644 --- a/v2/ansible/playbook/playbook_include.py +++ b/v2/ansible/playbook/playbook_include.py @@ -19,6 +19,8 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type +import os + from ansible.parsing.splitter import split_args, parse_kv from ansible.parsing.yaml.objects import AnsibleBaseYAMLObject, AnsibleMapping from ansible.playbook.attribute import FieldAttribute @@ -33,10 +35,10 @@ class PlaybookInclude(Base): _vars = FieldAttribute(isa='dict', default=dict()) @staticmethod - def load(data, variable_manager=None, loader=None): - return PlaybookInclude().load_data(ds=data, variable_manager=variable_manager, loader=loader) + def load(data, basedir, variable_manager=None, loader=None): + return PlaybookInclude().load_data(ds=data, basedir=basedir, variable_manager=variable_manager, loader=loader) - def load_data(self, ds, variable_manager=None, loader=None): + def load_data(self, ds, basedir, variable_manager=None, loader=None): ''' Overrides the base load_data(), as we're actually going to return a new Playbook() object rather than a PlaybookInclude object @@ -51,7 +53,12 @@ class PlaybookInclude(Base): # then we use the object to load a Playbook pb = Playbook(loader=loader) - pb._load_playbook_data(file_name=new_obj.include, variable_manager=variable_manager) + + file_name = new_obj.include + if not os.path.isabs(file_name): + file_name = os.path.join(basedir, file_name) + + pb._load_playbook_data(file_name=file_name, variable_manager=variable_manager) # finally, playbook includes can specify a list of variables, which are simply # used to update the vars of each play in the playbook