From ef93e364a56302738173fefe49b0097d30d8f467 Mon Sep 17 00:00:00 2001 From: Adrien Cunin Date: Wed, 19 Feb 2020 17:21:16 +0100 Subject: [PATCH] Added new playbook to set HAProxy backends state It helps to globally enable/disable HAProxy backends related to a specific controller. Change-Id: I776092b91c6a0a4949244faa044da2d45327cb4e --- .../playbooks/set-haproxy-backends-state.yml | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 ansible_tools/playbooks/set-haproxy-backends-state.yml diff --git a/ansible_tools/playbooks/set-haproxy-backends-state.yml b/ansible_tools/playbooks/set-haproxy-backends-state.yml new file mode 100644 index 00000000..9b66a142 --- /dev/null +++ b/ansible_tools/playbooks/set-haproxy-backends-state.yml @@ -0,0 +1,37 @@ +--- +# 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=` +# * `-e backend_state=` +# in order to globally enable/disable a controller at the HAProxy level. + +- name: Set HAProxy backends state + hosts: haproxy + vars: + - hostname: "" + - backend_state: enabled + tasks: + - name: List HAProxy backends to process + shell: echo show servers state | nc -U /var/run/haproxy.stat | awk '{print $4}' | grep '^{{ hostname }}' + register: backends + changed_when: false + - name: Loop through backends to set state + haproxy: + host: "{{ item }}" + state: "{{ backend_state }}" + socket: /var/run/haproxy.stat + with_items: "{{ backends.stdout_lines }}"