1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Work in progress on task loading.

This commit is contained in:
Michael DeHaan 2014-10-06 16:29:02 -04:00
parent 1556b0384f
commit e66a0096a7
6 changed files with 36 additions and 22 deletions

View file

@ -32,7 +32,7 @@ class TestTask(unittest.TestCase):
t = Task.load(basic_shell_task)
assert t is not None
assert t.name == basic_shell_task['name']
assert t.module == 'shell'
assert t.action == 'shell'
assert t.args == 'echo hi'
def test_can_load_action_kv_form(self):

View file

@ -0,0 +1,2 @@
# TODO: header

View file

@ -18,8 +18,9 @@
#from ansible.common.errors import AnsibleError
class Attribute(object):
def __init__(self, isa=None):
def __init__(self, isa=None, private=False):
self.isa = isa
self.private = private
self.value = None
def __call__(self):

View file

@ -37,6 +37,10 @@ class Base(object):
''' walk the input datastructure and assign any values '''
assert ds is not None
# we currently don't do anything with private attributes but may
# later decide to filter them out of 'ds' here.
ds = self.munge(ds)
# walk all attributes in the class
@ -64,7 +68,7 @@ class Base(object):
''' validation that is done at parse time, not load time '''
# walk all fields in the object
for (name, attribute) in self.__dict__:
for (name, attribute) in self.__dict__.iteritems():
# find any field attributes
if isinstance(attribute, FieldAttribute):
@ -95,5 +99,4 @@ class Base(object):
if needle in self._attributes:
return self._attributes[needle]
raise AttributeError
raise AttributeError("attribute not found: %s" % needle)

View file

@ -45,6 +45,8 @@ class Task(Base):
# will be used if defined
# might be possible to define others
_args = FieldAttribute(isa='dict')
_action = FieldAttribute(isa='string')
_always_run = FieldAttribute(isa='bool')
@ -60,11 +62,11 @@ class Task(Base):
# FIXME: this should not be a Task
# include = FieldAttribute(isa='string')
_loop = Attribute()
_loop = FieldAttribute(isa='string', private=True)
_loop_args = FieldAttribute(isa='list', private=True)
_local_action = FieldAttribute(isa='string')
# FIXME: this should not be a Task
_module_args = Attribute(isa='dict')
_meta = FieldAttribute(isa='string')
_name = FieldAttribute(isa='string')
@ -127,25 +129,31 @@ class Task(Base):
# convert it to "module + args"
if k in module_finder:
if _module.value is not None or 'action' in ds or 'local_action' in ds:
if self._action.value is not None or 'action' in ds or 'local_action' in ds:
raise AnsibleError("duplicate action in task: %s" % k)
_module.value = k
_module_args.value = v
print "SCANNED: %s" % k
new_ds['action'] = k
new_ds['args'] = v
# handle any loops, there can be only one kind of loop
elif "with_%s" % k in lookup_finder:
if _loop.value is not None:
if self._loop.value is not None:
raise AnsibleError("duplicate loop in task: %s" % k)
_loop.value = k
_loop_args.value = v
new_ds['loop'] = k
new_ds['loop_args'] = v
# otherwise send it through straight
else:
# nothing we need to filter
print "PASSING: %s => %s" % (k,v)
new_ds[k] = v
print "NEW_DS=%s" % new_ds
return new_ds

View file

@ -216,28 +216,28 @@ class PluginLoader(object):
action_loader = PluginLoader(
'ActionModule',
'ansible.runner.action_plugins',
'ansible.plugins.action',
C.DEFAULT_ACTION_PLUGIN_PATH,
'action_plugins'
)
cache_loader = PluginLoader(
'CacheModule',
'ansible.cache',
'ansible.plugins.cache',
C.DEFAULT_CACHE_PLUGIN_PATH,
'cache_plugins'
)
callback_loader = PluginLoader(
'CallbackModule',
'ansible.callback_plugins',
'ansible.plugins.callback',
C.DEFAULT_CALLBACK_PLUGIN_PATH,
'callback_plugins'
)
connection_loader = PluginLoader(
'Connection',
'ansible.runner.connection_plugins',
'ansible.plugins.connection',
C.DEFAULT_CONNECTION_PLUGIN_PATH,
'connection_plugins',
aliases={'paramiko': 'paramiko_ssh'}
@ -245,7 +245,7 @@ connection_loader = PluginLoader(
shell_loader = PluginLoader(
'ShellModule',
'ansible.runner.shell_plugins',
'ansible.plugins.shell',
'shell_plugins',
'shell_plugins',
)
@ -259,21 +259,21 @@ module_finder = PluginLoader(
lookup_finder = PluginLoader(
'LookupModule',
'ansible.runner.lookup_plugins',
'ansible.plugins.lookup',
C.DEFAULT_LOOKUP_PLUGIN_PATH,
'lookup_plugins'
)
vars_finder = PluginLoader(
'VarsModule',
'ansible.inventory.vars_plugins',
'ansible.plugins.vars',
C.DEFAULT_VARS_PLUGIN_PATH,
'vars_plugins'
)
filter_finder = PluginLoader(
'FilterModule',
'ansible.runner.filter_plugins',
'ansible.plugins.filter',
C.DEFAULT_FILTER_PLUGIN_PATH,
'filter_plugins'
)