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:
parent
1556b0384f
commit
e66a0096a7
6 changed files with 36 additions and 22 deletions
|
@ -32,7 +32,7 @@ class TestTask(unittest.TestCase):
|
||||||
t = Task.load(basic_shell_task)
|
t = Task.load(basic_shell_task)
|
||||||
assert t is not None
|
assert t is not None
|
||||||
assert t.name == basic_shell_task['name']
|
assert t.name == basic_shell_task['name']
|
||||||
assert t.module == 'shell'
|
assert t.action == 'shell'
|
||||||
assert t.args == 'echo hi'
|
assert t.args == 'echo hi'
|
||||||
|
|
||||||
def test_can_load_action_kv_form(self):
|
def test_can_load_action_kv_form(self):
|
||||||
|
|
2
v2/ansible/modules/__init__.py
Normal file
2
v2/ansible/modules/__init__.py
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
# TODO: header
|
||||||
|
|
|
@ -18,8 +18,9 @@
|
||||||
#from ansible.common.errors import AnsibleError
|
#from ansible.common.errors import AnsibleError
|
||||||
|
|
||||||
class Attribute(object):
|
class Attribute(object):
|
||||||
def __init__(self, isa=None):
|
def __init__(self, isa=None, private=False):
|
||||||
self.isa = isa
|
self.isa = isa
|
||||||
|
self.private = private
|
||||||
self.value = None
|
self.value = None
|
||||||
|
|
||||||
def __call__(self):
|
def __call__(self):
|
||||||
|
|
|
@ -37,6 +37,10 @@ class Base(object):
|
||||||
''' walk the input datastructure and assign any values '''
|
''' walk the input datastructure and assign any values '''
|
||||||
|
|
||||||
assert ds is not None
|
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)
|
ds = self.munge(ds)
|
||||||
|
|
||||||
# walk all attributes in the class
|
# walk all attributes in the class
|
||||||
|
@ -64,7 +68,7 @@ class Base(object):
|
||||||
''' validation that is done at parse time, not load time '''
|
''' validation that is done at parse time, not load time '''
|
||||||
|
|
||||||
# walk all fields in the object
|
# walk all fields in the object
|
||||||
for (name, attribute) in self.__dict__:
|
for (name, attribute) in self.__dict__.iteritems():
|
||||||
|
|
||||||
# find any field attributes
|
# find any field attributes
|
||||||
if isinstance(attribute, FieldAttribute):
|
if isinstance(attribute, FieldAttribute):
|
||||||
|
@ -95,5 +99,4 @@ class Base(object):
|
||||||
if needle in self._attributes:
|
if needle in self._attributes:
|
||||||
return self._attributes[needle]
|
return self._attributes[needle]
|
||||||
|
|
||||||
raise AttributeError
|
raise AttributeError("attribute not found: %s" % needle)
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,8 @@ class Task(Base):
|
||||||
# will be used if defined
|
# will be used if defined
|
||||||
# might be possible to define others
|
# might be possible to define others
|
||||||
|
|
||||||
|
|
||||||
|
_args = FieldAttribute(isa='dict')
|
||||||
_action = FieldAttribute(isa='string')
|
_action = FieldAttribute(isa='string')
|
||||||
|
|
||||||
_always_run = FieldAttribute(isa='bool')
|
_always_run = FieldAttribute(isa='bool')
|
||||||
|
@ -60,11 +62,11 @@ class Task(Base):
|
||||||
# FIXME: this should not be a Task
|
# FIXME: this should not be a Task
|
||||||
# include = FieldAttribute(isa='string')
|
# include = FieldAttribute(isa='string')
|
||||||
|
|
||||||
_loop = Attribute()
|
_loop = FieldAttribute(isa='string', private=True)
|
||||||
|
_loop_args = FieldAttribute(isa='list', private=True)
|
||||||
_local_action = FieldAttribute(isa='string')
|
_local_action = FieldAttribute(isa='string')
|
||||||
|
|
||||||
# FIXME: this should not be a Task
|
# FIXME: this should not be a Task
|
||||||
_module_args = Attribute(isa='dict')
|
|
||||||
_meta = FieldAttribute(isa='string')
|
_meta = FieldAttribute(isa='string')
|
||||||
|
|
||||||
_name = FieldAttribute(isa='string')
|
_name = FieldAttribute(isa='string')
|
||||||
|
@ -127,25 +129,31 @@ class Task(Base):
|
||||||
# convert it to "module + args"
|
# convert it to "module + args"
|
||||||
|
|
||||||
if k in module_finder:
|
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)
|
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
|
# handle any loops, there can be only one kind of loop
|
||||||
|
|
||||||
elif "with_%s" % k in lookup_finder:
|
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)
|
raise AnsibleError("duplicate loop in task: %s" % k)
|
||||||
_loop.value = k
|
new_ds['loop'] = k
|
||||||
_loop_args.value = v
|
new_ds['loop_args'] = v
|
||||||
|
|
||||||
# otherwise send it through straight
|
# otherwise send it through straight
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# nothing we need to filter
|
# nothing we need to filter
|
||||||
|
print "PASSING: %s => %s" % (k,v)
|
||||||
new_ds[k] = v
|
new_ds[k] = v
|
||||||
|
|
||||||
|
print "NEW_DS=%s" % new_ds
|
||||||
return new_ds
|
return new_ds
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -216,28 +216,28 @@ class PluginLoader(object):
|
||||||
|
|
||||||
action_loader = PluginLoader(
|
action_loader = PluginLoader(
|
||||||
'ActionModule',
|
'ActionModule',
|
||||||
'ansible.runner.action_plugins',
|
'ansible.plugins.action',
|
||||||
C.DEFAULT_ACTION_PLUGIN_PATH,
|
C.DEFAULT_ACTION_PLUGIN_PATH,
|
||||||
'action_plugins'
|
'action_plugins'
|
||||||
)
|
)
|
||||||
|
|
||||||
cache_loader = PluginLoader(
|
cache_loader = PluginLoader(
|
||||||
'CacheModule',
|
'CacheModule',
|
||||||
'ansible.cache',
|
'ansible.plugins.cache',
|
||||||
C.DEFAULT_CACHE_PLUGIN_PATH,
|
C.DEFAULT_CACHE_PLUGIN_PATH,
|
||||||
'cache_plugins'
|
'cache_plugins'
|
||||||
)
|
)
|
||||||
|
|
||||||
callback_loader = PluginLoader(
|
callback_loader = PluginLoader(
|
||||||
'CallbackModule',
|
'CallbackModule',
|
||||||
'ansible.callback_plugins',
|
'ansible.plugins.callback',
|
||||||
C.DEFAULT_CALLBACK_PLUGIN_PATH,
|
C.DEFAULT_CALLBACK_PLUGIN_PATH,
|
||||||
'callback_plugins'
|
'callback_plugins'
|
||||||
)
|
)
|
||||||
|
|
||||||
connection_loader = PluginLoader(
|
connection_loader = PluginLoader(
|
||||||
'Connection',
|
'Connection',
|
||||||
'ansible.runner.connection_plugins',
|
'ansible.plugins.connection',
|
||||||
C.DEFAULT_CONNECTION_PLUGIN_PATH,
|
C.DEFAULT_CONNECTION_PLUGIN_PATH,
|
||||||
'connection_plugins',
|
'connection_plugins',
|
||||||
aliases={'paramiko': 'paramiko_ssh'}
|
aliases={'paramiko': 'paramiko_ssh'}
|
||||||
|
@ -245,7 +245,7 @@ connection_loader = PluginLoader(
|
||||||
|
|
||||||
shell_loader = PluginLoader(
|
shell_loader = PluginLoader(
|
||||||
'ShellModule',
|
'ShellModule',
|
||||||
'ansible.runner.shell_plugins',
|
'ansible.plugins.shell',
|
||||||
'shell_plugins',
|
'shell_plugins',
|
||||||
'shell_plugins',
|
'shell_plugins',
|
||||||
)
|
)
|
||||||
|
@ -259,21 +259,21 @@ module_finder = PluginLoader(
|
||||||
|
|
||||||
lookup_finder = PluginLoader(
|
lookup_finder = PluginLoader(
|
||||||
'LookupModule',
|
'LookupModule',
|
||||||
'ansible.runner.lookup_plugins',
|
'ansible.plugins.lookup',
|
||||||
C.DEFAULT_LOOKUP_PLUGIN_PATH,
|
C.DEFAULT_LOOKUP_PLUGIN_PATH,
|
||||||
'lookup_plugins'
|
'lookup_plugins'
|
||||||
)
|
)
|
||||||
|
|
||||||
vars_finder = PluginLoader(
|
vars_finder = PluginLoader(
|
||||||
'VarsModule',
|
'VarsModule',
|
||||||
'ansible.inventory.vars_plugins',
|
'ansible.plugins.vars',
|
||||||
C.DEFAULT_VARS_PLUGIN_PATH,
|
C.DEFAULT_VARS_PLUGIN_PATH,
|
||||||
'vars_plugins'
|
'vars_plugins'
|
||||||
)
|
)
|
||||||
|
|
||||||
filter_finder = PluginLoader(
|
filter_finder = PluginLoader(
|
||||||
'FilterModule',
|
'FilterModule',
|
||||||
'ansible.runner.filter_plugins',
|
'ansible.plugins.filter',
|
||||||
C.DEFAULT_FILTER_PLUGIN_PATH,
|
C.DEFAULT_FILTER_PLUGIN_PATH,
|
||||||
'filter_plugins'
|
'filter_plugins'
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue