haproxy – Enable, disable, and set weights for HAProxy backend servers using socket commands¶
Parameters¶
Notes¶
Note
Enable, disable and drain commands are restricted and can only be issued on sockets configured for level ‘admin’. For example, you can add the line ‘stats socket /var/run/haproxy.sock level admin’ to the general section of haproxy.cfg. See http://haproxy.1wt.eu/download/1.5/doc/configuration.txt.
Depends on netcat (nc) being available; you need to install the appropriate package for your operating system before this module can be used.
Examples¶
- name: Disable server in 'www' backend pool
haproxy:
state: disabled
host: '{{ inventory_hostname }}'
backend: www
- name: Disable server without backend pool name (apply to all available backend pool)
haproxy:
state: disabled
host: '{{ inventory_hostname }}'
- name: Disable server, provide socket file
haproxy:
state: disabled
host: '{{ inventory_hostname }}'
socket: /var/run/haproxy.sock
backend: www
- name: Disable server, provide socket file, wait until status reports in maintenance
haproxy:
state: disabled
host: '{{ inventory_hostname }}'
socket: /var/run/haproxy.sock
backend: www
wait: yes
# Place server in drain mode, providing a socket file. Then check the server's
# status every minute to see if it changes to maintenance mode, continuing if it
# does in an hour and failing otherwise.
- haproxy:
state: disabled
host: '{{ inventory_hostname }}'
socket: /var/run/haproxy.sock
backend: www
wait: yes
drain: yes
wait_interval: 1
wait_retries: 60
- name: Disable backend server in 'www' backend pool and drop open sessions to it
haproxy:
state: disabled
host: '{{ inventory_hostname }}'
backend: www
socket: /var/run/haproxy.sock
shutdown_sessions: yes
- name: Disable server without backend pool name (apply to all available backend pool) but fail when the backend host is not found
haproxy:
state: disabled
host: '{{ inventory_hostname }}'
fail_on_not_found: yes
- name: Enable server in 'www' backend pool
haproxy:
state: enabled
host: '{{ inventory_hostname }}'
backend: www
- name: Enable server in 'www' backend pool wait until healthy
haproxy:
state: enabled
host: '{{ inventory_hostname }}'
backend: www
wait: yes
- name: Enable server in 'www' backend pool wait until healthy. Retry 10 times with intervals of 5 seconds to retrieve the health
haproxy:
state: enabled
host: '{{ inventory_hostname }}'
backend: www
wait: yes
wait_retries: 10
wait_interval: 5
- name: Enable server in 'www' backend pool with change server(s) weight
haproxy:
state: enabled
host: '{{ inventory_hostname }}'
socket: /var/run/haproxy.sock
weight: 10
backend: www
- name: Set the server in 'www' backend pool to drain mode
haproxy:
state: drain
host: '{{ inventory_hostname }}'
socket: /var/run/haproxy.sock
backend: www
Status¶
This module is not guaranteed to have a backwards compatible interface. [preview]
This module is maintained by the Ansible Community. [community]
Authors¶
Ravi Bhure (@ravibhure)
Hint
If you notice any issues in this documentation, you can edit this document to improve it.