1
0
Fork 0
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:
Sean Reifschneider 2020-07-29 15:39:48 -06:00 committed by GitHub
parent b29af922eb
commit 848d63fa38
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 1 deletions

View 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).

View file

@ -62,6 +62,18 @@ options:
type: str type: str
required: true required: true
choices: [ disabled, drain, enabled ] 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: fail_on_not_found:
description: description:
- Fail whenever trying to enable/disable a backend host that does not exist - Fail whenever trying to enable/disable a backend host that does not exist
@ -100,6 +112,13 @@ EXAMPLES = r'''
host: '{{ inventory_hostname }}' host: '{{ inventory_hostname }}'
backend: www 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) - name: Disable server without backend pool name (apply to all available backend pool)
community.general.haproxy: community.general.haproxy:
state: disabled state: disabled
@ -228,6 +247,8 @@ class HAProxy(object):
self.socket = self.module.params['socket'] self.socket = self.module.params['socket']
self.shutdown_sessions = self.module.params['shutdown_sessions'] self.shutdown_sessions = self.module.params['shutdown_sessions']
self.fail_on_not_found = self.module.params['fail_on_not_found'] 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 = self.module.params['wait']
self.wait_retries = self.module.params['wait_retries'] self.wait_retries = self.module.params['wait_retries']
self.wait_interval = self.module.params['wait_interval'] self.wait_interval = self.module.params['wait_interval']
@ -360,6 +381,10 @@ class HAProxy(object):
set the weight for haproxy backend server when provides. set the weight for haproxy backend server when provides.
""" """
cmd = "get weight $pxname/$svname; enable server $pxname/$svname" 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: if weight:
cmd += "; set weight $pxname/$svname %s" % weight cmd += "; set weight $pxname/$svname %s" % weight
self.execute_for_backends(cmd, backend, host, 'UP') self.execute_for_backends(cmd, backend, host, 'UP')
@ -370,7 +395,12 @@ class HAProxy(object):
performed on the server until it leaves maintenance, performed on the server until it leaves maintenance,
also it shutdown sessions while disabling backend host server. 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: if shutdown_sessions:
cmd += "; shutdown sessions server $pxname/$svname" cmd += "; shutdown sessions server $pxname/$svname"
self.execute_for_backends(cmd, backend, host, 'MAINT') self.execute_for_backends(cmd, backend, host, 'MAINT')
@ -428,6 +458,8 @@ def main():
socket=dict(type='path', default=DEFAULT_SOCKET_LOCATION), socket=dict(type='path', default=DEFAULT_SOCKET_LOCATION),
shutdown_sessions=dict(type='bool', default=False), shutdown_sessions=dict(type='bool', default=False),
fail_on_not_found=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=dict(type='bool', default=False),
wait_retries=dict(type='int', default=WAIT_RETRIES), wait_retries=dict(type='int', default=WAIT_RETRIES),
wait_interval=dict(type='int', default=WAIT_INTERVAL), wait_interval=dict(type='int', default=WAIT_INTERVAL),