mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
haproxy: Enable/disable health and agent checks (#689)
* Enable/disable health and agent checks Health and agent checks can cause a disabled service to re-enable itself. This adds "health" and "agent" options that will also enable or disable those checks, matching if the service is to be enabled/disabled. * Update plugins/modules/net_tools/haproxy.py Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/modules/net_tools/haproxy.py Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/modules/net_tools/haproxy.py Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/modules/net_tools/haproxy.py Co-authored-by: Felix Fontein <felix@fontein.de> * Changes to documentation and changelog. Changes for the haproxy documentation to resolve issues with the CI/CD, and adding a changelog fragment. * Update changelogs/fragments/689-haproxy_agent_and_health.yml Co-authored-by: Felix Fontein <felix@fontein.de> * Update changelogs/fragments/689-haproxy_agent_and_health.yml Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/modules/net_tools/haproxy.py Co-authored-by: Felix Fontein <felix@fontein.de> * Add an example of health/agent disable. * Update plugins/modules/net_tools/haproxy.py Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru> Co-authored-by: Felix Fontein <felix@fontein.de> Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>
This commit is contained in:
parent
b29af922eb
commit
848d63fa38
2 changed files with 40 additions and 1 deletions
7
changelogs/fragments/689-haproxy_agent_and_health.yml
Normal file
7
changelogs/fragments/689-haproxy_agent_and_health.yml
Normal file
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
minor_changes:
|
||||
- haproxy - add options to dis/enable health and agent checks. When health
|
||||
and agent checks are enabled for a service, a disabled service will
|
||||
re-enable itself automatically. These options also change the state of
|
||||
the agent checks to match the requested state for the backend
|
||||
(https://github.com/ansible-collections/community.general/issues/684).
|
|
@ -62,6 +62,18 @@ options:
|
|||
type: str
|
||||
required: true
|
||||
choices: [ disabled, drain, enabled ]
|
||||
agent:
|
||||
description:
|
||||
- Disable/enable agent checks (depending on I(state) value).
|
||||
type: bool
|
||||
default: no
|
||||
version_added: 1.0.0
|
||||
health:
|
||||
description:
|
||||
- Disable/enable health checks (depending on I(state) value).
|
||||
type: bool
|
||||
default: no
|
||||
version_added: "1.0.0"
|
||||
fail_on_not_found:
|
||||
description:
|
||||
- Fail whenever trying to enable/disable a backend host that does not exist
|
||||
|
@ -100,6 +112,13 @@ EXAMPLES = r'''
|
|||
host: '{{ inventory_hostname }}'
|
||||
backend: www
|
||||
|
||||
- name: Disable server in 'www' backend pool, also stop health/agent checks
|
||||
community.general.haproxy:
|
||||
state: disabled
|
||||
host: '{{ inventory_hostname }}'
|
||||
health: yes
|
||||
agent: yes
|
||||
|
||||
- name: Disable server without backend pool name (apply to all available backend pool)
|
||||
community.general.haproxy:
|
||||
state: disabled
|
||||
|
@ -228,6 +247,8 @@ class HAProxy(object):
|
|||
self.socket = self.module.params['socket']
|
||||
self.shutdown_sessions = self.module.params['shutdown_sessions']
|
||||
self.fail_on_not_found = self.module.params['fail_on_not_found']
|
||||
self.agent = self.module.params['agent']
|
||||
self.health = self.module.params['health']
|
||||
self.wait = self.module.params['wait']
|
||||
self.wait_retries = self.module.params['wait_retries']
|
||||
self.wait_interval = self.module.params['wait_interval']
|
||||
|
@ -360,6 +381,10 @@ class HAProxy(object):
|
|||
set the weight for haproxy backend server when provides.
|
||||
"""
|
||||
cmd = "get weight $pxname/$svname; enable server $pxname/$svname"
|
||||
if self.agent:
|
||||
cmd += "; enable agent $pxname/$svname"
|
||||
if self.health:
|
||||
cmd += "; enable health $pxname/$svname"
|
||||
if weight:
|
||||
cmd += "; set weight $pxname/$svname %s" % weight
|
||||
self.execute_for_backends(cmd, backend, host, 'UP')
|
||||
|
@ -370,7 +395,12 @@ class HAProxy(object):
|
|||
performed on the server until it leaves maintenance,
|
||||
also it shutdown sessions while disabling backend host server.
|
||||
"""
|
||||
cmd = "get weight $pxname/$svname; disable server $pxname/$svname"
|
||||
cmd = "get weight $pxname/$svname"
|
||||
if self.agent:
|
||||
cmd += "; disable agent $pxname/$svname"
|
||||
if self.health:
|
||||
cmd += "; disable health $pxname/$svname"
|
||||
cmd += "; disable server $pxname/$svname"
|
||||
if shutdown_sessions:
|
||||
cmd += "; shutdown sessions server $pxname/$svname"
|
||||
self.execute_for_backends(cmd, backend, host, 'MAINT')
|
||||
|
@ -428,6 +458,8 @@ def main():
|
|||
socket=dict(type='path', default=DEFAULT_SOCKET_LOCATION),
|
||||
shutdown_sessions=dict(type='bool', default=False),
|
||||
fail_on_not_found=dict(type='bool', default=False),
|
||||
health=dict(type='bool', default=False),
|
||||
agent=dict(type='bool', default=False),
|
||||
wait=dict(type='bool', default=False),
|
||||
wait_retries=dict(type='int', default=WAIT_RETRIES),
|
||||
wait_interval=dict(type='int', default=WAIT_INTERVAL),
|
||||
|
|
Loading…
Reference in a new issue