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 = [] -%}