mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
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.
This commit is contained in:
parent
66b0a1ef2d
commit
338a8c8632
1 changed files with 5 additions and 4 deletions
|
@ -49,6 +49,7 @@ from distutils.version import LooseVersion
|
||||||
# import module snippets
|
# import module snippets
|
||||||
from ansible.module_utils.basic import *
|
from ansible.module_utils.basic import *
|
||||||
from ansible.module_utils.facts import *
|
from ansible.module_utils.facts import *
|
||||||
|
from ansible.module_utils._text import to_bytes, to_native
|
||||||
|
|
||||||
|
|
||||||
class UnimplementedStrategy(object):
|
class UnimplementedStrategy(object):
|
||||||
|
@ -135,7 +136,7 @@ class GenericStrategy(object):
|
||||||
if rc != 0:
|
if rc != 0:
|
||||||
self.module.fail_json(msg="Command failed rc=%d, out=%s, err=%s" %
|
self.module.fail_json(msg="Command failed rc=%d, out=%s, err=%s" %
|
||||||
(rc, out, err))
|
(rc, out, err))
|
||||||
return out.strip()
|
return to_native(out).strip()
|
||||||
|
|
||||||
def set_current_hostname(self, name):
|
def set_current_hostname(self, name):
|
||||||
cmd = [self.hostname_cmd, name]
|
cmd = [self.hostname_cmd, name]
|
||||||
|
@ -297,7 +298,7 @@ class SystemdStrategy(GenericStrategy):
|
||||||
if rc != 0:
|
if rc != 0:
|
||||||
self.module.fail_json(msg="Command failed rc=%d, out=%s, err=%s" %
|
self.module.fail_json(msg="Command failed rc=%d, out=%s, err=%s" %
|
||||||
(rc, out, err))
|
(rc, out, err))
|
||||||
return out.strip()
|
return to_native(out).strip()
|
||||||
|
|
||||||
def set_current_hostname(self, name):
|
def set_current_hostname(self, name):
|
||||||
if len(name) > 64:
|
if len(name) > 64:
|
||||||
|
@ -314,7 +315,7 @@ class SystemdStrategy(GenericStrategy):
|
||||||
if rc != 0:
|
if rc != 0:
|
||||||
self.module.fail_json(msg="Command failed rc=%d, out=%s, err=%s" %
|
self.module.fail_json(msg="Command failed rc=%d, out=%s, err=%s" %
|
||||||
(rc, out, err))
|
(rc, out, err))
|
||||||
return out.strip()
|
return to_native(out).strip()
|
||||||
|
|
||||||
def set_permanent_hostname(self, name):
|
def set_permanent_hostname(self, name):
|
||||||
if len(name) > 64:
|
if len(name) > 64:
|
||||||
|
@ -442,7 +443,7 @@ class SolarisStrategy(GenericStrategy):
|
||||||
if rc != 0:
|
if rc != 0:
|
||||||
self.module.fail_json(msg="Command failed rc=%d, out=%s, err=%s" %
|
self.module.fail_json(msg="Command failed rc=%d, out=%s, err=%s" %
|
||||||
(rc, out, err))
|
(rc, out, err))
|
||||||
return out.strip()
|
return to_native(out).strip()
|
||||||
|
|
||||||
def set_permanent_hostname(self, name):
|
def set_permanent_hostname(self, name):
|
||||||
cmd = [self.hostname_cmd, name]
|
cmd = [self.hostname_cmd, name]
|
||||||
|
|
Loading…
Reference in a new issue