mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
* supervisorctl - bugfix + pythonification
* added changelog fragment
* rollback check on the binpath
(cherry picked from commit c8b2d7c1e5
)
Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
This commit is contained in:
parent
8a8e6c8058
commit
9bd3627796
2 changed files with 21 additions and 18 deletions
4
changelogs/fragments/3068-supervisorctl-bugfix.yaml
Normal file
4
changelogs/fragments/3068-supervisorctl-bugfix.yaml
Normal file
|
@ -0,0 +1,4 @@
|
|||
bugfixes:
|
||||
- supervisorctl - state ``signalled`` was not working (https://github.com/ansible-collections/community.general/pull/3068).
|
||||
minor_changes:
|
||||
- supervisorctl - using standard Ansible mechanism to validate ``signalled`` state required parameter (https://github.com/ansible-collections/community.general/pull/3068).
|
|
@ -101,16 +101,20 @@ from ansible.module_utils.basic import AnsibleModule, is_executable
|
|||
def main():
|
||||
arg_spec = dict(
|
||||
name=dict(type='str', required=True),
|
||||
config=dict(required=False, type='path'),
|
||||
server_url=dict(type='str', required=False),
|
||||
username=dict(type='str', required=False),
|
||||
password=dict(type='str', required=False, no_log=True),
|
||||
supervisorctl_path=dict(required=False, type='path'),
|
||||
config=dict(type='path'),
|
||||
server_url=dict(type='str'),
|
||||
username=dict(type='str'),
|
||||
password=dict(type='str', no_log=True),
|
||||
supervisorctl_path=dict(type='path'),
|
||||
state=dict(type='str', required=True, choices=['present', 'started', 'restarted', 'stopped', 'absent', 'signalled']),
|
||||
signal=dict(type='str', required=False)
|
||||
signal=dict(type='str'),
|
||||
)
|
||||
|
||||
module = AnsibleModule(argument_spec=arg_spec, supports_check_mode=True)
|
||||
module = AnsibleModule(
|
||||
argument_spec=arg_spec,
|
||||
supports_check_mode=True,
|
||||
required_if=[('state', 'signalled', ['signal'])],
|
||||
)
|
||||
|
||||
name = module.params['name']
|
||||
is_group = False
|
||||
|
@ -146,9 +150,6 @@ def main():
|
|||
if password:
|
||||
supervisorctl_args.extend(['-p', password])
|
||||
|
||||
if state == 'signalled' and not signal:
|
||||
module.fail_json(msg="State 'signalled' requires a 'signal' value")
|
||||
|
||||
def run_supervisorctl(cmd, name=None, **kwargs):
|
||||
args = list(supervisorctl_args) # copy the master args
|
||||
args.append(cmd)
|
||||
|
@ -231,26 +232,24 @@ def main():
|
|||
if module.check_mode:
|
||||
module.exit_json(changed=True)
|
||||
run_supervisorctl('reread', check_rc=True)
|
||||
rc, out, err = run_supervisorctl('add', name)
|
||||
dummy, out, dummy = run_supervisorctl('add', name)
|
||||
if '%s: added process group' % name in out:
|
||||
module.exit_json(changed=True, name=name, state=state)
|
||||
else:
|
||||
module.fail_json(msg=out, name=name, state=state)
|
||||
|
||||
# from this point onwards, if there are no matching processes, module cannot go on.
|
||||
if len(processes) == 0:
|
||||
module.fail_json(name=name, msg="ERROR (no such process)")
|
||||
|
||||
if state == 'started':
|
||||
if len(processes) == 0:
|
||||
module.fail_json(name=name, msg="ERROR (no such process)")
|
||||
take_action_on_processes(processes, lambda s: s not in ('RUNNING', 'STARTING'), 'start', 'started')
|
||||
|
||||
if state == 'stopped':
|
||||
if len(processes) == 0:
|
||||
module.fail_json(name=name, msg="ERROR (no such process)")
|
||||
take_action_on_processes(processes, lambda s: s in ('RUNNING', 'STARTING'), 'stop', 'stopped')
|
||||
|
||||
if state == 'signalled':
|
||||
if len(processes) == 0:
|
||||
module.fail_json(name=name, msg="ERROR (no such process)")
|
||||
take_action_on_processes(processes, lambda s: s in ('RUNNING'), "signal %s" % signal, 'signalled')
|
||||
take_action_on_processes(processes, lambda s: s in ('RUNNING',), "signal %s" % signal, 'signalled')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
Loading…
Reference in a new issue