Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import openbsd patches #74056

Merged
merged 5 commits into from Mar 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/openbsd-service.yml
@@ -0,0 +1,2 @@
minor_changes:
- service_facts - return service state information on OpenBSD.
2 changes: 2 additions & 0 deletions changelogs/fragments/openbsd-sysutil.yml
@@ -0,0 +1,2 @@
bugfixes:
- OpenBSD module_utils - update sysctl variable name
6 changes: 3 additions & 3 deletions lib/ansible/module_utils/facts/hardware/openbsd.py
Expand Up @@ -132,7 +132,7 @@ def get_uptime_facts(self):
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
Expand All @@ -143,8 +143,8 @@ def get_processor_facts(self):
# 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

Expand Down
53 changes: 49 additions & 4 deletions lib/ansible/modules/service_facts.py
Expand Up @@ -55,22 +55,22 @@
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
status:
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:
Expand Down Expand Up @@ -260,10 +260,55 @@ def gather_services(self):
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:
Expand Down