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
This commit is contained in:
Dmitriy Rabotyagov 2024-01-23 11:13:53 +01:00
parent 1c0bd2ae11
commit a6fe4260a2

View File

@ -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