Validate plugin option type 'dict' / 'dictionary' (#71928)

* Validate option type 'dict' / 'dictionary'.

* Add changelog fragment.

* Change type of 'environment' to list.
pull/72046/head
Felix Fontein 4 years ago committed by GitHub
parent a077bca5d5
commit 8893a244b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,2 @@
minor_changes:
- "plugin option validation - now the option type ``dict``/``dictionary`` is also validated by the config manager (https://github.com/ansible/ansible/pull/71928)."

@ -24,7 +24,7 @@ except ImportError:
from ansible.config.data import ConfigData from ansible.config.data import ConfigData
from ansible.errors import AnsibleOptionsError, AnsibleError from ansible.errors import AnsibleOptionsError, AnsibleError
from ansible.module_utils._text import to_text, to_bytes, to_native from ansible.module_utils._text import to_text, to_bytes, to_native
from ansible.module_utils.common._collections_compat import Sequence from ansible.module_utils.common._collections_compat import Mapping, Sequence
from ansible.module_utils.six import PY3, string_types from ansible.module_utils.six import PY3, string_types
from ansible.module_utils.six.moves import configparser from ansible.module_utils.six.moves import configparser
from ansible.module_utils.parsing.convert_bool import boolean from ansible.module_utils.parsing.convert_bool import boolean
@ -144,6 +144,10 @@ def ensure_type(value, value_type, origin=None):
else: else:
errmsg = 'pathlist' errmsg = 'pathlist'
elif value_type in ('dict', 'dictionary'):
if not isinstance(value, Mapping):
errmsg = 'dictionary'
elif value_type in ('str', 'string'): elif value_type in ('str', 'string'):
if isinstance(value, (string_types, AnsibleVaultEncryptedUnicode)): if isinstance(value, (string_types, AnsibleVaultEncryptedUnicode)):
value = unquote(to_text(value, errors='surrogate_or_strict')) value = unquote(to_text(value, errors='surrogate_or_strict'))

@ -56,10 +56,10 @@ options:
vars: vars:
- name: ansible_async_dir - name: ansible_async_dir
environment: environment:
type: dict type: list
default: {} default: [{}]
description: description:
- dictionary of environment variables and their values to use when executing commands. - List of dictionaries of environment variables and their values to use when executing commands.
admin_users: admin_users:
type: list type: list
default: ['root', 'toor'] default: ['root', 'toor']

@ -42,8 +42,8 @@ options:
- 'no' - 'no'
environment: environment:
description: description:
- Dictionary of environment variables and their values to use when - List of dictionaries of environment variables and their values to use when
executing commands. executing commands.
type: dict type: list
default: {} default: [{}]
""" """

Loading…
Cancel
Save