From 4267fd2482a83665acd31bdcdcfcf1622f8b439e Mon Sep 17 00:00:00 2001 From: Georg Pfuetzenreuter Date: Fri, 17 Feb 2023 00:07:24 +0100 Subject: [PATCH] feat(config): pillar based config template Allow management of general configuration using pillar data. Signed-off-by: Georg Pfuetzenreuter --- nsd/config/file.sls | 10 ++++++++++ .../default/pillar-configuration.conf.jinja | 6 ++++++ pillar.example | 19 ++++++++++++++++--- .../default/files/_mapdata/debian-10.yaml | 11 +++++++++-- .../default/files/_mapdata/debian-9.yaml | 11 +++++++++-- .../default/files/_mapdata/opensuse-15.yaml | 11 +++++++++-- .../files/_mapdata/opensuse-tumbleweed.yaml | 11 +++++++++-- 7 files changed, 68 insertions(+), 11 deletions(-) create mode 100644 nsd/files/default/pillar-configuration.conf.jinja diff --git a/nsd/config/file.sls b/nsd/config/file.sls index da1bc20..713210f 100644 --- a/nsd/config/file.sls +++ b/nsd/config/file.sls @@ -4,6 +4,7 @@ {#- Get the `tplroot` from `tpldir` #} {%- set tplroot = tpldir.split('/')[0] %} {%- set sls_package_install = tplroot ~ '.package.install' %} +{%- from tplroot ~ "/macros.jinja" import config_file with context %} {%- from tplroot ~ "/map.jinja" import mapdata as nsd with context %} {%- from tplroot ~ "/libtofs.jinja" import files_switch with context %} @@ -28,3 +29,12 @@ nsd-config-file-file-managed: - context: nsd: {{ nsd | json }} - check_cmd: nsd-checkconf + +{%- set config_data = nsd.get('config_data', {}) %} + +{%- if config_data | length > 0 %} + +{{ config_file('10-salt', 'pillar-configuration') }} + +{%- endif %} + diff --git a/nsd/files/default/pillar-configuration.conf.jinja b/nsd/files/default/pillar-configuration.conf.jinja new file mode 100644 index 0000000..74a87df --- /dev/null +++ b/nsd/files/default/pillar-configuration.conf.jinja @@ -0,0 +1,6 @@ +{%- for category, config in nsd.get('config_data').items() %} +{{ category }}: +{%- for option, value in config.items() %} + {{ option }}: {{ value }} +{%- endfor %} +{%- endfor %} diff --git a/pillar.example b/pillar.example index f7ea0d1..c56bfdd 100644 --- a/pillar.example +++ b/pillar.example @@ -17,9 +17,10 @@ nsd: # config_include_glob: *.conf # Configuration is separated into several files which have their own templates - config_files: - 10-server: local-nsd-for-unbound - # 90-generated-zones is reserved for zones generated by this formula + # config_files: + # 10-server: local-nsd-for-unbound + # # 90-generated-zones is reserved for zones generated by this formula + # # 10-salt is reserved for general configuration generated by this formula # If this section is present in your Pillar data, # nsd.conf.d/90-generated-zones will be created and managed. @@ -31,6 +32,18 @@ nsd: # NSD's include-pattern directive may be a better way to share configuration # across zones than using YAML anchors. + # If this section is present in your Pillar data, + # nsd.conf.d/10-salt.conf will be created and managed + config_data: + server: + hide-version: 'yes' + ip-address: 127.0.0.1 + verbosity: 2 + port: 53530 + remote-control: + control-enable: 'yes' + control-interface: /run/nsd.sock + tofs: # The files_switch key serves as a selector for alternative # directories under the formula files directory. See TOFS pattern diff --git a/test/integration/default/files/_mapdata/debian-10.yaml b/test/integration/default/files/_mapdata/debian-10.yaml index 638f05a..ef7eb79 100644 --- a/test/integration/default/files/_mapdata/debian-10.yaml +++ b/test/integration/default/files/_mapdata/debian-10.yaml @@ -7,8 +7,15 @@ values: added_in_pillar: pillar_value arch: amd64 config: /etc/nsd/nsd.conf - config_files: - 10-server: local-nsd-for-unbound + config_data: + remote-control: + control-enable: 'yes' + control-interface: /run/nsd.sock + server: + hide-version: 'yes' + ip-address: 127.0.0.1 + port: 53530 + verbosity: 2 config_include_dir: "/etc/nsd/nsd.conf.d" config_include_glob: "*.conf" lookup: diff --git a/test/integration/default/files/_mapdata/debian-9.yaml b/test/integration/default/files/_mapdata/debian-9.yaml index f914738..494618e 100644 --- a/test/integration/default/files/_mapdata/debian-9.yaml +++ b/test/integration/default/files/_mapdata/debian-9.yaml @@ -7,8 +7,15 @@ values: added_in_pillar: pillar_value arch: amd64 config: /etc/nsd/nsd.conf - config_files: - 10-server: local-nsd-for-unbound + config_data: + remote-control: + control-enable: 'yes' + control-interface: /run/nsd.sock + server: + hide-version: 'yes' + ip-address: 127.0.0.1 + port: 53530 + verbosity: 2 config_include_dir: "/etc/nsd/nsd.conf.d" config_include_glob: "*.conf" lookup: diff --git a/test/integration/default/files/_mapdata/opensuse-15.yaml b/test/integration/default/files/_mapdata/opensuse-15.yaml index 0a28fbd..fe626b3 100644 --- a/test/integration/default/files/_mapdata/opensuse-15.yaml +++ b/test/integration/default/files/_mapdata/opensuse-15.yaml @@ -7,8 +7,15 @@ values: added_in_pillar: pillar_value arch: amd64 config: /etc/nsd/nsd.conf - config_files: - 10-server: local-nsd-for-unbound + config_data: + remote-control: + control-enable: 'yes' + control-interface: /run/nsd.sock + server: + hide-version: 'yes' + ip-address: 127.0.0.1 + port: 53530 + verbosity: 2 config_include_dir: "/etc/nsd/nsd.conf.d" config_include_glob: "*.conf" lookup: diff --git a/test/integration/default/files/_mapdata/opensuse-tumbleweed.yaml b/test/integration/default/files/_mapdata/opensuse-tumbleweed.yaml index 827e149..b11e55b 100644 --- a/test/integration/default/files/_mapdata/opensuse-tumbleweed.yaml +++ b/test/integration/default/files/_mapdata/opensuse-tumbleweed.yaml @@ -7,8 +7,15 @@ values: added_in_pillar: pillar_value arch: amd64 config: /etc/nsd/nsd.conf - config_files: - 10-server: local-nsd-for-unbound + config_data: + remote-control: + control-enable: 'yes' + control-interface: /run/nsd.sock + server: + hide-version: 'yes' + ip-address: 127.0.0.1 + port: 53530 + verbosity: 2 config_include_dir: "/etc/nsd/nsd.conf.d" config_include_glob: "*.conf" lookup: