From d60efd97687803fd184ac53aa691bd4e0ec43170 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Beno=C3=AEt?= Date: Thu, 24 Feb 2022 20:05:52 +0100 Subject: [PATCH] hostname module - fix TypeError in FileStrategy (#77025) (#77074) * Use file_get_content() to read the file containing the host name --- .../fragments/77074-hostname-fix-typeerror-in-filestrategy.yml | 2 ++ lib/ansible/modules/hostname.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/77074-hostname-fix-typeerror-in-filestrategy.yml 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 00000000000..d2e80a0cebe --- /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 5af1c712589..cf24ec4b117 100644 --- a/lib/ansible/modules/hostname.py +++ b/lib/ansible/modules/hostname.py @@ -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),