diff --git a/changelogs/fragments/71928-ensure_type-dict.yml b/changelogs/fragments/71928-ensure_type-dict.yml new file mode 100644 index 00000000000..c131d6b5f38 --- /dev/null +++ b/changelogs/fragments/71928-ensure_type-dict.yml @@ -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)." diff --git a/lib/ansible/config/manager.py b/lib/ansible/config/manager.py index 5cd87acfc94..e57bbc5ace4 100644 --- a/lib/ansible/config/manager.py +++ b/lib/ansible/config/manager.py @@ -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')) diff --git a/lib/ansible/plugins/doc_fragments/shell_common.py b/lib/ansible/plugins/doc_fragments/shell_common.py index 27f93c5bdbe..5f43d5f8538 100644 --- a/lib/ansible/plugins/doc_fragments/shell_common.py +++ b/lib/ansible/plugins/doc_fragments/shell_common.py @@ -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'] diff --git a/lib/ansible/plugins/doc_fragments/shell_windows.py b/lib/ansible/plugins/doc_fragments/shell_windows.py index d6d4d7c59c0..ee43f7ca72f 100644 --- a/lib/ansible/plugins/doc_fragments/shell_windows.py +++ b/lib/ansible/plugins/doc_fragments/shell_windows.py @@ -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: [{}] """