summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeorg Pfuetzenreuter2023-01-28 01:52:07 +0100
committerGeorg Pfuetzenreuter2023-01-28 02:14:37 +0100
commitbd7fe25eb06bbd1db36ce7e338820703dd79b62d (patch)
tree2772924719b2512e4ecb36743d63cacfd12cab8d
parentbd166cbb4275a5e0fc8919104916e25b1ae84257 (diff)
downloadsalt-bd7fe25eb06bbd1db36ce7e338820703dd79b62d.tar.gz
salt-bd7fe25eb06bbd1db36ce7e338820703dd79b62d.tar.bz2
salt-bd7fe25eb06bbd1db36ce7e338820703dd79b62d.zip
Listeners macro: skip on empty mine
Don't fail if mine does not contain information about the queried minion. In the future it would be nice to add another conditional to allow such minions to fall-back to the locally executed network module for masterless setups. Signed-off-by: Georg Pfuetzenreuter <mail@georg-pfuetzenreuter.net>
-rw-r--r--pillar/global/macros.jinja10
1 files changed, 6 insertions, 4 deletions
diff --git a/pillar/global/macros.jinja b/pillar/global/macros.jinja
index 90e73e2..d01784a 100644
--- a/pillar/global/macros.jinja
+++ b/pillar/global/macros.jinja
@@ -2,16 +2,18 @@
{%- set listen_ips = [] -%}
{%- set minion = grains['id'] -%}
{%- set legal6s = ('fd29', '2a01:4f8:11e:2200') -%}
-{%- for ip in salt.saltutil.runner('mine.get', tgt=minion, fun='network.ip_addrs', tgt_type='glob')[minion] -%}
+{%- set ip4s = salt.saltutil.runner('mine.get', tgt=minion, fun='network.ip_addrs', tgt_type='glob') -%}
+{%- set ip6s = salt.saltutil.runner('mine.get', tgt=minion, fun='network.ip_addrs6', tgt_type='glob') -%}
+{%- if minion in ip4s -%}{%- for ip in ip4s[minion] -%}
{%- if salt['network.is_private'](ip) -%}
{%- do listen_ips.append(ip) -%}
{%- endif -%}
-{%- endfor -%}
-{%- for ip in salt.saltutil.runner('mine.get', tgt=minion, fun='network.ip_addrs6', tgt_type='glob')[minion] -%}
+{%- endfor -%}{%- endif -%}
+{%- if minion in ip6s -%}{%- for ip in ip6s[minion] -%}
{%- if ip.startswith(legal6s) -%}
{%- do listen_ips.append(ip) -%}
{%- endif -%}
-{%- endfor -%}
+{%- endfor -%}{%- endif -%}
{%- for ip in listen_ips %}
- {{ ip }}
{%- endfor %}