Validate plugin option type 'dict' / 'dictionary' (#71928)
* Validate option type 'dict' / 'dictionary'. * Add changelog fragment. * Change type of 'environment' to list.
This commit is contained in:
parent
a077bca5d5
commit
8893a244b9
4 changed files with 13 additions and 7 deletions
2
changelogs/fragments/71928-ensure_type-dict.yml
Normal file
2
changelogs/fragments/71928-ensure_type-dict.yml
Normal file
|
@ -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.errors import AnsibleOptionsError, AnsibleError
|
||||
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.moves import configparser
|
||||
from ansible.module_utils.parsing.convert_bool import boolean
|
||||
|
@ -144,6 +144,10 @@ def ensure_type(value, value_type, origin=None):
|
|||
else:
|
||||
errmsg = 'pathlist'
|
||||
|
||||
elif value_type in ('dict', 'dictionary'):
|
||||
if not isinstance(value, Mapping):
|
||||
errmsg = 'dictionary'
|
||||
|
||||
elif value_type in ('str', 'string'):
|
||||
if isinstance(value, (string_types, AnsibleVaultEncryptedUnicode)):
|
||||
value = unquote(to_text(value, errors='surrogate_or_strict'))
|
||||
|
|
|
@ -56,10 +56,10 @@ options:
|
|||
vars:
|
||||
- name: ansible_async_dir
|
||||
environment:
|
||||
type: dict
|
||||
default: {}
|
||||
type: list
|
||||
default: [{}]
|
||||
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:
|
||||
type: list
|
||||
default: ['root', 'toor']
|
||||
|
|
|
@ -42,8 +42,8 @@ options:
|
|||
- 'no'
|
||||
environment:
|
||||
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.
|
||||
type: dict
|
||||
default: {}
|
||||
type: list
|
||||
default: [{}]
|
||||
"""
|
||||
|
|
Loading…
Reference in a new issue