From ba6522ce5b0c2a4f851fe4826aa9f077a4d3d381 Mon Sep 17 00:00:00 2001 From: Georg Pfuetzenreuter Date: Mon, 30 Jan 2023 05:43:53 +0100 Subject: [PATCH] Refactor map/macro sourcing - move pillar macros and map to base directory - move listener logic from macro to map - update includes respectively Signed-off-by: Georg Pfuetzenreuter --- pillar/global/init.sls | 2 +- pillar/global/ssh.sls | 2 +- pillar/{global => }/macros.jinja | 0 pillar/{global => }/map.jinja | 24 +++++++++++++++++++++++- 4 files changed, 25 insertions(+), 3 deletions(-) rename pillar/{global => }/macros.jinja (100%) rename pillar/{global => }/map.jinja (66%) diff --git a/pillar/global/init.sls b/pillar/global/init.sls index 16ab652..5b174bf 100644 --- a/pillar/global/init.sls +++ b/pillar/global/init.sls @@ -1,4 +1,4 @@ -{%- from slspath ~ '/map.jinja' import firewall_interfaces, public, internal, backend %} +{%- from slspath ~ '/../map.jinja' import firewall_interfaces, public, internal, backend %} include: - role.salt.common diff --git a/pillar/global/ssh.sls b/pillar/global/ssh.sls index 8c18a86..57ef933 100644 --- a/pillar/global/ssh.sls +++ b/pillar/global/ssh.sls @@ -1,4 +1,4 @@ -{%- from slspath ~ '/../global/macros.jinja' import listeners -%} +{%- from slspath ~ '/../map.jinja' import listeners -%} {#- {%- from '/tmp/salt-libertacasa/pillar/global/macros.jinja' import listeners with context -%} #} diff --git a/pillar/global/macros.jinja b/pillar/macros.jinja similarity index 100% rename from pillar/global/macros.jinja rename to pillar/macros.jinja diff --git a/pillar/global/map.jinja b/pillar/map.jinja similarity index 66% rename from pillar/global/map.jinja rename to pillar/map.jinja index c0fff69..bb0a536 100644 --- a/pillar/global/map.jinja +++ b/pillar/map.jinja @@ -1,7 +1,29 @@ -{%- from slspath ~ '/macros.jinja' import firewall_interfaces -%} +{%- from 'macros.jinja' import firewall_interfaces, listeners -%} {%- set firewall_interfaces = firewall_interfaces -%} +{%- set listeners = listeners -%} {%- set minion = grains['id'] -%} +{#- START Listener detection logic -#} + +{%- set listen_ips = [] -%} +{%- set minion = grains['id'] -%} +{%- set legal6s = ('fd29', '2a01:4f8:11e:2200') -%} +{%- 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 -%}{%- endif -%} +{%- if minion in ip6s -%}{%- for ip in ip6s[minion] -%} +{%- if ip.startswith(legal6s) -%} +{%- do listen_ips.append(ip) -%} +{%- endif -%} +{%- endfor -%}{%- endif -%} + +{#- END Listener detection logic -%} + + {#- START Interface mapping logic -#} {%- set public = [] -%}