summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbhijeet Kasurde <akasurde@redhat.com>2022-04-13 22:04:33 +0530
committerGitHub <noreply@github.com>2022-04-13 11:34:33 -0500
commit2ce5d99e83be7b7986c8e7d68175df58ea8d381b (patch)
treeb610572007af3886638c4a248fbb0dbaed46243d
parent8bbcfebd5c7e5efeb9c8dc173a3fa5ebceab3df5 (diff)
downloadansible-2ce5d99e83be7b7986c8e7d68175df58ea8d381b.tar.gz
[bp-2.12] hostname - fix TypeError in FileStrategy (#77365)
* Use file_get_content() to read the file containing the host name (cherry picked from commit d60efd97687803fd184ac53aa691bd4e0ec43170) Signed-off-by: Emmanuel Benoît <tseeker@nocternity.net> Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com> Co-authored-by: Emmanuel Benoît <tseeker@nocternity.net>
-rw-r--r--changelogs/fragments/77074-hostname-fix-typeerror-in-filestrategy.yml2
-rw-r--r--lib/ansible/modules/hostname.py4
2 files changed, 4 insertions, 2 deletions
diff --git a/changelogs/fragments/77074-hostname-fix-typeerror-in-filestrategy.yml b/changelogs/fragments/77074-hostname-fix-typeerror-in-filestrategy.yml
new file mode 100644
index 0000000000..d2e80a0ceb
--- /dev/null
+++ b/changelogs/fragments/77074-hostname-fix-typeerror-in-filestrategy.yml
@@ -0,0 +1,2 @@
+bugfixes:
+ - hostname - use ``file_get_content()`` to read the file containing the host name in the ``FileStrategy.get_permanent_hostname()`` method. This prevents a ``TypeError`` from being raised when the strategy is used (https://github.com/ansible/ansible/issues/77025).
diff --git a/lib/ansible/modules/hostname.py b/lib/ansible/modules/hostname.py
index fc908b5046..8410df2160 100644
--- a/lib/ansible/modules/hostname.py
+++ b/lib/ansible/modules/hostname.py
@@ -78,7 +78,7 @@ from ansible.module_utils.basic import (
)
from ansible.module_utils.common.sys_info import get_platform_subclass
from ansible.module_utils.facts.system.service_mgr import ServiceMgrFactCollector
-from ansible.module_utils.facts.utils import get_file_lines
+from ansible.module_utils.facts.utils import get_file_lines, get_file_content
from ansible.module_utils._text import to_native, to_text
from ansible.module_utils.six import PY3, text_type
@@ -257,7 +257,7 @@ class FileStrategy(BaseStrategy):
return ''
try:
- return get_file_lines(self.FILE)
+ return get_file_content(self.FILE, default='', strip=True)
except Exception as e:
self.module.fail_json(
msg="failed to read hostname: %s" % to_native(e),