mirror of https://github.com/ansible/ansible.git
fixes #74225
Co-authored-by: Kim Nørring <github@norring.dk>
(cherry picked from commit b91749d671
)
pull/74312/head
parent
3aab644285
commit
a81386fa62
@ -0,0 +1,2 @@
|
|||||||
|
bugfixes:
|
||||||
|
- plugin config now allows list type options to have multiple valid choices (#74225).
|
@ -0,0 +1,51 @@
|
|||||||
|
# (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: bogus
|
||||||
|
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
|
||||||
|
test_list:
|
||||||
|
description: does nothihng, just for testing values
|
||||||
|
type: list
|
||||||
|
choices:
|
||||||
|
- Dan
|
||||||
|
- Yevgeni
|
||||||
|
- Carla
|
||||||
|
- Manuela
|
||||||
|
"""
|
||||||
|
|
||||||
|
EXAMPLES = """
|
||||||
|
- name: like some other plugins, this is mostly useless
|
||||||
|
debug: msg={{ q('bogus', [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)
|
||||||
|
dump = self.get_option('test_list')
|
||||||
|
|
||||||
|
return terms
|
@ -0,0 +1,17 @@
|
|||||||
|
- hosts: localhost
|
||||||
|
gather_facts: false
|
||||||
|
tasks:
|
||||||
|
- name: does nothing but an empty assign, should fail only if lookup gets invalid options
|
||||||
|
set_fact: whatever={{ lookup('bogus', 1, test_list=['Dan', 'Manuela']) }}
|
||||||
|
|
||||||
|
- name: now pass invalid option and fail!
|
||||||
|
set_fact: whatever={{ lookup('bogus', 1, test_list=['Dan', 'Manuela', 'Yoko']) }}
|
||||||
|
register: bad_input
|
||||||
|
ignore_errors: true
|
||||||
|
|
||||||
|
- name: ensure it fails as expected
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- bad_input is failed
|
||||||
|
- '"Invalid value " in bad_input.msg'
|
||||||
|
- '"valid values are:" in bad_input.msg'
|
Loading…
Reference in New Issue