community.general.haproxy (8.5.0) — module

Enable, disable, and set weights for HAProxy backend servers using socket commands

Authors: Ravi Bhure (@ravibhure)

Install collection

Install with ansible-galaxy collection install community.general:==8.5.0


Add to requirements.yml

  collections:
    - name: community.general
      version: 8.5.0

Description

Enable, disable, drain and set weights for HAProxy backend servers using socket commands.

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Disable server in 'www' backend pool
  community.general.haproxy:
    state: disabled
    host: '{{ inventory_hostname }}'
    backend: www
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Disable server in 'www' backend pool, also stop health/agent checks
  community.general.haproxy:
    state: disabled
    host: '{{ inventory_hostname }}'
    health: true
    agent: true
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Disable server without backend pool name (apply to all available backend pool)
  community.general.haproxy:
    state: disabled
    host: '{{ inventory_hostname }}'
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Disable server, provide socket file
  community.general.haproxy:
    state: disabled
    host: '{{ inventory_hostname }}'
    socket: /var/run/haproxy.sock
    backend: www
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Disable server, provide socket file, wait until status reports in maintenance
  community.general.haproxy:
    state: disabled
    host: '{{ inventory_hostname }}'
    socket: /var/run/haproxy.sock
    backend: www
    wait: true
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# 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.
- community.general.haproxy:
    state: disabled
    host: '{{ inventory_hostname }}'
    socket: /var/run/haproxy.sock
    backend: www
    wait: true
    drain: true
    wait_interval: 60
    wait_retries: 60
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Disable backend server in 'www' backend pool and drop open sessions to it
  community.general.haproxy:
    state: disabled
    host: '{{ inventory_hostname }}'
    backend: www
    socket: /var/run/haproxy.sock
    shutdown_sessions: true
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Disable server without backend pool name (apply to all available backend pool) but fail when the backend host is not found
  community.general.haproxy:
    state: disabled
    host: '{{ inventory_hostname }}'
    fail_on_not_found: true
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Enable server in 'www' backend pool
  community.general.haproxy:
    state: enabled
    host: '{{ inventory_hostname }}'
    backend: www
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Enable server in 'www' backend pool wait until healthy
  community.general.haproxy:
    state: enabled
    host: '{{ inventory_hostname }}'
    backend: www
    wait: true
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Enable server in 'www' backend pool wait until healthy. Retry 10 times with intervals of 5 seconds to retrieve the health
  community.general.haproxy:
    state: enabled
    host: '{{ inventory_hostname }}'
    backend: www
    wait: true
    wait_retries: 10
    wait_interval: 5
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Enable server in 'www' backend pool with change server(s) weight
  community.general.haproxy:
    state: enabled
    host: '{{ inventory_hostname }}'
    socket: /var/run/haproxy.sock
    weight: 10
    backend: www
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Set the server in 'www' backend pool to drain mode
  community.general.haproxy:
    state: drain
    host: '{{ inventory_hostname }}'
    socket: /var/run/haproxy.sock
    backend: www

Inputs

    
host:
    description:
    - Name of the backend host to change.
    required: true
    type: str

wait:
    default: false
    description:
    - Wait until the server reports a status of C(UP) when O(state=enabled), status of
      C(MAINT) when O(state=disabled) or status of C(DRAIN) when O(state=drain).
    type: bool

agent:
    default: false
    description:
    - Disable/enable agent checks (depending on O(state) value).
    type: bool
    version_added: 1.0.0
    version_added_collection: community.general

drain:
    default: false
    description:
    - Wait until the server has no active connections or until the timeout determined
      by wait_interval and wait_retries is reached.
    - Continue only after the status changes to C(MAINT).
    - This overrides the shutdown_sessions option.
    type: bool

state:
    choices:
    - disabled
    - drain
    - enabled
    description:
    - Desired state of the provided backend host.
    - Note that V(drain) state was added in version 2.4.
    - It is supported only by HAProxy version 1.5 or later,
    - When used on versions < 1.5, it will be ignored.
    required: true
    type: str

health:
    default: false
    description:
    - Disable/enable health checks (depending on O(state) value).
    type: bool
    version_added: 1.0.0
    version_added_collection: community.general

socket:
    default: /var/run/haproxy.sock
    description:
    - Path to the HAProxy socket file.
    type: path

weight:
    description:
    - The value passed in argument.
    - If the value ends with the V(%) sign, then the new weight will be relative to the
      initially configured weight.
    - Relative weights are only permitted between 0 and 100% and absolute weights are
      permitted between 0 and 256.
    type: str

backend:
    description:
    - Name of the HAProxy backend pool.
    - If this parameter is unset, it will be auto-detected.
    type: str

wait_retries:
    default: 25
    description:
    - Number of times to check for status after changing the state.
    type: int

wait_interval:
    default: 5
    description:
    - Number of seconds to wait between retries.
    type: int

fail_on_not_found:
    default: false
    description:
    - Fail whenever trying to enable/disable a backend host that does not exist.
    type: bool

shutdown_sessions:
    default: false
    description:
    - When disabling a server, immediately terminate all the sessions attached to the
      specified server.
    - This can be used to terminate long-running sessions after a server is put into maintenance
      mode. Overridden by the drain option.
    type: bool