def _get_variables_from_file(self, var_file):
"""
Looks for file relative to base_path. If not found, checks relative to base_path/ansible.
If file extension is .yml | .yaml, parses as YAML, otherwise parses as JSON.
:return: ruamel.ordereddict
"""
abspath = path.abspath(var_file)
if not path.exists(abspath):
dirname, filename = path.split(abspath)
raise AnsibleContainerConfigException(
u'Variables file "%s" not found. (I looked in "%s" for it.)' % (filename, dirname)
)
logger.debug("Use variable file: %s", abspath, file=abspath)
if path.splitext(abspath)[-1].lower().endswith(('yml', 'yaml')):
try:
config = yaml.round_trip_load(open(abspath))
except yaml.YAMLError as exc:
raise AnsibleContainerConfigException(u"YAML exception: %s" % text_type(exc))
else:
try:
config = json.load(open(abspath))
except Exception as exc:
raise AnsibleContainerConfigException(u"JSON exception: %s" % text_type(exc))
return iteritems(config)
评论列表
文章目录