mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Included support to AIX group of subsystems on service module (#33043)
* Included support to AIX group subsystems AIX systems has subsystems as services but also uses group subsystems. For example, spooler is a group subsystem to services qdaemon, writesrv, and lpd. This change enables the possibility to use also the group susbsystmes such as spooler, nfs, etc. When the service name is informed, first the module will check if the name is a subsystem, if not it will check if the name is a group subsystem and also it subsystems states. This change makes services more flexible with AIX systems. * Included test/legacy/aix_services.yml for tests As discussed on IRC ansible-devel channes, was include the legacy tests for further manual tests.
This commit is contained in:
parent
b52d7d56d9
commit
3ec469f904
2 changed files with 78 additions and 8 deletions
|
@ -68,6 +68,7 @@ options:
|
||||||
default: auto
|
default: auto
|
||||||
version_added: 2.2
|
version_added: 2.2
|
||||||
notes:
|
notes:
|
||||||
|
- For AIX group subsystem names can be used.
|
||||||
- For Windows targets, use the M(win_service) module instead.
|
- For Windows targets, use the M(win_service) module instead.
|
||||||
seealso:
|
seealso:
|
||||||
- module: win_service
|
- module: win_service
|
||||||
|
@ -1484,19 +1485,64 @@ class AIX(Service):
|
||||||
self.running = False
|
self.running = False
|
||||||
|
|
||||||
def get_aix_src_status(self):
|
def get_aix_src_status(self):
|
||||||
|
# Check subsystem status
|
||||||
rc, stdout, stderr = self.execute_command("%s -s %s" % (self.lssrc_cmd, self.name))
|
rc, stdout, stderr = self.execute_command("%s -s %s" % (self.lssrc_cmd, self.name))
|
||||||
|
if rc == 1:
|
||||||
|
# If check for subsystem is not ok, check if service name is a
|
||||||
|
# group subsystem
|
||||||
|
rc, stdout, stderr = self.execute_command("%s -g %s" % (self.lssrc_cmd, self.name))
|
||||||
|
if rc == 1:
|
||||||
|
if stderr:
|
||||||
|
self.module.fail_json(msg=stderr)
|
||||||
|
else:
|
||||||
|
self.module.fail_json(msg=stdout)
|
||||||
|
else:
|
||||||
|
# Check all subsystem status, if one subsystem is not active
|
||||||
|
# the group is considered not active.
|
||||||
|
lines = stdout.splitlines()
|
||||||
|
for state in lines[1:]:
|
||||||
|
if state.split()[-1].strip() != "active":
|
||||||
|
status = state.split()[-1].strip()
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
status = "active"
|
||||||
|
|
||||||
|
# status is one of: active, inoperative
|
||||||
|
return status
|
||||||
|
else:
|
||||||
|
lines = stdout.rstrip("\n").split("\n")
|
||||||
|
status = lines[-1].split(" ")[-1]
|
||||||
|
|
||||||
|
# status is one of: active, inoperative
|
||||||
|
return status
|
||||||
|
|
||||||
|
def service_control(self):
|
||||||
|
|
||||||
|
# Check if service name is a subsystem of a group subsystem
|
||||||
|
rc, stdout, stderr = self.execute_command("%s -a" % (self.lssrc_cmd))
|
||||||
if rc == 1:
|
if rc == 1:
|
||||||
if stderr:
|
if stderr:
|
||||||
self.module.fail_json(msg=stderr)
|
self.module.fail_json(msg=stderr)
|
||||||
else:
|
else:
|
||||||
self.module.fail_json(msg=stdout)
|
self.module.fail_json(msg=stdout)
|
||||||
|
else:
|
||||||
|
lines = stdout.splitlines()
|
||||||
|
subsystems = []
|
||||||
|
groups = []
|
||||||
|
for line in lines[1:]:
|
||||||
|
subsystem = line.split()[0].strip()
|
||||||
|
group = line.split()[1].strip()
|
||||||
|
subsystems.append(subsystem)
|
||||||
|
if group:
|
||||||
|
groups.append(group)
|
||||||
|
|
||||||
lines = stdout.rstrip("\n").split("\n")
|
# Define if service name parameter:
|
||||||
status = lines[-1].split(" ")[-1]
|
# -s subsystem or -g group subsystem
|
||||||
# status is one of: active, inoperative
|
if self.name in subsystems:
|
||||||
return status
|
srccmd_parameter = "-s"
|
||||||
|
elif self.name in groups:
|
||||||
|
srccmd_parameter = "-g"
|
||||||
|
|
||||||
def service_control(self):
|
|
||||||
if self.action == 'start':
|
if self.action == 'start':
|
||||||
srccmd = self.startsrc_cmd
|
srccmd = self.startsrc_cmd
|
||||||
elif self.action == 'stop':
|
elif self.action == 'stop':
|
||||||
|
@ -1504,13 +1550,13 @@ class AIX(Service):
|
||||||
elif self.action == 'reload':
|
elif self.action == 'reload':
|
||||||
srccmd = self.refresh_cmd
|
srccmd = self.refresh_cmd
|
||||||
elif self.action == 'restart':
|
elif self.action == 'restart':
|
||||||
self.execute_command("%s -s %s" % (self.stopsrc_cmd, self.name))
|
self.execute_command("%s %s %s" % (self.stopsrc_cmd, srccmd_parameter, self.name))
|
||||||
srccmd = self.startsrc_cmd
|
srccmd = self.startsrc_cmd
|
||||||
|
|
||||||
if self.arguments and self.action == 'start':
|
if self.arguments and self.action == 'start':
|
||||||
return self.execute_command("%s -a \"%s\" -s %s" % (srccmd, self.arguments, self.name))
|
return self.execute_command("%s -a \"%s\" %s %s" % (srccmd, self.arguments, srccmd_parameter, self.name))
|
||||||
else:
|
else:
|
||||||
return self.execute_command("%s -s %s" % (srccmd, self.name))
|
return self.execute_command("%s %s %s" % (srccmd, srccmd_parameter, self.name))
|
||||||
|
|
||||||
|
|
||||||
# ===========================================
|
# ===========================================
|
||||||
|
|
24
test/legacy/aix_services.yml
Normal file
24
test/legacy/aix_services.yml
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
---
|
||||||
|
- name: Services/Subsystems tests for AIX
|
||||||
|
hosts: localhost
|
||||||
|
connection: local
|
||||||
|
tasks:
|
||||||
|
- name: spooler shutdown
|
||||||
|
service:
|
||||||
|
name: spooler
|
||||||
|
state: started
|
||||||
|
|
||||||
|
- name: stopping sendmail
|
||||||
|
service:
|
||||||
|
name: sendmail
|
||||||
|
state: stopped
|
||||||
|
|
||||||
|
- name: starting sendmail
|
||||||
|
service:
|
||||||
|
name: sendmail
|
||||||
|
state: started
|
||||||
|
|
||||||
|
- name: starting an inexistent subsystem and group subsystem
|
||||||
|
service:
|
||||||
|
name: fakeservice
|
||||||
|
state: stopped
|
Loading…
Reference in a new issue