summaryrefslogtreecommitdiffstats
path: root/lib/ansible/plugins/lookup
diff options
context:
space:
mode:
Diffstat (limited to 'lib/ansible/plugins/lookup')
-rw-r--r--lib/ansible/plugins/lookup/__init__.py4
-rw-r--r--lib/ansible/plugins/lookup/config.py34
-rw-r--r--lib/ansible/plugins/lookup/csvfile.py23
-rw-r--r--lib/ansible/plugins/lookup/dict.py5
-rw-r--r--lib/ansible/plugins/lookup/env.py8
-rw-r--r--lib/ansible/plugins/lookup/file.py3
-rw-r--r--lib/ansible/plugins/lookup/fileglob.py3
-rw-r--r--lib/ansible/plugins/lookup/first_found.py15
-rw-r--r--lib/ansible/plugins/lookup/indexed_items.py3
-rw-r--r--lib/ansible/plugins/lookup/ini.py9
-rw-r--r--lib/ansible/plugins/lookup/inventory_hostnames.py3
-rw-r--r--lib/ansible/plugins/lookup/items.py3
-rw-r--r--lib/ansible/plugins/lookup/lines.py3
-rw-r--r--lib/ansible/plugins/lookup/list.py4
-rw-r--r--lib/ansible/plugins/lookup/nested.py3
-rw-r--r--lib/ansible/plugins/lookup/password.py30
-rw-r--r--lib/ansible/plugins/lookup/pipe.py3
-rw-r--r--lib/ansible/plugins/lookup/random_choice.py3
-rw-r--r--lib/ansible/plugins/lookup/sequence.py73
-rw-r--r--lib/ansible/plugins/lookup/subelements.py3
-rw-r--r--lib/ansible/plugins/lookup/template.py3
-rw-r--r--lib/ansible/plugins/lookup/together.py3
-rw-r--r--lib/ansible/plugins/lookup/unvault.py3
-rw-r--r--lib/ansible/plugins/lookup/url.py12
-rw-r--r--lib/ansible/plugins/lookup/varnames.py3
-rw-r--r--lib/ansible/plugins/lookup/vars.py3
26 files changed, 118 insertions, 144 deletions
diff --git a/lib/ansible/plugins/lookup/__init__.py b/lib/ansible/plugins/lookup/__init__.py
index c9779d6..bc15943 100644
--- a/lib/ansible/plugins/lookup/__init__.py
+++ b/lib/ansible/plugins/lookup/__init__.py
@@ -15,9 +15,7 @@
# 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
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
+from __future__ import annotations
from abc import abstractmethod
diff --git a/lib/ansible/plugins/lookup/config.py b/lib/ansible/plugins/lookup/config.py
index b476b53..4c6b000 100644
--- a/lib/ansible/plugins/lookup/config.py
+++ b/lib/ansible/plugins/lookup/config.py
@@ -1,42 +1,46 @@
# (c) 2017 Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
+from __future__ import annotations
DOCUMENTATION = """
name: config
author: Ansible Core Team
version_added: "2.5"
- short_description: Lookup current Ansible configuration values
+ short_description: Display the 'resolved' Ansible option values.
description:
- - Retrieves the value of an Ansible configuration setting.
- - You can use C(ansible-config list) to see all available settings.
+ - Retrieves the value of an Ansible configuration setting, resolving all sources, from defaults, ansible.cfg, envirionmnet,
+ CLI, and variables, but not keywords.
+ - The values returned assume the context of the current host or C(inventory_hostname).
+ - You can use C(ansible-config list) to see the global available settings, add C(-t all) to also show plugin options.
options:
_terms:
- description: The key(s) to look up
+ description: The option(s) to look up.
required: True
on_missing:
- description:
- - action to take if term is missing from config
- - Error will raise a fatal error
- - Skip will just ignore the term
- - Warn will skip over it but issue a warning
+ description: Action to take if term is missing from config
default: error
type: string
- choices: ['error', 'skip', 'warn']
+ choices:
+ error: Issue an error message and raise fatal signal
+ warn: Issue a warning message and continue
+ skip: Silently ignore
plugin_type:
- description: the type of the plugin referenced by 'plugin_name' option.
+ description: The type of the plugin referenced by 'plugin_name' option.
choices: ['become', 'cache', 'callback', 'cliconf', 'connection', 'httpapi', 'inventory', 'lookup', 'netconf', 'shell', 'vars']
type: string
version_added: '2.12'
plugin_name:
- description: name of the plugin for which you want to retrieve configuration settings.
+ description: The name of the plugin for which you want to retrieve configuration settings.
type: string
version_added: '2.12'
show_origin:
- description: toggle the display of what configuration subsystem the value came from
+ description: Set this to return what configuration subsystem the value came from
+ (defaults, config file, environment, CLI, or variables).
type: bool
version_added: '2.16'
+ notes:
+ - Be aware that currently this lookup cannot take keywords nor delegation into account,
+ so for options that support keywords or are affected by delegation, it is at best a good guess or approximation.
"""
EXAMPLES = """
diff --git a/lib/ansible/plugins/lookup/csvfile.py b/lib/ansible/plugins/lookup/csvfile.py
index 76d97ed..9d199d8 100644
--- a/lib/ansible/plugins/lookup/csvfile.py
+++ b/lib/ansible/plugins/lookup/csvfile.py
@@ -1,8 +1,7 @@
# (c) 2013, Jan-Piet Mens <jpmens(at)gmail.com>
# (c) 2017 Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
+from __future__ import annotations
DOCUMENTATION = r"""
name: csvfile
@@ -17,6 +16,11 @@ DOCUMENTATION = r"""
col:
description: column to return (0 indexed).
default: "1"
+ keycol:
+ description: column to search in (0 indexed).
+ default: 0
+ type: int
+ version_added: "2.17"
default:
description: what to return if the value is not found in the file.
delimiter:
@@ -83,7 +87,7 @@ from ansible.module_utils.common.text.converters import to_bytes, to_native, to_
class CSVRecoder:
"""
- Iterator that reads an encoded stream and reencodes the input to UTF-8
+ Iterator that reads an encoded stream and encodes the input to UTF-8
"""
def __init__(self, f, encoding='utf-8'):
self.reader = codecs.getreader(encoding)(f)
@@ -123,14 +127,14 @@ class CSVReader:
class LookupModule(LookupBase):
- def read_csv(self, filename, key, delimiter, encoding='utf-8', dflt=None, col=1):
+ def read_csv(self, filename, key, delimiter, encoding='utf-8', dflt=None, col=1, keycol=0):
try:
f = open(to_bytes(filename), 'rb')
creader = CSVReader(f, delimiter=to_native(delimiter), encoding=encoding)
for row in creader:
- if len(row) and row[0] == key:
+ if len(row) and row[keycol] == key:
return row[int(col)]
except Exception as e:
raise AnsibleError("csvfile: %s" % to_native(e))
@@ -156,6 +160,7 @@ class LookupModule(LookupBase):
# parameters override per term using k/v
try:
+ reset_params = False
for name, value in kv.items():
if name == '_raw_params':
continue
@@ -163,7 +168,11 @@ class LookupModule(LookupBase):
raise AnsibleAssertionError('%s is not a valid option' % name)
self._deprecate_inline_kv()
- paramvals[name] = value
+ self.set_option(name, value)
+ reset_params = True
+
+ if reset_params:
+ paramvals = self.get_options()
except (ValueError, AssertionError) as e:
raise AnsibleError(e)
@@ -173,7 +182,7 @@ class LookupModule(LookupBase):
paramvals['delimiter'] = "\t"
lookupfile = self.find_file_in_search_path(variables, 'files', paramvals['file'])
- var = self.read_csv(lookupfile, key, paramvals['delimiter'], paramvals['encoding'], paramvals['default'], paramvals['col'])
+ var = self.read_csv(lookupfile, key, paramvals['delimiter'], paramvals['encoding'], paramvals['default'], paramvals['col'], paramvals['keycol'])
if var is not None:
if isinstance(var, MutableSequence):
for v in var:
diff --git a/lib/ansible/plugins/lookup/dict.py b/lib/ansible/plugins/lookup/dict.py
index af9a081..a8c1089 100644
--- a/lib/ansible/plugins/lookup/dict.py
+++ b/lib/ansible/plugins/lookup/dict.py
@@ -1,8 +1,7 @@
# (c) 2014, Kent R. Spillner <kspillner@acm.org>
# (c) 2017 Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
+from __future__ import annotations
DOCUMENTATION = """
name: dict
@@ -49,7 +48,7 @@ tasks:
RETURN = """
_list:
description:
- - list of composed dictonaries with key and value
+ - list of composed dictionaries with key and value
type: list
"""
diff --git a/lib/ansible/plugins/lookup/env.py b/lib/ansible/plugins/lookup/env.py
index db34d8d..50547a8 100644
--- a/lib/ansible/plugins/lookup/env.py
+++ b/lib/ansible/plugins/lookup/env.py
@@ -1,8 +1,7 @@
# (c) 2012, Jan-Piet Mens <jpmens(at)gmail.com>
# (c) 2017 Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
+from __future__ import annotations
DOCUMENTATION = """
name: env
@@ -56,11 +55,12 @@ RETURN = """
type: list
"""
+import os
+
from jinja2.runtime import Undefined
from ansible.errors import AnsibleUndefinedVariable
from ansible.plugins.lookup import LookupBase
-from ansible.utils import py3compat
class LookupModule(LookupBase):
@@ -72,7 +72,7 @@ class LookupModule(LookupBase):
d = self.get_option('default')
for term in terms:
var = term.split()[0]
- val = py3compat.environ.get(var, d)
+ val = os.environ.get(var, d)
if isinstance(val, Undefined):
raise AnsibleUndefinedVariable('The "env" lookup, found an undefined variable: %s' % var)
ret.append(val)
diff --git a/lib/ansible/plugins/lookup/file.py b/lib/ansible/plugins/lookup/file.py
index 25946b2..17338c0 100644
--- a/lib/ansible/plugins/lookup/file.py
+++ b/lib/ansible/plugins/lookup/file.py
@@ -1,8 +1,7 @@
# (c) 2012, Daniel Hokka Zakrisson <daniel@hozac.com>
# (c) 2017 Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
+from __future__ import annotations
DOCUMENTATION = """
name: file
diff --git a/lib/ansible/plugins/lookup/fileglob.py b/lib/ansible/plugins/lookup/fileglob.py
index 00d5f09..5ab730d 100644
--- a/lib/ansible/plugins/lookup/fileglob.py
+++ b/lib/ansible/plugins/lookup/fileglob.py
@@ -1,8 +1,7 @@
# (c) 2012, Michael DeHaan <michael.dehaan@gmail.com>
# (c) 2017 Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
+from __future__ import annotations
DOCUMENTATION = """
name: fileglob
diff --git a/lib/ansible/plugins/lookup/first_found.py b/lib/ansible/plugins/lookup/first_found.py
index 6862880..a68791b 100644
--- a/lib/ansible/plugins/lookup/first_found.py
+++ b/lib/ansible/plugins/lookup/first_found.py
@@ -1,8 +1,7 @@
# (c) 2013, seth vidal <skvidal@fedoraproject.org> red hat, inc
# (c) 2017 Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
+from __future__ import annotations
DOCUMENTATION = """
name: first_found
@@ -147,6 +146,7 @@ from jinja2.exceptions import UndefinedError
from ansible.errors import AnsibleLookupError, AnsibleUndefinedVariable
from ansible.module_utils.six import string_types
from ansible.plugins.lookup import LookupBase
+from ansible.utils.path import unfrackpath
def _splitter(value, chars):
@@ -198,7 +198,7 @@ class LookupModule(LookupBase):
# NOTE: this is used as 'global' but can be set many times?!?!?
skip = self.get_option('skip')
- # magic extra spliting to create lists
+ # magic extra splitting to create lists
filelist = _split_on(files, ',;')
pathlist = _split_on(paths, ',:;')
@@ -209,7 +209,7 @@ class LookupModule(LookupBase):
f = os.path.join(path, fn)
total_search.append(f)
elif filelist:
- # NOTE: this is now 'extend', previouslly it would clobber all options, but we deemed that a bug
+ # NOTE: this is now 'extend', previously it would clobber all options, but we deemed that a bug
total_search.extend(filelist)
else:
total_search.append(term)
@@ -218,8 +218,9 @@ class LookupModule(LookupBase):
def run(self, terms, variables, **kwargs):
+ self.set_options(var_options=variables, direct=kwargs)
+
if not terms:
- self.set_options(var_options=variables, direct=kwargs)
terms = self.get_option('files')
total_search, skip = self._process_terms(terms, variables, kwargs)
@@ -246,10 +247,10 @@ class LookupModule(LookupBase):
# exit if we find one!
if path is not None:
- return [path]
+ return [unfrackpath(path, follow=False)]
# if we get here, no file was found
if skip:
- # NOTE: global skip wont matter, only last 'skip' value in dict term
+ # NOTE: global skip won't matter, only last 'skip' value in dict term
return []
raise AnsibleLookupError("No file was found when using first_found.")
diff --git a/lib/ansible/plugins/lookup/indexed_items.py b/lib/ansible/plugins/lookup/indexed_items.py
index f63a895..fe919cd 100644
--- a/lib/ansible/plugins/lookup/indexed_items.py
+++ b/lib/ansible/plugins/lookup/indexed_items.py
@@ -1,8 +1,7 @@
# (c) 2012, Michael DeHaan <michael.dehaan@gmail.com>
# (c) 2017 Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
+from __future__ import annotations
DOCUMENTATION = """
name: indexed_items
diff --git a/lib/ansible/plugins/lookup/ini.py b/lib/ansible/plugins/lookup/ini.py
index 9467676..cdc9a15 100644
--- a/lib/ansible/plugins/lookup/ini.py
+++ b/lib/ansible/plugins/lookup/ini.py
@@ -1,8 +1,7 @@
# (c) 2015, Yannig Perre <yannig.perre(at)gmail.com>
# (c) 2017 Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
+from __future__ import annotations
DOCUMENTATION = """
name: ini
@@ -155,16 +154,20 @@ class LookupModule(LookupBase):
params = _parse_params(term, paramvals)
try:
updated_key = False
+ updated_options = False
for param in params:
if '=' in param:
name, value = param.split('=')
if name not in paramvals:
raise AnsibleLookupError('%s is not a valid option.' % name)
- paramvals[name] = value
+ self.set_option(name, value)
+ updated_options = True
elif key == term:
# only take first, this format never supported multiple keys inline
key = param
updated_key = True
+ if updated_options:
+ paramvals = self.get_options()
except ValueError as e:
# bad params passed
raise AnsibleLookupError("Could not use '%s' from '%s': %s" % (param, params, to_native(e)), orig_exc=e)
diff --git a/lib/ansible/plugins/lookup/inventory_hostnames.py b/lib/ansible/plugins/lookup/inventory_hostnames.py
index 4fa1d68..e9ba61b 100644
--- a/lib/ansible/plugins/lookup/inventory_hostnames.py
+++ b/lib/ansible/plugins/lookup/inventory_hostnames.py
@@ -3,8 +3,7 @@
# (c) 2017 Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
+from __future__ import annotations
DOCUMENTATION = """
name: inventory_hostnames
diff --git a/lib/ansible/plugins/lookup/items.py b/lib/ansible/plugins/lookup/items.py
index 162c1e7..058ba97 100644
--- a/lib/ansible/plugins/lookup/items.py
+++ b/lib/ansible/plugins/lookup/items.py
@@ -1,8 +1,7 @@
# (c) 2012, Michael DeHaan <michael.dehaan@gmail.com>
# (c) 2017 Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
+from __future__ import annotations
DOCUMENTATION = """
name: items
diff --git a/lib/ansible/plugins/lookup/lines.py b/lib/ansible/plugins/lookup/lines.py
index 6314e37..7b08acf 100644
--- a/lib/ansible/plugins/lookup/lines.py
+++ b/lib/ansible/plugins/lookup/lines.py
@@ -2,8 +2,7 @@
# (c) 2017 Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
+from __future__ import annotations
DOCUMENTATION = """
name: lines
diff --git a/lib/ansible/plugins/lookup/list.py b/lib/ansible/plugins/lookup/list.py
index 6c553ae..a953f68 100644
--- a/lib/ansible/plugins/lookup/list.py
+++ b/lib/ansible/plugins/lookup/list.py
@@ -1,10 +1,8 @@
# (c) 2012-17 Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
-# Make coding more python3-ish
-from __future__ import (absolute_import, division, print_function)
+from __future__ import annotations
-__metaclass__ = type
DOCUMENTATION = """
name: list
diff --git a/lib/ansible/plugins/lookup/nested.py b/lib/ansible/plugins/lookup/nested.py
index e768dba..097c2a4 100644
--- a/lib/ansible/plugins/lookup/nested.py
+++ b/lib/ansible/plugins/lookup/nested.py
@@ -1,8 +1,7 @@
# (c) 2012, Michael DeHaan <michael.dehaan@gmail.com>
# (c) 2017 Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
+from __future__ import annotations
DOCUMENTATION = """
name: nested
diff --git a/lib/ansible/plugins/lookup/password.py b/lib/ansible/plugins/lookup/password.py
index 1fe97f1..84894e2 100644
--- a/lib/ansible/plugins/lookup/password.py
+++ b/lib/ansible/plugins/lookup/password.py
@@ -3,8 +3,7 @@
# (c) 2013, Maykel Moya <mmoya@speedyrails.com>
# (c) 2017 Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
+from __future__ import annotations
DOCUMENTATION = """
name: password
@@ -332,29 +331,32 @@ class LookupModule(LookupBase):
if invalid_params:
raise AnsibleError('Unrecognized parameter(s) given to password lookup: %s' % ', '.join(invalid_params))
- # Set defaults
- params['length'] = int(params.get('length', self.get_option('length')))
- params['encrypt'] = params.get('encrypt', self.get_option('encrypt'))
- params['ident'] = params.get('ident', self.get_option('ident'))
- params['seed'] = params.get('seed', self.get_option('seed'))
+ # update options with what we got
+ if params:
+ self.set_options(direct=params)
- params['chars'] = params.get('chars', self.get_option('chars'))
- if params['chars'] and isinstance(params['chars'], string_types):
+ # chars still might need more
+ chars = params.get('chars', self.get_option('chars'))
+ if chars and isinstance(chars, string_types):
tmp_chars = []
- if u',,' in params['chars']:
+ if u',,' in chars:
tmp_chars.append(u',')
- tmp_chars.extend(c for c in params['chars'].replace(u',,', u',').split(u',') if c)
- params['chars'] = tmp_chars
+ tmp_chars.extend(c for c in chars.replace(u',,', u',').split(u',') if c)
+ self.set_option('chars', tmp_chars)
+
+ # return processed params
+ for field in VALID_PARAMS:
+ params[field] = self.get_option(field)
return relpath, params
def run(self, terms, variables, **kwargs):
ret = []
- self.set_options(var_options=variables, direct=kwargs)
-
for term in terms:
+ self.set_options(var_options=variables, direct=kwargs)
+
changed = None
relpath, params = self._parse_parameters(term)
path = self._loader.path_dwim(relpath)
diff --git a/lib/ansible/plugins/lookup/pipe.py b/lib/ansible/plugins/lookup/pipe.py
index 20e922b..0923f13 100644
--- a/lib/ansible/plugins/lookup/pipe.py
+++ b/lib/ansible/plugins/lookup/pipe.py
@@ -1,8 +1,7 @@
# (c) 2012, Daniel Hokka Zakrisson <daniel@hozac.com>
# (c) 2017 Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
+from __future__ import annotations
DOCUMENTATION = r"""
name: pipe
diff --git a/lib/ansible/plugins/lookup/random_choice.py b/lib/ansible/plugins/lookup/random_choice.py
index 93e6c2e..2e43d2e 100644
--- a/lib/ansible/plugins/lookup/random_choice.py
+++ b/lib/ansible/plugins/lookup/random_choice.py
@@ -1,8 +1,7 @@
# (c) 2013, Michael DeHaan <michael.dehaan@gmail.com>
# (c) 2017 Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
+from __future__ import annotations
DOCUMENTATION = """
name: random_choice
diff --git a/lib/ansible/plugins/lookup/sequence.py b/lib/ansible/plugins/lookup/sequence.py
index f4fda43..9efe7ce 100644
--- a/lib/ansible/plugins/lookup/sequence.py
+++ b/lib/ansible/plugins/lookup/sequence.py
@@ -1,8 +1,7 @@
# (c) 2013, Jayson Vantuyl <jayson@aggressive.ly>
# (c) 2012-17 Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
+from __future__ import annotations
DOCUMENTATION = """
name: sequence
@@ -20,21 +19,21 @@ DOCUMENTATION = """
options:
start:
description: number at which to start the sequence
- default: 0
+ default: 1
type: integer
end:
description: number at which to end the sequence, dont use this with count
type: integer
- default: 0
count:
description: number of elements in the sequence, this is not to be used with end
type: integer
- default: 0
stride:
description: increments between sequence numbers, the default is 1 unless the end is less than the start, then it is -1.
type: integer
+ default: 1
format:
description: return a string with the generated number formatted in
+ default: "%d"
"""
EXAMPLES = """
@@ -98,6 +97,7 @@ SHORTCUT = re_compile(
"(:(.+))?$", # Group 5, Group 6: Format String
IGNORECASE
)
+FIELDS = frozenset(('start', 'end', 'stride', 'count', 'format'))
class LookupModule(LookupBase):
@@ -139,30 +139,12 @@ class LookupModule(LookupBase):
calculating the number of entries in a sequence when a stride is specified.
"""
- def reset(self):
- """set sensible defaults"""
- self.start = 1
- self.count = None
- self.end = None
- self.stride = 1
- self.format = "%d"
-
def parse_kv_args(self, args):
"""parse key-value style arguments"""
- for arg in ["start", "end", "count", "stride"]:
- try:
- arg_raw = args.pop(arg, None)
- if arg_raw is None:
- continue
- arg_cooked = int(arg_raw, 0)
- setattr(self, arg, arg_cooked)
- except ValueError:
- raise AnsibleError(
- "can't parse %s=%s as integer"
- % (arg, arg_raw)
- )
- if 'format' in args:
- self.format = args.pop("format")
+ for arg in FIELDS:
+ value = args.pop(arg, None)
+ if value is not None:
+ self.set_option(arg, value)
if args:
raise AnsibleError(
"unrecognized arguments to with_sequence: %s"
@@ -177,33 +159,17 @@ class LookupModule(LookupBase):
dummy, start, end, dummy, stride, dummy, format = match.groups()
- if start is not None:
- try:
- start = int(start, 0)
- except ValueError:
- raise AnsibleError("can't parse start=%s as integer" % start)
- if end is not None:
- try:
- end = int(end, 0)
- except ValueError:
- raise AnsibleError("can't parse end=%s as integer" % end)
- if stride is not None:
- try:
- stride = int(stride, 0)
- except ValueError:
- raise AnsibleError("can't parse stride=%s as integer" % stride)
-
- if start is not None:
- self.start = start
- if end is not None:
- self.end = end
- if stride is not None:
- self.stride = stride
- if format is not None:
- self.format = format
+ for key in FIELDS:
+ value = locals().get(key, None)
+ if value is not None:
+ self.set_option(key, value)
return True
+ def set_fields(self):
+ for f in FIELDS:
+ setattr(self, f, self.get_option(f))
+
def sanity_check(self):
if self.count is None and self.end is None:
raise AnsibleError("must specify count or end in with_sequence")
@@ -246,7 +212,8 @@ class LookupModule(LookupBase):
for term in terms:
try:
- self.reset() # clear out things for this iteration
+ # set defaults/global
+ self.set_options(direct=kwargs)
try:
if not self.parse_simple_args(term):
self.parse_kv_args(parse_kv(term))
@@ -255,7 +222,9 @@ class LookupModule(LookupBase):
except Exception as e:
raise AnsibleError("unknown error parsing with_sequence arguments: %r. Error was: %s" % (term, e))
+ self.set_fields()
self.sanity_check()
+
if self.stride != 0:
results.extend(self.generate_sequence())
except AnsibleError:
diff --git a/lib/ansible/plugins/lookup/subelements.py b/lib/ansible/plugins/lookup/subelements.py
index f221652..e269be5 100644
--- a/lib/ansible/plugins/lookup/subelements.py
+++ b/lib/ansible/plugins/lookup/subelements.py
@@ -1,8 +1,7 @@
# (c) 2013, Serge van Ginderachter <serge@vanginderachter.be>
# (c) 2012-17 Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
+from __future__ import annotations
DOCUMENTATION = """
name: subelements
diff --git a/lib/ansible/plugins/lookup/template.py b/lib/ansible/plugins/lookup/template.py
index 358fa1d..b2508d0 100644
--- a/lib/ansible/plugins/lookup/template.py
+++ b/lib/ansible/plugins/lookup/template.py
@@ -2,8 +2,7 @@
# Copyright: (c) 2012-17, Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
+from __future__ import annotations
DOCUMENTATION = """
name: template
diff --git a/lib/ansible/plugins/lookup/together.py b/lib/ansible/plugins/lookup/together.py
index c990e06..0d0bfd9 100644
--- a/lib/ansible/plugins/lookup/together.py
+++ b/lib/ansible/plugins/lookup/together.py
@@ -1,8 +1,7 @@
# (c) 2013, Bradley Young <young.bradley@gmail.com>
# (c) 2012-17 Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
+from __future__ import annotations
DOCUMENTATION = """
name: together
diff --git a/lib/ansible/plugins/lookup/unvault.py b/lib/ansible/plugins/lookup/unvault.py
index d7f3cba..f2db18e 100644
--- a/lib/ansible/plugins/lookup/unvault.py
+++ b/lib/ansible/plugins/lookup/unvault.py
@@ -1,7 +1,6 @@
# (c) 2020 Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
+from __future__ import annotations
DOCUMENTATION = """
name: unvault
diff --git a/lib/ansible/plugins/lookup/url.py b/lib/ansible/plugins/lookup/url.py
index f5c93f2..05ebe6d 100644
--- a/lib/ansible/plugins/lookup/url.py
+++ b/lib/ansible/plugins/lookup/url.py
@@ -1,8 +1,7 @@
# (c) 2015, Brian Coca <bcoca@ansible.com>
# (c) 2012-17 Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
+from __future__ import annotations
DOCUMENTATION = """
name: url
@@ -88,7 +87,7 @@ options:
- section: url_lookup
key: force_basic_auth
follow_redirects:
- description: String of urllib2, all/yes, safe, none to determine how redirects are followed, see RedirectHandlerFactory for more information
+ description: String of urllib2, all/yes, safe, none to determine how redirects are followed
type: string
version_added: "2.10"
default: 'urllib2'
@@ -99,6 +98,13 @@ options:
ini:
- section: url_lookup
key: follow_redirects
+ choices:
+ all: Will follow all redirects.
+ none: Will not follow any redirects.
+ safe: Only redirects doing GET or HEAD requests will be followed.
+ urllib2: Defer to urllib2 behavior (As of writing this follows HTTP redirects).
+ 'no': (DEPRECATED, will be removed in the future version) alias of V(none).
+ 'yes': (DEPRECATED, will be removed in the future version) alias of V(all).
use_gssapi:
description:
- Use GSSAPI handler of requests
diff --git a/lib/ansible/plugins/lookup/varnames.py b/lib/ansible/plugins/lookup/varnames.py
index 4fd0153..2163ce7 100644
--- a/lib/ansible/plugins/lookup/varnames.py
+++ b/lib/ansible/plugins/lookup/varnames.py
@@ -1,7 +1,6 @@
# (c) 2017 Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
+from __future__ import annotations
DOCUMENTATION = """
name: varnames
diff --git a/lib/ansible/plugins/lookup/vars.py b/lib/ansible/plugins/lookup/vars.py
index dd5f763..14cac99 100644
--- a/lib/ansible/plugins/lookup/vars.py
+++ b/lib/ansible/plugins/lookup/vars.py
@@ -1,7 +1,6 @@
# (c) 2017 Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
+from __future__ import annotations
DOCUMENTATION = """
name: vars