mirror of https://github.com/ansible/ansible.git
parent
888fea69e5
commit
d2d1f01f9d
@ -0,0 +1,2 @@
|
||||
bugfixes:
|
||||
- config, ensure 'quoted' lists from ini or env do not take the quotes literally as part of the list item.
|
||||
@ -0,0 +1,66 @@
|
||||
# (c) 2021 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)
|
||||
|
||||
__metaclass__ = type
|
||||
|
||||
DOCUMENTATION = """
|
||||
name: types
|
||||
author: Ansible Core Team
|
||||
version_added: histerical
|
||||
short_description: returns what you gave it
|
||||
description:
|
||||
- this is mostly a noop
|
||||
options:
|
||||
_terms:
|
||||
description: stuff to pass through
|
||||
valid:
|
||||
description: does nothihng, just for testing values
|
||||
type: list
|
||||
ini:
|
||||
- section: list_values
|
||||
key: valid
|
||||
mustunquote:
|
||||
description: does nothihng, just for testing values
|
||||
type: list
|
||||
ini:
|
||||
- section: list_values
|
||||
key: mustunquote
|
||||
notvalid:
|
||||
description: does nothihng, just for testing values
|
||||
type: list
|
||||
ini:
|
||||
- section: list_values
|
||||
key: notvalid
|
||||
totallynotvalid:
|
||||
description: does nothihng, just for testing values
|
||||
type: list
|
||||
ini:
|
||||
- section: list_values
|
||||
key: totallynotvalid
|
||||
"""
|
||||
|
||||
EXAMPLES = """
|
||||
- name: like some other plugins, this is mostly useless
|
||||
debug: msg={{ q('types', [1,2,3])}}
|
||||
"""
|
||||
|
||||
RETURN = """
|
||||
_list:
|
||||
description: basically the same as you fed in
|
||||
type: list
|
||||
elements: raw
|
||||
"""
|
||||
|
||||
from ansible.plugins.lookup import LookupBase
|
||||
|
||||
|
||||
class LookupModule(LookupBase):
|
||||
|
||||
def run(self, terms, variables=None, **kwargs):
|
||||
|
||||
self.set_options(var_options=variables, direct=kwargs)
|
||||
|
||||
return terms
|
||||
@ -0,0 +1,8 @@
|
||||
[defaults]
|
||||
nothing = here
|
||||
|
||||
[list_values]
|
||||
valid = 1, 2, 3
|
||||
mustunquote = '1', '2', '3'
|
||||
notvalid = [1, 2, 3]
|
||||
totallynotvalid = ['1', '2', '3']
|
||||
@ -0,0 +1,25 @@
|
||||
- hosts: localhost
|
||||
gather_facts: false
|
||||
tasks:
|
||||
- name: ensures we got the list we expected
|
||||
block:
|
||||
- name: initialize plugin
|
||||
debug: msg={{ lookup('types', 'starting test') }}
|
||||
|
||||
- set_fact:
|
||||
valid: '{{ lookup("config", "valid", plugin_type="lookup", plugin_name="types") }}'
|
||||
mustunquote: '{{ lookup("config", "mustunquote", plugin_type="lookup", plugin_name="types") }}'
|
||||
notvalid: '{{ lookup("config", "notvalid", plugin_type="lookup", plugin_name="types") }}'
|
||||
totallynotvalid: '{{ lookup("config", "totallynotvalid", plugin_type="lookup", plugin_name="types") }}'
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- 'valid|type_debug == "list"'
|
||||
- 'mustunquote|type_debug == "list"'
|
||||
- 'notvalid|type_debug == "list"'
|
||||
- 'totallynotvalid|type_debug == "list"'
|
||||
- valid[0]|int == 1
|
||||
- mustunquote[0]|int == 1
|
||||
- "notvalid[0] == '[1'"
|
||||
# using 'and true' to avoid quote hell
|
||||
- totallynotvalid[0] == "['1'" and True
|
||||
Loading…
Reference in New Issue