summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchemsaf3 <81536662+chemsaf3@users.noreply.github.com>2021-03-30 16:17:40 +0000
committerGitHub <noreply@github.com>2021-03-30 12:17:40 -0400
commit381bd1a575ff830cbbe397379b80d1a95683733e (patch)
tree4fdc88ed044691da21ae49b4b842e64853261210
parent6b33864a2cfd2b702a7372d7a68fdc247b4f31a7 (diff)
downloadansible-381bd1a575ff830cbbe397379b80d1a95683733e.tar.gz
import openbsd patches (#74056)
* add openbsd service info * Create openbsd-service.yml * Update var name
-rw-r--r--changelogs/fragments/openbsd-service.yml2
-rw-r--r--changelogs/fragments/openbsd-sysutil.yml2
-rw-r--r--lib/ansible/module_utils/facts/hardware/openbsd.py6
-rw-r--r--lib/ansible/modules/service_facts.py53
4 files changed, 56 insertions, 7 deletions
diff --git a/changelogs/fragments/openbsd-service.yml b/changelogs/fragments/openbsd-service.yml
new file mode 100644
index 0000000000..1338bce619
--- /dev/null
+++ b/changelogs/fragments/openbsd-service.yml
@@ -0,0 +1,2 @@
+minor_changes:
+ - service_facts - return service state information on OpenBSD.
diff --git a/changelogs/fragments/openbsd-sysutil.yml b/changelogs/fragments/openbsd-sysutil.yml
new file mode 100644
index 0000000000..8a02700a60
--- /dev/null
+++ b/changelogs/fragments/openbsd-sysutil.yml
@@ -0,0 +1,2 @@
+bugfixes:
+ - OpenBSD module_utils - update sysctl variable name
diff --git a/lib/ansible/module_utils/facts/hardware/openbsd.py b/lib/ansible/module_utils/facts/hardware/openbsd.py
index 563216e411..3bcf8ce41c 100644
--- a/lib/ansible/module_utils/facts/hardware/openbsd.py
+++ b/lib/ansible/module_utils/facts/hardware/openbsd.py
@@ -132,7 +132,7 @@ class OpenBSDHardware(Hardware):
def get_processor_facts(self):
cpu_facts = {}
processor = []
- for i in range(int(self.sysctl['hw.ncpu'])):
+ for i in range(int(self.sysctl['hw.ncpuonline'])):
processor.append(self.sysctl['hw.model'])
cpu_facts['processor'] = processor
@@ -143,8 +143,8 @@ class OpenBSDHardware(Hardware):
# dmesg, however even those have proven to be unreliable.
# So take a shortcut and report the logical number of processors in
# 'processor_count' and 'processor_cores' and leave it at that.
- cpu_facts['processor_count'] = self.sysctl['hw.ncpu']
- cpu_facts['processor_cores'] = self.sysctl['hw.ncpu']
+ cpu_facts['processor_count'] = self.sysctl['hw.ncpuonline']
+ cpu_facts['processor_cores'] = self.sysctl['hw.ncpuonline']
return cpu_facts
diff --git a/lib/ansible/modules/service_facts.py b/lib/ansible/modules/service_facts.py
index 6440e33b3f..cec49324d5 100644
--- a/lib/ansible/modules/service_facts.py
+++ b/lib/ansible/modules/service_facts.py
@@ -55,14 +55,14 @@ ansible_facts:
source:
description:
- Init system of the service.
- - One of C(systemd), C(sysv), C(upstart), C(src).
+ - One of C(rcctl), C(systemd), C(sysv), C(upstart), C(src).
returned: always
type: str
sample: sysv
state:
description:
- State of the service.
- - Either C(running), C(stopped), or C(unknown).
+ - Either C(failed), C(running), C(stopped), or C(unknown).
returned: always
type: str
sample: running
@@ -70,7 +70,7 @@ ansible_facts:
description:
- State of the service.
- Either C(enabled), C(disabled), C(static), C(indirect) or C(unknown).
- returned: systemd systems or RedHat/SUSE flavored sysvinit/upstart
+ returned: systemd systems or RedHat/SUSE flavored sysvinit/upstart or OpenBSD
type: str
sample: enabled
name:
@@ -260,10 +260,55 @@ class AIXScanService(BaseService):
return services
+class OpenBSDScanService(BaseService):
+ def query_rcctl(self, cmd):
+ svcs = []
+
+ rc, stdout, stderr = self.module.run_command("%s ls %s" % (self.rcctl_path, cmd))
+ if 'needs root privileges' in stderr.lower():
+ self.incomplete_warning = True
+ return []
+
+ for svc in stdout.split('\n'):
+ if svc == '':
+ continue
+ else:
+ svcs.append(svc)
+
+ return svcs
+
+ def gather_services(self):
+ services = {}
+ self.rcctl_path = self.module.get_bin_path("rcctl")
+ if self.rcctl_path is None:
+ return None
+
+ for svc in self.query_rcctl('all'):
+ services[svc] = {'name': svc, 'source': 'rcctl'}
+
+ for svc in self.query_rcctl('on'):
+ services[svc].update({'status': 'enabled'})
+
+ for svc in self.query_rcctl('started'):
+ services[svc].update({'state': 'running'})
+
+ # Based on the list of services that are enabled, determine which are disabled
+ [services[svc].update({'status': 'disabled'}) for svc in services if services[svc].get('status') is None]
+
+ # and do the same for those are aren't running
+ [services[svc].update({'state': 'stopped'}) for svc in services if services[svc].get('state') is None]
+
+ # Override the state for services which are marked as 'failed'
+ for svc in self.query_rcctl('failed'):
+ services[svc].update({'state': 'failed'})
+
+ return services
+
+
def main():
module = AnsibleModule(argument_spec=dict(), supports_check_mode=True)
module.run_command_environ_update = dict(LANG="C", LC_ALL="C")
- service_modules = (ServiceScanService, SystemctlScanService, AIXScanService)
+ service_modules = (ServiceScanService, SystemctlScanService, AIXScanService, OpenBSDScanService)
all_services = {}
incomplete_warning = False
for svc_module in service_modules: