Files
openstack-ansible-plugins/playbooks/tools/set_haproxy_backends_state.yml
Dmitriy Rabotyagov 0602318e72 Leverage haproxy_endpoint_manage for backends state playbook
Most of our playbooks already leverage haproxy_endpoint_manage role
which aims to manage haproxy endpoints.

With that it makes sense to leverage the same role by
set_haproxy_backends_state playbook which should ensure
variables and parameters being respected consistently.

Change-Id: Iade16dc168f516e663ff1e0b79789312abba9cbf
Signed-off-by: Dmitriy Rabotyagov <dmitriy.rabotyagov@cleura.com>
2025-08-21 17:04:14 +02:00

51 lines
1.8 KiB
YAML

---
# Copyright 2020, Springer Nature.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# This playbook is typically used with the following ansible-playbook
# arguments:
# * `-e hostname=<host>`
# * `-e backend_state=<enabled|disabled>`
# in order to globally enable/disable a controller at the HAProxy level.
- name: Set HAProxy backends state
hosts: haproxy
vars_prompt:
- name: "hostname"
prompt: |-
Supply a hostname of backends to be managed.
Define metal host to manage LXC container backends on this host
private: false
- name: "backend_state"
prompt: "Supply desired HAProxy state for affected backends"
default: "enabled"
private: false
tasks:
- name: List HAProxy backends to process # noqa: risky-shell-pipe
ansible.builtin.shell: echo show servers state | nc -U /var/run/haproxy.stat | awk '{print $4}' | grep '^{{ hostname }}' | sort | uniq
register: backends
changed_when: false
- name: Including haproxy_endpoint_manage role
ansible.builtin.include_role:
name: openstack.osa.haproxy_endpoint_manage
vars:
haproxy_host: "{{ backend }}"
haproxy_state: "{{ backend_state }}"
haproxy_target_hosts:
- "{{ inventory_hostname }}"
loop: "{{ backends.stdout_lines }}"
loop_control:
loop_var: backend