Coverage for lib/ansible/playbook/role/definition.py : 79%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# (c) 2014 Michael DeHaan, <michael@ansible.com> # # This file is part of Ansible # # Ansible is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # Ansible is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see <http://www.gnu.org/licenses/>.
# Make coding more python3-ish
# def __repr__(self): # return 'ROLEDEF: ' + self._attributes.get('role', '<no name set>')
raise AnsibleError("not implemented")
# role names that are simply numbers can be parsed by PyYAML # as integers even when quoted, so turn it into a string type ds = "%s" % ds
raise AnsibleAssertionError()
# save the original ds for use later
# we create a new data structure here, using the same # object used internally by the YAML parsing code so we # can preserve file:line:column information if it exists
# first we pull the role name out of the data structure, # and then use that to determine the role path (which may # result in a new role name, if it was a file path)
# next, we split the role params out from the valid role # attributes and update the new datastructure with that # result and the role name
# set the role name in the new ds
# we store the role path internally
# and return the cleaned-up data structure
''' Returns the role name (either the role: or name: field) from the role definition, or (when the role definition is a simple string), just that string '''
raise AnsibleError('role definitions must contain a role name', obj=ds)
# if we have the required datastructures, and if the role_name # contains a variable, try and template it now role_name = templar.template(role_name)
''' the 'role', as specified in the ds (or as a bare string), can either be a simple name or a full path. If it is a full path, we use the basename as the role name, otherwise we take the name as-given and append it to the default role path '''
# we always start the search for roles in the base directory of the playbook os.path.join(self._loader.get_basedir(), u'roles'), ]
# also search in the configured roles path
# next, append the roles basedir, if it was set, so we can # search relative to that directory for dependent roles
# finally as a last resort we look in the current basedir as set # in the loader (which should be the playbook dir itself) but without # the roles/ dir appended
# create a templar class to template the dependency names, in # case they contain variables else: all_vars = dict()
# now iterate through the possible paths and return the first one we find
# if not found elsewhere try to extract path from name role_path = unfrackpath(role_name) if self._loader.path_exists(role_path): role_name = os.path.basename(role_name) return (role_name, role_path)
raise AnsibleError("the role '%s' was not found in %s" % (role_name, ":".join(role_search_paths)), obj=self._ds)
''' Splits any random role params off from the role spec and store them in a dictionary of params for parsing later '''
# use the list of FieldAttribute values to determine what is and is not # an extra parameter for this role (or sub-class of this role) # FIXME: hard-coded list of exception key names here corresponds to the # connection fields in the Base class. There may need to be some # other mechanism where we exclude certain kinds of field attributes, # or make this list more automatic in some way so we don't have to # remember to update it manually. if key in ('connection', 'port', 'remote_user'): display.deprecated("Using '%s' as a role param has been deprecated. " % key + "In the future, these values should be entered in the `vars:` " + "section for roles, but for now we'll store it as both a param and an attribute.", version="2.7") role_def[key] = value # this key does not match a field attribute, so it must be a role param role_params[key] = value else: # this is a field attribute, so copy it over directly
|