From a6fe4260a23a24c84642adcad7ba0b4980f086d4 Mon Sep 17 00:00:00 2001 From: Dmitriy Rabotyagov Date: Tue, 23 Jan 2024 11:13:53 +0100 Subject: [PATCH] Use only unique backends to iterate over Prior output was containing same host multiple times. Applying uniq to the stdout should eliminate that and result in running module only once per host as was originally intended. Change-Id: I0993a276d26a7da86fa60b8735de05ee24160395 --- ansible_tools/playbooks/set-haproxy-backends-state.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ansible_tools/playbooks/set-haproxy-backends-state.yml b/ansible_tools/playbooks/set-haproxy-backends-state.yml index 9b66a142..9133cd9d 100644 --- a/ansible_tools/playbooks/set-haproxy-backends-state.yml +++ b/ansible_tools/playbooks/set-haproxy-backends-state.yml @@ -26,11 +26,11 @@ - 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 }}' + 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: Loop through backends to set state - haproxy: + community.general.haproxy: host: "{{ item }}" state: "{{ backend_state }}" socket: /var/run/haproxy.stat