From 338a8c8632f7c8b140638bc18ffedb560f39cb48 Mon Sep 17 00:00:00 2001 From: Michael Scherer Date: Sat, 27 Aug 2016 15:53:13 +0200 Subject: [PATCH] Convert command output to native string (#4559) Without it, the module always return changed on python3, which is harmless but add noise and can have some side effects. --- lib/ansible/modules/system/hostname.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/ansible/modules/system/hostname.py b/lib/ansible/modules/system/hostname.py index 5e98d5bdb2..d16b1ccca2 100644 --- a/lib/ansible/modules/system/hostname.py +++ b/lib/ansible/modules/system/hostname.py @@ -49,6 +49,7 @@ from distutils.version import LooseVersion # import module snippets from ansible.module_utils.basic import * from ansible.module_utils.facts import * +from ansible.module_utils._text import to_bytes, to_native class UnimplementedStrategy(object): @@ -135,7 +136,7 @@ class GenericStrategy(object): if rc != 0: self.module.fail_json(msg="Command failed rc=%d, out=%s, err=%s" % (rc, out, err)) - return out.strip() + return to_native(out).strip() def set_current_hostname(self, name): cmd = [self.hostname_cmd, name] @@ -297,7 +298,7 @@ class SystemdStrategy(GenericStrategy): if rc != 0: self.module.fail_json(msg="Command failed rc=%d, out=%s, err=%s" % (rc, out, err)) - return out.strip() + return to_native(out).strip() def set_current_hostname(self, name): if len(name) > 64: @@ -314,7 +315,7 @@ class SystemdStrategy(GenericStrategy): if rc != 0: self.module.fail_json(msg="Command failed rc=%d, out=%s, err=%s" % (rc, out, err)) - return out.strip() + return to_native(out).strip() def set_permanent_hostname(self, name): if len(name) > 64: @@ -442,7 +443,7 @@ class SolarisStrategy(GenericStrategy): if rc != 0: self.module.fail_json(msg="Command failed rc=%d, out=%s, err=%s" % (rc, out, err)) - return out.strip() + return to_native(out).strip() def set_permanent_hostname(self, name): cmd = [self.hostname_cmd, name]