mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 21:00:22 -07:00
Starting to move over lookups and fixing some bugs related to that
This commit is contained in:
parent
0823fb2cd9
commit
63c2d616e7
14 changed files with 236 additions and 61 deletions
|
@ -140,9 +140,7 @@ class ActionModule(ActionBase):
|
|||
else:
|
||||
private_key = task_vars.get('ansible_ssh_private_key_file', self.runner.private_key_file)
|
||||
|
||||
private_key = template.template(self.runner.basedir, private_key, task_vars, fail_on_undefined=True)
|
||||
|
||||
if not private_key is None:
|
||||
if private_key is not None:
|
||||
private_key = os.path.expanduser(private_key)
|
||||
|
||||
# use the mode to define src and dest's url
|
||||
|
@ -172,7 +170,7 @@ class ActionModule(ActionBase):
|
|||
# module_args = "CHECKMODE=True"
|
||||
|
||||
# run the module and store the result
|
||||
result = self.runner._execute_module('synchronize', tmp=tmpmodule_args, complex_args=options, task_vars=task_vars)
|
||||
result = self.runner._execute_module('synchronize', module_args=, complex_args=options, task_vars=task_vars)
|
||||
|
||||
return result
|
||||
|
||||
|
|
|
@ -19,3 +19,25 @@
|
|||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
__all__ = ['LookupBase']
|
||||
|
||||
class LookupBase:
|
||||
def __init__(self, **kwargs):
|
||||
pass
|
||||
|
||||
def _flatten(self, terms):
|
||||
ret = []
|
||||
for term in terms:
|
||||
if isinstance(term, (list, tuple)):
|
||||
ret.extend(term)
|
||||
else:
|
||||
ret.append(term)
|
||||
return ret
|
||||
|
||||
def _combine(self, a, b):
|
||||
results = []
|
||||
for x in a:
|
||||
for y in b:
|
||||
results.append(self._flatten([x,y]))
|
||||
return results
|
||||
|
||||
|
|
|
@ -15,30 +15,10 @@
|
|||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#from ansible.utils import safe_eval
|
||||
#import ansible.utils as utils
|
||||
#import ansible.errors as errors
|
||||
from ansible.plugins.lookup import LookupBase
|
||||
|
||||
def flatten(terms):
|
||||
ret = []
|
||||
for term in terms:
|
||||
if isinstance(term, list):
|
||||
ret.extend(term)
|
||||
else:
|
||||
ret.append(term)
|
||||
return ret
|
||||
|
||||
class LookupModule(object):
|
||||
|
||||
def __init__(self, basedir=None, **kwargs):
|
||||
self.basedir = basedir
|
||||
|
||||
def run(self, terms, inject=None, **kwargs):
|
||||
# FIXME: this function needs to be ported still, or something like it
|
||||
# where really the intention is just to template a bare variable
|
||||
# with the result being a list of terms
|
||||
#terms = utils.listify_lookup_plugin_terms(terms, self.basedir, inject)
|
||||
|
||||
return flatten(terms)
|
||||
class LookupModule(LookupBase):
|
||||
|
||||
def run(self, terms, **kwargs):
|
||||
return self._flatten(terms)
|
||||
|
||||
|
|
49
v2/ansible/plugins/lookup/nested.py
Normal file
49
v2/ansible/plugins/lookup/nested.py
Normal file
|
@ -0,0 +1,49 @@
|
|||
# (c) 2012, Michael DeHaan <michael.dehaan@gmail.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/>.
|
||||
|
||||
from ansible.errors import AnsibleError
|
||||
from ansible.plugins.lookup import LookupBase
|
||||
from ansible.utils.listify import listify_lookup_plugin_terms
|
||||
|
||||
class LookupModule(LookupBase):
|
||||
|
||||
def __lookup_variabless(self, terms, variables):
|
||||
results = []
|
||||
for x in terms:
|
||||
intermediate = listify_lookup_plugin_terms(x, variables)
|
||||
results.append(intermediate)
|
||||
return results
|
||||
|
||||
def run(self, terms, variables=None, **kwargs):
|
||||
|
||||
terms = self.__lookup_variabless(terms, variables)
|
||||
|
||||
my_list = terms[:]
|
||||
my_list.reverse()
|
||||
result = []
|
||||
if len(my_list) == 0:
|
||||
raise AnsibleError("with_nested requires at least one element in the nested list")
|
||||
result = my_list.pop()
|
||||
while len(my_list) > 0:
|
||||
result2 = self._combine(result, my_list.pop())
|
||||
result = result2
|
||||
new_result = []
|
||||
for x in result:
|
||||
new_result.append(self._flatten(x))
|
||||
return new_result
|
||||
|
||||
|
|
@ -96,7 +96,13 @@ class StrategyBase:
|
|||
debug("done getting variables")
|
||||
|
||||
debug("running post_validate() on the task")
|
||||
new_task.post_validate(task_vars)
|
||||
if new_task.loop:
|
||||
# if the task has a lookup loop specified, we do not error out
|
||||
# on undefined variables yet, as fields may use {{item}} or some
|
||||
# variant, which won't be defined until execution time
|
||||
new_task.post_validate(task_vars, fail_on_undefined=False)
|
||||
else:
|
||||
new_task.post_validate(task_vars)
|
||||
debug("done running post_validate() on the task")
|
||||
|
||||
# and then queue the new task
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue