Skip to content

Commit ad4385b

Browse files
committed
feat(map): config.get lookups from configurable roots
We avoid compatibility break with user pillars by looking up configuration values using `config.get` in configurable roots. We provide a new parameter `map_jinja:config_get_roots` in the formula `parameters/defaults.yaml`to retrives values not only from `tplroot=openssh` but from `sshd_config` and `ssh_config` too. We need to update the `_mapdata` reference files to include the new `map_jinja:config_get_roots`.
1 parent df477b2 commit ad4385b

16 files changed

Lines changed: 144 additions & 40 deletions

openssh/map.jinja

Lines changed: 68 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,31 @@
4747
~ map_sources
4848
) %}
4949

50+
{#- Lookup with `config.get` from configurable roots #}
51+
{%- do salt["log.debug"](
52+
"map.jinja: initialise 'config.get' roots with 'tplroot' "
53+
~ tplroot
54+
) %}
55+
{%- set config_get_roots = [tplroot] %}
56+
{#- Configure `config.get` from defaults.yaml #}
57+
{%- set config_get_roots = default_settings | traverse(
58+
"values:map_jinja:config_get_roots",
59+
config_get_roots
60+
) %}
61+
{#- Lookup global `config.get` roots #}
62+
{%- set config_get_roots = salt["config.get"](
63+
"map_jinja:config_get_roots",
64+
config_get_roots
65+
) %}
66+
{#- Lookup per formula `config.get` roots #}
67+
{%- set config_get_roots = salt["config.get"](
68+
tplroot ~ ":map_jinja:config_get_roots",
69+
config_get_roots,
70+
) %}
71+
{%- do salt["log.debug"](
72+
"map.jinja: load parameters with 'config.get' from roots "
73+
~ config_get_roots
74+
) %}
5075

5176
{#- Work around assignment inside for loop #}
5277
{#- load configuration values used in `config.get` merging strategies #}
@@ -85,47 +110,50 @@
85110
{#- process each `map.jinja` source #}
86111
{%- for map_source in map_sources %}
87112
{%- if map_source in ["config_get", "config_get_lookup"] %}
88-
{%- set _config_key = {
89-
"config_get": tplroot,
90-
"config_get_lookup": tplroot ~ ":lookup",
91-
}.get(map_source) %}
92-
{%- set _config_type = {
93-
"config_get": "configuration",
94-
"config_get_lookup": "lookup",
95-
}.get(map_source) %}
96-
97-
{%- do salt["log.debug"](
98-
"map.jinja: retrieve formula "
99-
~ _config_type
100-
~ " with 'config.get'"
101-
~ _config["merge_msg"]
102-
) %}
103-
{%- set _config_get = salt["config.get"](
104-
_config_key, default={}, **_config["merge_opt"]
105-
) %}
113+
{%- for _config_root in config_get_roots %}
114+
{%- set _config_key = {
115+
"config_get": _config_root,
116+
"config_get_lookup": _config_root ~ ":lookup",
117+
}.get(map_source) %}
118+
119+
{%- do salt["log.debug"](
120+
"map.jinja: retrieve '"
121+
~ _config_key
122+
~ "' with 'config.get'"
123+
~ _config["merge_msg"]
124+
) %}
125+
{%- set _config_get = salt["config.get"](
126+
_config_key, default={}, **_config["merge_opt"]
127+
) %}
106128

107-
{#- `slsutil.merge` defaults to `smart` instead of `None` for `config.get` #}
108-
{%- set _strategy = _config["merge_strategy"] | default("smart", boolean=True) %}
109-
{%- do salt["log.debug"](
110-
"map.jinja: merge formula "
111-
~ _config_type
112-
~ " retrieved with 'config.get'"
113-
~ ", merge: strategy='"
114-
~ _strategy
115-
~ "', lists='"
116-
~ _config["merge_lists"]
117-
~ "'"
118-
) %}
119-
{%- do _config.update(
120-
{
121-
"stack": salt["slsutil.merge"](
122-
_config["stack"],
123-
_config_get,
124-
strategy=_strategy,
125-
merge_lists=_config["merge_lists"],
126-
)
127-
}
128-
) %}
129+
{#- `slsutil.merge` defaults to `smart` instead of `None` for `config.get` #}
130+
{%- set _strategy = _config["merge_strategy"] | default("smart", boolean=True) %}
131+
{%- do salt["log.debug"](
132+
"map.jinja: merge '"
133+
~ _config_key
134+
~ "' retrieved with 'config.get'"
135+
~ ", merge: strategy='"
136+
~ _strategy
137+
~ "', lists='"
138+
~ _config["merge_lists"]
139+
~ "'"
140+
) %}
141+
142+
{#- Keep values under each root key when there are more than one #}
143+
{%- if config_get_roots|length > 1 %}
144+
{%- set _config_get = { _config_root: _config_get } %}
145+
{%- endif %}
146+
{%- do _config.update(
147+
{
148+
"stack": salt["slsutil.merge"](
149+
_config["stack"],
150+
_config_get,
151+
strategy=_strategy,
152+
merge_lists=_config["merge_lists"],
153+
)
154+
}
155+
) %}
156+
{%- endfor %}
129157
{%- else %}
130158
{#- Lookup the grain/pillar/... #}
131159
{#- Fallback to use the source name as a direct filename #}

openssh/parameters/defaults.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
# vim: ft=yaml
33
---
44
values:
5+
map_jinja:
6+
config_get_roots:
7+
- openssh
8+
- sshd_config
9+
- ssh_config
10+
511
openssh:
612
sshd_enable: true
713
sshd_binary: /usr/sbin/sshd

test/integration/default/files/_mapdata/amazonlinux-1.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# yamllint disable rule:indentation rule:line-length
22
# Amazon Linux AMI-2018
33
---
4+
map_jinja:
5+
config_get_roots:
6+
- openssh
7+
- sshd_config
8+
- ssh_config
49
openssh:
510
absent_dsa_keys: false
611
absent_ecdsa_keys: false

test/integration/default/files/_mapdata/amazonlinux-2.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# yamllint disable rule:indentation rule:line-length
22
# Amazon Linux-2
33
---
4+
map_jinja:
5+
config_get_roots:
6+
- openssh
7+
- sshd_config
8+
- ssh_config
49
openssh:
510
absent_dsa_keys: false
611
absent_ecdsa_keys: false

test/integration/default/files/_mapdata/arch-base-latest.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# yamllint disable rule:indentation rule:line-length
22
# Arch
33
---
4+
map_jinja:
5+
config_get_roots:
6+
- openssh
7+
- sshd_config
8+
- ssh_config
49
openssh:
510
absent_dsa_keys: false
611
absent_ecdsa_keys: false

test/integration/default/files/_mapdata/centos-6.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# yamllint disable rule:indentation rule:line-length
22
# CentOS-6
33
---
4+
map_jinja:
5+
config_get_roots:
6+
- openssh
7+
- sshd_config
8+
- ssh_config
49
openssh:
510
absent_dsa_keys: false
611
absent_ecdsa_keys: false

test/integration/default/files/_mapdata/centos-7.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# yamllint disable rule:indentation rule:line-length
22
# CentOS Linux-7
33
---
4+
map_jinja:
5+
config_get_roots:
6+
- openssh
7+
- sshd_config
8+
- ssh_config
49
openssh:
510
absent_dsa_keys: false
611
absent_ecdsa_keys: false

test/integration/default/files/_mapdata/centos-8.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# yamllint disable rule:indentation rule:line-length
22
# CentOS Linux-8
33
---
4+
map_jinja:
5+
config_get_roots:
6+
- openssh
7+
- sshd_config
8+
- ssh_config
49
openssh:
510
absent_dsa_keys: false
611
absent_ecdsa_keys: false

test/integration/default/files/_mapdata/debian-10.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# yamllint disable rule:indentation rule:line-length
22
# Debian-10
33
---
4+
map_jinja:
5+
config_get_roots:
6+
- openssh
7+
- sshd_config
8+
- ssh_config
49
openssh:
510
absent_dsa_keys: false
611
absent_ecdsa_keys: false

test/integration/default/files/_mapdata/debian-9.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# yamllint disable rule:indentation rule:line-length
22
# Debian-9
33
---
4+
map_jinja:
5+
config_get_roots:
6+
- openssh
7+
- sshd_config
8+
- ssh_config
49
openssh:
510
absent_dsa_keys: false
611
absent_ecdsa_keys: false

0 commit comments

Comments
 (0)