Skip to content
This repository has been archived by the owner on Oct 30, 2018. It is now read-only.

Commit

Permalink
Make service work when the service is not present in rc.conf
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mscherer authored and bcoca committed Nov 4, 2016
1 parent 94d28fb commit 872594b
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions system/service.py
Expand Up @@ -988,7 +988,7 @@ def service_enable(self):
# 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:
Expand All @@ -997,8 +997,10 @@ def service_enable(self):
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:

Expand Down

0 comments on commit 872594b

Please sign in to comment.