summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Scherer <misc@redhat.com>2016-10-23 19:24:00 +0200
committerBrian Coca <brian.coca+git@gmail.com>2016-11-08 15:38:40 -0500
commit72b2386ec8db1cbd472d40eb6e8bd5c4ca5b17ae (patch)
treef68dc69963140e09426fcf1046c9f3f2b1e1c251
parent115501abb14c22b5223e7ffc88fcce31a11f48c4 (diff)
downloadansible-modules-core-72b2386ec8db1cbd472d40eb6e8bd5c4ca5b17ae.tar.gz
Make service work when the service is not present in rc.conf
After installing a package from the ports collection on a fresh FreeBSD 11.0, Ansible was unable to enable it, failing with "unable to get current rcvar value". Debugging showed that sysrc didn't see the variable from /usr/local/etc/rc.d/myservice, but adding the value was working. So we will just fallback to the default value if we can't find it. (cherry picked from commit 872594b49a69a1f3795e0de3f7cf0194b6bdfd53)
-rw-r--r--system/service.py6
1 files changed, 4 insertions, 2 deletions
diff --git a/system/service.py b/system/service.py
index d216e683..c8781b1c 100644
--- a/system/service.py
+++ b/system/service.py
@@ -988,7 +988,7 @@ class FreeBsdService(Service):
# and hope for the best.
for rcvar in rcvars:
if '=' in rcvar:
- self.rcconf_key = rcvar.split('=')[0]
+ self.rcconf_key, default_rcconf_value = rcvar.split('=', 1)
break
if self.rcconf_key is None:
@@ -997,8 +997,10 @@ class FreeBsdService(Service):
if self.sysrc_cmd: # FreeBSD >= 9.2
rc, current_rcconf_value, stderr = self.execute_command("%s -n %s" % (self.sysrc_cmd, self.rcconf_key))
+ # it can happen that rcvar is not set (case of a system coming from the ports collection)
+ # so we will fallback on the default
if rc != 0:
- self.module.fail_json(msg="unable to get current rcvar value", stdout=stdout, stderr=stderr)
+ current_rcconf_value = default_rcconf_value
if current_rcconf_value.strip().upper() != self.rcconf_value: