diff --git a/changelogs/fragments/558-load_provider.yml b/changelogs/fragments/558-load_provider.yml new file mode 100644 index 000000000..b203911d3 --- /dev/null +++ b/changelogs/fragments/558-load_provider.yml @@ -0,0 +1,2 @@ +bugfixes: + - "Ensure that all connection plugin options that should be strings are actually strings (https://github.com/ansible-collections/ansible.netcommon/pull/549)." diff --git a/plugins/module_utils/network/common/utils.py b/plugins/module_utils/network/common/utils.py index 4644a0717..6f7a50b5d 100644 --- a/plugins/module_utils/network/common/utils.py +++ b/plugins/module_utils/network/common/utils.py @@ -468,12 +468,12 @@ def load_provider(spec, args): provider = args.get("provider") or {} for key, value in iteritems(spec): if key not in provider: - if "fallback" in value: + try: + # Get fallback if defined, and valid provider[key] = _fallback(value["fallback"]) - elif "default" in value: - provider[key] = value["default"] - else: - provider[key] = None + except (basic.AnsibleFallbackNotFound, KeyError): + # Get default if defined, otherwise set to None + provider[key] = value.get("default") if "authorize" in provider: # Coerce authorize to provider if a string has somehow snuck in. provider["authorize"] = boolean(provider["authorize"] or False) @@ -491,10 +491,8 @@ def _fallback(fallback): kwargs = item else: args = item - try: - return strategy(*args, **kwargs) - except basic.AnsibleFallbackNotFound: - pass + + return strategy(*args, **kwargs) def generate_dict(spec):