mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Fixing playbook includes in v2 where included paths are relative
This commit is contained in:
parent
b07ab41994
commit
ed05db52ba
2 changed files with 12 additions and 5 deletions
v2/ansible/playbook
|
@ -72,7 +72,7 @@ class Playbook:
|
||||||
raise AnsibleParserError("playbook entries must be either a valid play or an include statement", obj=entry)
|
raise AnsibleParserError("playbook entries must be either a valid play or an include statement", obj=entry)
|
||||||
|
|
||||||
if 'include' in 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)
|
self._entries.extend(pb._entries)
|
||||||
else:
|
else:
|
||||||
entry_obj = Play.load(entry, variable_manager=variable_manager, loader=self._loader)
|
entry_obj = Play.load(entry, variable_manager=variable_manager, loader=self._loader)
|
||||||
|
|
|
@ -19,6 +19,8 @@
|
||||||
from __future__ import (absolute_import, division, print_function)
|
from __future__ import (absolute_import, division, print_function)
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
from ansible.parsing.splitter import split_args, parse_kv
|
from ansible.parsing.splitter import split_args, parse_kv
|
||||||
from ansible.parsing.yaml.objects import AnsibleBaseYAMLObject, AnsibleMapping
|
from ansible.parsing.yaml.objects import AnsibleBaseYAMLObject, AnsibleMapping
|
||||||
from ansible.playbook.attribute import FieldAttribute
|
from ansible.playbook.attribute import FieldAttribute
|
||||||
|
@ -33,10 +35,10 @@ class PlaybookInclude(Base):
|
||||||
_vars = FieldAttribute(isa='dict', default=dict())
|
_vars = FieldAttribute(isa='dict', default=dict())
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def load(data, variable_manager=None, loader=None):
|
def load(data, basedir, variable_manager=None, loader=None):
|
||||||
return PlaybookInclude().load_data(ds=data, variable_manager=variable_manager, loader=loader)
|
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
|
Overrides the base load_data(), as we're actually going to return a new
|
||||||
Playbook() object rather than a PlaybookInclude object
|
Playbook() object rather than a PlaybookInclude object
|
||||||
|
@ -51,7 +53,12 @@ class PlaybookInclude(Base):
|
||||||
|
|
||||||
# then we use the object to load a Playbook
|
# then we use the object to load a Playbook
|
||||||
pb = Playbook(loader=loader)
|
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
|
# finally, playbook includes can specify a list of variables, which are simply
|
||||||
# used to update the vars of each play in the playbook
|
# used to update the vars of each play in the playbook
|
||||||
|
|
Loading…
Add table
Reference in a new issue