diff --git a/changelogs/fragments/bsd_rcconf_string_replace.yaml b/changelogs/fragments/bsd_rcconf_string_replace.yaml new file mode 100644 index 00000000000..1bacce1a09e --- /dev/null +++ b/changelogs/fragments/bsd_rcconf_string_replace.yaml @@ -0,0 +1,2 @@ +bugfixes: +- service - Fix for the BSD rcconf code using a Python 2 specific string replace function diff --git a/lib/ansible/modules/service.py b/lib/ansible/modules/service.py index f4eb709735d..59cd7e8113f 100644 --- a/lib/ansible/modules/service.py +++ b/lib/ansible/modules/service.py @@ -135,7 +135,6 @@ import platform import re import select import shlex -import string import subprocess import tempfile import time @@ -419,7 +418,7 @@ class Service(object): # Write out the contents of the list into our temporary file. for rcline in new_rc_conf: - os.write(TMP_RCCONF, rcline) + os.write(TMP_RCCONF, rcline.encode()) # Close temporary file. os.close(TMP_RCCONF) @@ -1116,7 +1115,7 @@ class DragonFlyBsdService(FreeBsdService): if os.path.isfile(rcfile): self.rcconf_file = rcfile - self.rcconf_key = "%s" % string.replace(self.name, "-", "_") + self.rcconf_key = "%s" % self.name.replace("-", "_") return self.service_enable_rcconf() @@ -1274,7 +1273,7 @@ class NetBsdService(Service): """ This is the NetBSD Service manipulation class - it uses the /etc/rc.conf file for controlling services started at boot, check status and perform - direct service manipulation. Init scripts in /etc/rcd are used for + direct service manipulation. Init scripts in /etc/rc.d are used for controlling services (start/stop) as well as for controlling the current state. """ @@ -1304,7 +1303,7 @@ class NetBsdService(Service): if os.path.isfile(rcfile): self.rcconf_file = rcfile - self.rcconf_key = "%s" % string.replace(self.name, "-", "_") + self.rcconf_key = "%s" % self.name.replace("-", "_") return self.service_enable_rcconf()