[stable-2.7] Support .yaml extension for meta file (#46505)
(cherry picked from commit e4cadddd70
)
This commit is contained in:
parent
093ab2170d
commit
476673f3e4
2 changed files with 25 additions and 21 deletions
2
changelogs/fragments/galaxy-metea-yaml-extension.yaml
Normal file
2
changelogs/fragments/galaxy-metea-yaml-extension.yaml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
bugfixes:
|
||||||
|
- ansible-galaxy - support yaml extension for meta file (https://github.com/ansible/ansible/pull/46505)
|
|
@ -46,7 +46,7 @@ except ImportError:
|
||||||
class GalaxyRole(object):
|
class GalaxyRole(object):
|
||||||
|
|
||||||
SUPPORTED_SCMS = set(['git', 'hg'])
|
SUPPORTED_SCMS = set(['git', 'hg'])
|
||||||
META_MAIN = os.path.join('meta', 'main.yml')
|
META_MAIN = (os.path.join('meta', 'main.yml'), os.path.join('meta', 'main.yaml'))
|
||||||
META_INSTALL = os.path.join('meta', '.galaxy_install_info')
|
META_INSTALL = os.path.join('meta', '.galaxy_install_info')
|
||||||
ROLE_DIRS = ('defaults', 'files', 'handlers', 'meta', 'tasks', 'templates', 'vars', 'tests')
|
ROLE_DIRS = ('defaults', 'files', 'handlers', 'meta', 'tasks', 'templates', 'vars', 'tests')
|
||||||
|
|
||||||
|
@ -96,16 +96,17 @@ class GalaxyRole(object):
|
||||||
Returns role metadata
|
Returns role metadata
|
||||||
"""
|
"""
|
||||||
if self._metadata is None:
|
if self._metadata is None:
|
||||||
meta_path = os.path.join(self.path, self.META_MAIN)
|
for meta_main in self.META_MAIN:
|
||||||
if os.path.isfile(meta_path):
|
meta_path = os.path.join(self.path, meta_main)
|
||||||
try:
|
if os.path.isfile(meta_path):
|
||||||
f = open(meta_path, 'r')
|
try:
|
||||||
self._metadata = yaml.safe_load(f)
|
f = open(meta_path, 'r')
|
||||||
except:
|
self._metadata = yaml.safe_load(f)
|
||||||
display.vvvvv("Unable to load metadata for %s" % self.name)
|
except:
|
||||||
return False
|
display.vvvvv("Unable to load metadata for %s" % self.name)
|
||||||
finally:
|
return False
|
||||||
f.close()
|
finally:
|
||||||
|
f.close()
|
||||||
|
|
||||||
return self._metadata
|
return self._metadata
|
||||||
|
|
||||||
|
@ -268,18 +269,19 @@ class GalaxyRole(object):
|
||||||
members = role_tar_file.getmembers()
|
members = role_tar_file.getmembers()
|
||||||
# next find the metadata file
|
# next find the metadata file
|
||||||
for member in members:
|
for member in members:
|
||||||
if self.META_MAIN in member.name:
|
for meta_main in self.META_MAIN:
|
||||||
# Look for parent of meta/main.yml
|
if meta_main in member.name:
|
||||||
# Due to possibility of sub roles each containing meta/main.yml
|
# Look for parent of meta/main.yml
|
||||||
# look for shortest length parent
|
# Due to possibility of sub roles each containing meta/main.yml
|
||||||
meta_parent_dir = os.path.dirname(os.path.dirname(member.name))
|
# look for shortest length parent
|
||||||
if not meta_file:
|
meta_parent_dir = os.path.dirname(os.path.dirname(member.name))
|
||||||
archive_parent_dir = meta_parent_dir
|
if not meta_file:
|
||||||
meta_file = member
|
|
||||||
else:
|
|
||||||
if len(meta_parent_dir) < len(archive_parent_dir):
|
|
||||||
archive_parent_dir = meta_parent_dir
|
archive_parent_dir = meta_parent_dir
|
||||||
meta_file = member
|
meta_file = member
|
||||||
|
else:
|
||||||
|
if len(meta_parent_dir) < len(archive_parent_dir):
|
||||||
|
archive_parent_dir = meta_parent_dir
|
||||||
|
meta_file = member
|
||||||
if not meta_file:
|
if not meta_file:
|
||||||
raise AnsibleError("this role does not appear to have a meta/main.yml file.")
|
raise AnsibleError("this role does not appear to have a meta/main.yml file.")
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in a new issue