From 25123eafc7d1fad9f77ed12b8c97e4736fd6dfd9 Mon Sep 17 00:00:00 2001 From: Grzegorz Grasza Date: Wed, 17 Jun 2020 19:45:37 +0200 Subject: [PATCH] Fix the behavior of ipa modules in case IPA_HOST is empty (#241) * Fix the behavior of ipa modules in case IPA_HOST is empty The expected behavior, when the env is empty, is to fallback on DNS. Without this fix, if IPA_HOST is empty, there are different errors, depending on urllib version, which additionally confuses the user. Example errors: * host_find: Request failed: * Failed to connect to None at port 443: [Errno 111] Connection refused", "status": -1, "url": "https:///ipa/session/json * Add a changelog fragment for IPA_HOST fix * Update changelogs/fragments/241-fix-ipa-modules-when-ipa_host-empty.yml Co-authored-by: Sandra McCann Co-authored-by: John R Barker Co-authored-by: Sandra McCann --- .../fragments/241-fix-ipa-modules-when-ipa_host-empty.yml | 2 ++ plugins/module_utils/ipa.py | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/241-fix-ipa-modules-when-ipa_host-empty.yml diff --git a/changelogs/fragments/241-fix-ipa-modules-when-ipa_host-empty.yml b/changelogs/fragments/241-fix-ipa-modules-when-ipa_host-empty.yml new file mode 100644 index 0000000000..94e8f975fb --- /dev/null +++ b/changelogs/fragments/241-fix-ipa-modules-when-ipa_host-empty.yml @@ -0,0 +1,2 @@ +bugfixes: + - ipa modules - fix error when IPA_HOST is empty and fallback on DNS (https://github.com/ansible-collections/community.general/pull/241) diff --git a/plugins/module_utils/ipa.py b/plugins/module_utils/ipa.py index e6f959eda1..73e26a190c 100644 --- a/plugins/module_utils/ipa.py +++ b/plugins/module_utils/ipa.py @@ -43,7 +43,9 @@ from ansible.module_utils.basic import env_fallback, AnsibleFallbackNotFound def _env_then_dns_fallback(*args, **kwargs): ''' Load value from environment or DNS in that order''' try: - return env_fallback(*args, **kwargs) + result = env_fallback(*args, **kwargs) + if result == '': + raise AnsibleFallbackNotFound except AnsibleFallbackNotFound: # If no host was given, we try to guess it from IPA. # The ipa-ca entry is a standard entry that IPA will have set for