From 16c63c5fda68edf40c158b88d89b6ad0f5c712ee Mon Sep 17 00:00:00 2001 From: Vitaliy Kukharik Date: Mon, 3 Jul 2023 14:07:50 +0300 Subject: [PATCH] Make inventory group 'balancers' optional in Ansible tasks With this commit, we've adjusted our Ansible tasks to treat the 'balancers' group as optional. Previously, if this group wasn't defined in the inventory file, it would result in a task failure. We've addressed this issue by utilizing the default filter, which handles the 'balancers' group as an empty list if not defined, thus preventing any associated errors. Please note that this change doesn't impact the 'postgres_cluster' group, which remains as a required group in the inventory. Issue: https://github.com/vitabaks/postgresql_cluster/issues/388 --- roles/deploy-finish/tasks/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/deploy-finish/tasks/main.yml b/roles/deploy-finish/tasks/main.yml index 6fa5b9285..798f4bce7 100644 --- a/roles/deploy-finish/tasks/main.yml +++ b/roles/deploy-finish/tasks/main.yml @@ -128,7 +128,7 @@ - name: Create list of nodes run_once: true set_fact: - haproxy_nodes: "{% for host in groups['balancers'] %}{{ hostvars[host]['inventory_hostname'] }}{% if not loop.last %},{% endif %}{% endfor %}" + haproxy_nodes: "{% for host in groups['balancers'] | default([]) %}{{ hostvars[host]['inventory_hostname'] }}{% if not loop.last %},{% endif %}{% endfor %}" postgres_cluster_nodes: "{% for host in groups['postgres_cluster'] %}{{ hostvars[host]['inventory_hostname'] }}{% if not loop.last %},{% endif %}{% endfor %}" - name: PostgreSQL Cluster connection info