@ -78,16 +78,47 @@ class RoleMixin(object):
Note : The methods for actual display of role data are not present here .
"""
ROLE_ARGSPEC_FILE = ' main.yml '
# Potential locations of the role arg spec file in the meta subdir, with main.yml
# having the lowest priority.
ROLE_ARGSPEC_FILES = [ ' argument_specs ' + e for e in C . YAML_FILENAME_EXTENSIONS ] + [ " main " + e for e in C . YAML_FILENAME_EXTENSIONS ]
def _load_argspec ( self , role_name , collection_path = None , role_path = None ) :
""" Load the role argument spec data from the source file.
: param str role_name : The name of the role for which we want the argspec data .
: param str collection_path : Path to the collection containing the role . This
will be None for standard roles .
: param str role_path : Path to the standard role . This will be None for
collection roles .
We support two files containing the role arg spec data : either meta / main . yml
or meta / argument_spec . yml . The argument_spec . yml file will take precedence
over the meta / main . yml file , if it exists . Data is NOT combined between the
two files .
: returns : A dict of all data underneath the ` ` argument_specs ` ` top - level YAML
key in the argspec data file . Empty dict is returned if there is no data .
"""
if collection_path :
path = os . path . join ( collection_path , ' roles ' , role_name , ' meta ' , self . ROLE_ARGSPEC_FILE )
meta_ path = os . path . join ( collection_path , ' roles ' , role_name , ' meta ' )
elif role_path :
path = os . path . join ( role_path , ' meta ' , self . ROLE_ARGSPEC_FILE )
meta_ path = os . path . join ( role_path , ' meta ' )
else :
raise AnsibleError ( " A path is required to load argument specs for role ' %s ' " % role_name )
path = None
# Check all potential spec files
for specfile in self . ROLE_ARGSPEC_FILES :
full_path = os . path . join ( meta_path , specfile )
if os . path . exists ( full_path ) :
path = full_path
break
if path is None :
return { }
try :
with open ( path , ' r ' ) as f :
data = from_yaml ( f . read ( ) , file_name = path )
@ -110,18 +141,25 @@ class RoleMixin(object):
"""
found = set ( )
found_names = set ( )
for path in role_paths :
if not os . path . isdir ( path ) :
continue
# Check each subdir for a meta/main.yml file
# Check each subdir for an argument spec file
for entry in os . listdir ( path ) :
role_path = os . path . join ( path , entry )
full_path = os . path . join ( role_path , ' meta ' , self . ROLE_ARGSPEC_FILE )
# Check all potential spec files
for specfile in self . ROLE_ARGSPEC_FILES :
full_path = os . path . join ( role_path , ' meta ' , specfile )
if os . path . exists ( full_path ) :
if name_filters is None or entry in name_filters :
if entry not in found_names :
found . add ( ( entry , role_path ) )
found_names . add ( entry )
# select first-found
break
return found
def _find_all_collection_roles ( self , name_filters = None , collection_filter = None ) :
@ -147,7 +185,10 @@ class RoleMixin(object):
roles_dir = os . path . join ( path , ' roles ' )
if os . path . exists ( roles_dir ) :
for entry in os . listdir ( roles_dir ) :
full_path = os . path . join ( roles_dir , entry , ' meta ' , self . ROLE_ARGSPEC_FILE )
# Check all potential spec files
for specfile in self . ROLE_ARGSPEC_FILES :
full_path = os . path . join ( roles_dir , entry , ' meta ' , specfile )
if os . path . exists ( full_path ) :
if name_filters is None :
found . add ( ( entry , collname , path ) )
@ -160,6 +201,7 @@ class RoleMixin(object):
found . add ( ( entry , collname , path ) )
elif fqcn == entry :
found . add ( ( entry , collname , path ) )
break
return found
def _build_summary ( self , role , collection , argspec ) :