utils.warning("It is unnecessary to use '{{' in loops, leave variables in loop expressions bare.")
plugin_name=k.replace("with_","")
ifplugin_nameinutils.plugins.lookup_loader:
results['_lookup_plugin']=plugin_name
results['_lookup_terms']=v
else:
raiseerrors.AnsibleError("cannot find lookup plugin named %s for usage in with_%s"%(plugin_name,plugin_name))
returnresults
def_load_legacy_when(self,ds,k,v):
''' yell about old when syntax being used still '''
# 'action' and 'local_action' are mutually-exclusive options
if'action'indsand'local_action'inds:
raiseAnsibleError("the 'action' and 'local_action' attributes can not be used together")
utils.deprecated("The 'when_' conditional has been removed. Switch to using the regular unified 'when' statements as described on docs.ansible.com.","1.5",removed=True)
ifself._when:
raiseerrors.AnsibleError("multiple when_* statements specified in task %s"%(ds.get('name',ds.get('action'))))
when_name=k.replace("when_","")
returndict(_when="%s%s"%(when_name,v))
# iterate over each key/value in the datastructure to parse out its parameters.
args=None
def_load_when(self,ds,k,v):
''' validate/transmogrify/assign a conditional '''
conditionals=self._when.copy()
conditionals.push(v)
returndict(_when=conditionals)
def_load_changed_when(self,ds,k,v):
''' validate/transmogrify/assign a changed_when conditional '''
conditionals=self._changed_when.copy()
conditionals.push(v)
returndict(_changed_when=conditionals)
def_load_failed_when(self,ds,k,v):
''' validate/transmogrify/assign a failed_when conditional '''
conditionals=self._failed_when.copy()
conditionals.push(v)
returndict(_failed_when=conditionals)
# FIXME: move to BaseObject
def_load_tags(self,ds,k,v):
''' validate/transmogrify/assign any tags '''
new_tags=self.tags.copy()
tags=v
ifisinstance(v,basestring):
tags=v.split(',')
new_tags.push(v)
returndict(_tags=v)
def_load_invalid_key(self,ds,k,v):
''' handle any key we do not recognize '''
raiseAnsibleError("%s is not a legal parameter in an Ansible task or handler"%k)
def_load_other_valid_key(self,ds,k,v):
''' handle any other attribute we DO recognize '''
results=dict()
k="_%s"%k
results[k]=v
returnresults
def_loader_for_key(self,k):
''' based on the name of a datastructure element, find the code to handle it '''
ifkin('action','local_action'):
returnself._load_action
elifkinutils.plugins.module_finder:
returnself._load_module
elifk.startswith('with_'):
returnself._load_loop
elifk=='changed_when':
returnself._load_changed_when
elifk=='failed_when':
returnself._load_failed_when
elifk=='when':
returnself._load_when
elifk=='tags':
returnself._load_tags
elifknotinself.VALID_KEYS:
returnself._load_invalid_key
else:
returnself._load_other_valid_key
@classmethod
defload(self,ds,block=None,role=None):
''' walk the datastructure and store/validate parameters '''
self=Task(block=block,role=role)
returnself._load_from_datastructure(ds)
# TODO: move to BaseObject
def_load_from_datastructure(ds)
self._pre_validate(ds)
# load the keys from the datastructure
fork,vinds.iteritems():
ifkin('action','local_action'):
# task structure is:
# action: module_name k=v ...
# or
# local_action: module_name k=v ...
module_name,params=v.strip().split('',1)
ifmodule_namenotinutils.plugins.module_finder:
raiseAnsibleError("the specified module '%s' could not be found, check your module path"%module_name)
self._module_name=module_name
self._parameters=utils.parse_kv(params)
ifk=='local_action':
if'delegate_to'inds:
raiseAnsibleError("delegate_to cannot be specified with local_action in task: %s"%ds.get('name',v))
self._delegate_to='127.0.0.1'
ifnot'transport'indsandnot'connection'inds:
self._transport='local'
elifkinutils.plugins.module_finder:
# task structure is:
# - module_name: k=v ...
ifself._module_name:
raiseAnsibleError("the module name (%s) was already specified, '%s' is a duplicate"%(self._module_name,k))
elif'action'inds:
raiseAnsibleError("multiple actions specified in task: '%s' and '%s'"%(k,ds.get('name',ds['action'])))
self._module_name=k
ifisinstance(v,dict)and'args'inds:
raiseAnsibleError("can't combine args: and a dict for %s: in task %s"%(k,ds.get('name',"%s: %s"%(k,v))))
utils.warning("It is unnecessary to use '{{' in loops, leave variables in loop expressions bare.")
plugin_name=k.replace("with_","")
ifplugin_nameinutils.plugins.lookup_loader:
self._lookup_plugin=plugin_name
self._lookup_terms=v
else:
raiseerrors.AnsibleError("cannot find lookup plugin named %s for usage in with_%s"%(plugin_name,plugin_name))
elifk.startswith('when_'):
utils.deprecated("The 'when_' conditional has been removed. Switch to using the regular unified 'when' statements as described on docs.ansible.com.","1.5",removed=True)
ifself._when:
raiseerrors.AnsibleError("multiple when_* statements specified in task %s"%(ds.get('name',ds.get('action'))))
when_name=k.replace("when_","")
self._when="%s%s"%(when_name,v)
elifkin('changed_when','failed_when','when'):
# these are conditional objects, so we push the new conditional value
# into the object so that it can be evaluated later
getattr(self,'_%s'%k).push(v)
elifk=='tags':
# all taggable datastructures in Ansible (tasks, roles, etc.) are
# based on the Base() class, which includes the _tags attribute
# (which is a Tag() class)
tags=v
ifisinstance(v,basestring):
tags=v.split(',')
self._tags.push(tags)
elifknotinself.VALID_KEYS:
raiseAnsibleError("%s is not a legal parameter in an Ansible task or handler"%k)
else:
setattr(self,'_%s'%k,v)
# if args were specified along with parameters, merge them now