Link Here
|
|
|
1 |
From 872594b49a69a1f3795e0de3f7cf0194b6bdfd53 Mon Sep 17 00:00:00 2001 |
2 |
From: Michael Scherer <misc@redhat.com> |
3 |
Date: Sun, 23 Oct 2016 19:24:00 +0200 |
4 |
Subject: [PATCH] Make service work when the service is not present in rc.conf |
5 |
|
6 |
After installing a package from the ports collection on a |
7 |
fresh FreeBSD 11.0, Ansible was unable to enable it, failing with |
8 |
"unable to get current rcvar value". Debugging showed that sysrc |
9 |
didn't see the variable from /usr/local/etc/rc.d/myservice, but |
10 |
adding the value was working. |
11 |
|
12 |
So we will just fallback to the default value if we can't find it. |
13 |
--- |
14 |
system/service.py | 6 ++++-- |
15 |
1 file changed, 4 insertions(+), 2 deletions(-) |
16 |
|
17 |
diff --git system/service.py system/service.py |
18 |
index d216e68..c8781b1 100644 |
19 |
--- lib/ansible/modules/core/system/service.py |
20 |
+++ lib/ansible/modules/core/system/service.py |
21 |
@@ -988,7 +988,7 @@ def service_enable(self): |
22 |
# and hope for the best. |
23 |
for rcvar in rcvars: |
24 |
if '=' in rcvar: |
25 |
- self.rcconf_key = rcvar.split('=')[0] |
26 |
+ self.rcconf_key, default_rcconf_value = rcvar.split('=', 1) |
27 |
break |
28 |
|
29 |
if self.rcconf_key is None: |
30 |
@@ -997,8 +997,10 @@ def service_enable(self): |
31 |
if self.sysrc_cmd: # FreeBSD >= 9.2 |
32 |
|
33 |
rc, current_rcconf_value, stderr = self.execute_command("%s -n %s" % (self.sysrc_cmd, self.rcconf_key)) |
34 |
+ # it can happen that rcvar is not set (case of a system coming from the ports collection) |
35 |
+ # so we will fallback on the default |
36 |
if rc != 0: |
37 |
- self.module.fail_json(msg="unable to get current rcvar value", stdout=stdout, stderr=stderr) |
38 |
+ current_rcconf_value = default_rcconf_value |
39 |
|
40 |
if current_rcconf_value.strip().upper() != self.rcconf_value: |
41 |
|