feat(unbound): use TOFS for configuration

This commit is contained in:
Alexander Weidinger 2021-03-31 11:08:28 +02:00
parent ec6ea521b6
commit 5952aa24aa
41 changed files with 123 additions and 140 deletions

View File

@ -18,8 +18,14 @@ unbound-formula
:scale: 100%
:target: https://github.com/pre-commit/pre-commit
A SaltStack formula that is empty. It has dummy content to help with a quick
start on a new formula and it serves as a style guide.
A SaltStack formula which manages _unbound_.
The actual configuration file is out of scope.
It's not trivial to map Pillar data to ubound's configuration format.
Furthermore it's not clear that this the best approach in all use-cases.
Therefore this formula assumes you'll provide a configuration file (or a template)
following the `TOFS pattern <https://template-formula.readthedocs.io/en/latest/TOFS_pattern.html>`_.
.. contents:: **Table of Contents**
:depth: 1

View File

@ -489,7 +489,7 @@ Here is an example based on `template-formula/unbound/config/file.sls`_:
unbound-config-file-file-managed:
file.managed:
- name: {{ unbound.config }}
- source: {{ files_switch(['example.tmpl'],
- source: {{ files_switch(['unbound.conf'],
lookup='unbound-config-file-file-managed'
)
}}

View File

@ -8,14 +8,11 @@ unbound:
winner: lookup
added_in_lookup: lookup_value
# Using bash package and udev service as an example. This allows us to
# test the template formula itself. You should set these parameters to
# examples that make sense in the contexto of the formula you're writing.
pkg:
name: bash
service:
name: systemd-journald
config: /etc/template-formula.conf
# pkg:
# name: unbound
# service:
# name: unbound
# config: /etc/unbound/unbound.conf
tofs:
# The files_switch key serves as a selector for alternative
@ -48,7 +45,7 @@ unbound:
# For testing purposes
source_files:
unbound-config-file-file-managed:
- 'example.tmpl.jinja'
- 'unbound.conf.jinja'
# Just for testing purposes
winner: pillar

View File

@ -3,20 +3,20 @@
control 'unbound.config.file' do
title 'Verify the configuration file'
describe file('/etc/template-formula.conf') do
describe file('/etc/unbound/unbound.conf') do
it { should be_file }
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
its('mode') { should cmp '0644' }
its('content') do
should include(
'This is another example file from SaltStack template-formula.'
'This is just a sample for testing purposes.'
)
end
its('content') { should include '"added_in_pillar": "pillar_value"' }
its('content') { should include '"added_in_defaults": "defaults_value"' }
its('content') { should include '"added_in_lookup": "lookup_value"' }
its('content') { should include '"config": "/etc/template-formula.conf"' }
its('content') { should include '"config": "/etc/unbound/unbound.conf"' }
its('content') { should include '"lookup": {"added_in_lookup": "lookup_value",' }
its('content') { should include '"pkg": {"name": "' }
its('content') { should include '"service": {"name": "' }
@ -26,7 +26,7 @@ control 'unbound.config.file' do
should include(
'"tofs": {"files_switch": ["any/path/can/be/used/here", "id", '\
'"roles", "osfinger", "os", "os_family"], "source_files": '\
'{"unbound-config-file-file-managed": ["example.tmpl.jinja"]}'
'{"unbound-config-file-file-managed": ["unbound.conf.jinja"]}'
)
# rubocop:enable Layout/LineLength
# rubocop:enable Lint/RedundantCopDisableDirective

View File

@ -6,7 +6,7 @@ values:
added_in_lookup: lookup_value
added_in_pillar: pillar_value
arch: amd64
config: /etc/template-formula.conf
config: /etc/unbound/unbound.conf
lookup:
added_in_lookup: lookup_value
master: template-master
@ -36,5 +36,5 @@ values:
- os_family
source_files:
unbound-config-file-file-managed:
- example.tmpl.jinja
- unbound.conf.jinja
winner: pillar

View File

@ -6,7 +6,7 @@ values:
added_in_lookup: lookup_value
added_in_pillar: pillar_value
arch: amd64
config: /etc/template-formula.conf
config: /etc/unbound/unbound.conf
lookup:
added_in_lookup: lookup_value
master: template-master
@ -22,10 +22,10 @@ values:
- Y:G@id
master: template-master
pkg:
name: bash
name: unbound
rootgroup: root
service:
name: systemd-journald
name: unbound
tofs:
files_switch:
- any/path/can/be/used/here
@ -36,5 +36,5 @@ values:
- os_family
source_files:
unbound-config-file-file-managed:
- example.tmpl.jinja
- unbound.conf.jinja
winner: pillar

View File

@ -6,7 +6,7 @@ values:
added_in_lookup: lookup_value
added_in_pillar: pillar_value
arch: amd64
config: /etc/template-formula.conf
config: /etc/unbound/unbound.conf
lookup:
added_in_lookup: lookup_value
master: template-master
@ -22,10 +22,10 @@ values:
- Y:G@id
master: template-master
pkg:
name: bash
name: unbound
rootgroup: root
service:
name: systemd-journald
name: unbound
tofs:
files_switch:
- any/path/can/be/used/here
@ -36,5 +36,5 @@ values:
- os_family
source_files:
unbound-config-file-file-managed:
- example.tmpl.jinja
- unbound.conf.jinja
winner: pillar

View File

@ -6,7 +6,7 @@ values:
added_in_lookup: lookup_value
added_in_pillar: pillar_value
arch: amd64
config: /etc/template-formula.conf
config: /etc/unbound/unbound.conf
lookup:
added_in_lookup: lookup_value
master: template-master
@ -36,5 +36,5 @@ values:
- os_family
source_files:
unbound-config-file-file-managed:
- example.tmpl.jinja
- unbound.conf.jinja
winner: pillar

View File

@ -6,7 +6,7 @@ values:
added_in_lookup: lookup_value
added_in_pillar: pillar_value
arch: amd64
config: /etc/template-formula.conf
config: /etc/unbound/unbound.conf
lookup:
added_in_lookup: lookup_value
master: template-master
@ -22,10 +22,10 @@ values:
- Y:G@id
master: template-master
pkg:
name: bash
name: unbound
rootgroup: root
service:
name: systemd-journald
name: unbound
tofs:
files_switch:
- any/path/can/be/used/here
@ -36,5 +36,5 @@ values:
- os_family
source_files:
unbound-config-file-file-managed:
- example.tmpl.jinja
- unbound.conf.jinja
winner: pillar

View File

@ -6,7 +6,7 @@ values:
added_in_lookup: lookup_value
added_in_pillar: pillar_value
arch: amd64
config: /etc/template-formula.conf
config: /etc/unbound/unbound.conf
lookup:
added_in_lookup: lookup_value
master: template-master
@ -22,10 +22,10 @@ values:
- Y:G@id
master: template-master
pkg:
name: bash
name: unbound
rootgroup: root
service:
name: systemd-journald
name: unbound
tofs:
files_switch:
- any/path/can/be/used/here
@ -36,5 +36,5 @@ values:
- os_family
source_files:
unbound-config-file-file-managed:
- example.tmpl.jinja
- unbound.conf.jinja
winner: pillar

View File

@ -6,7 +6,7 @@ values:
added_in_lookup: lookup_value
added_in_pillar: pillar_value
arch: amd64
config: /etc/template-formula.conf
config: /etc/unbound/unbound.conf
lookup:
added_in_lookup: lookup_value
master: template-master
@ -22,10 +22,10 @@ values:
- Y:G@id
master: template-master
pkg:
name: bash
name: unbound
rootgroup: root
service:
name: systemd-journald
name: unbound
tofs:
files_switch:
- any/path/can/be/used/here
@ -36,5 +36,5 @@ values:
- os_family
source_files:
unbound-config-file-file-managed:
- example.tmpl.jinja
- unbound.conf.jinja
winner: pillar

View File

@ -6,7 +6,7 @@ values:
added_in_lookup: lookup_value
added_in_pillar: pillar_value
arch: amd64
config: /etc/template-formula.conf
config: /etc/unbound/unbound.conf
lookup:
added_in_lookup: lookup_value
master: template-master
@ -22,10 +22,10 @@ values:
- Y:G@id
master: template-master
pkg:
name: bash
name: unbound
rootgroup: root
service:
name: systemd-journald
name: unbound
tofs:
files_switch:
- any/path/can/be/used/here
@ -36,5 +36,5 @@ values:
- os_family
source_files:
unbound-config-file-file-managed:
- example.tmpl.jinja
- unbound.conf.jinja
winner: pillar

View File

@ -6,7 +6,7 @@ values:
added_in_lookup: lookup_value
added_in_pillar: pillar_value
arch: amd64
config: /etc/template-formula.conf
config: /etc/unbound/unbound.conf
lookup:
added_in_lookup: lookup_value
master: template-master
@ -22,10 +22,10 @@ values:
- Y:G@id
master: template-master
pkg:
name: bash
name: unbound
rootgroup: root
service:
name: systemd-journald
name: unbound
tofs:
files_switch:
- any/path/can/be/used/here
@ -36,5 +36,5 @@ values:
- os_family
source_files:
unbound-config-file-file-managed:
- example.tmpl.jinja
- unbound.conf.jinja
winner: pillar

View File

@ -6,7 +6,7 @@ values:
added_in_lookup: lookup_value
added_in_pillar: pillar_value
arch: amd64
config: /etc/template-formula.conf
config: /etc/unbound/unbound.conf
lookup:
added_in_lookup: lookup_value
master: template-master
@ -22,10 +22,10 @@ values:
- Y:G@id
master: template-master
pkg:
name: bash
name: unbound
rootgroup: root
service:
name: systemd-journald
name: unbound
tofs:
files_switch:
- any/path/can/be/used/here
@ -36,5 +36,5 @@ values:
- os_family
source_files:
unbound-config-file-file-managed:
- example.tmpl.jinja
- unbound.conf.jinja
winner: pillar

View File

@ -6,7 +6,7 @@ values:
added_in_lookup: lookup_value
added_in_pillar: pillar_value
arch: amd64
config: /etc/template-formula.conf
config: /etc/unbound/unbound.conf
lookup:
added_in_lookup: lookup_value
master: template-master
@ -22,10 +22,10 @@ values:
- Y:G@id
master: template-master
pkg:
name: bash
name: unbound
rootgroup: root
service:
name: systemd-journald
name: unbound
tofs:
files_switch:
- any/path/can/be/used/here
@ -36,5 +36,5 @@ values:
- os_family
source_files:
unbound-config-file-file-managed:
- example.tmpl.jinja
- unbound.conf.jinja
winner: pillar

View File

@ -6,7 +6,7 @@ values:
added_in_lookup: lookup_value
added_in_pillar: pillar_value
arch: amd64
config: /etc/template-formula.conf
config: /etc/unbound/unbound.conf
lookup:
added_in_lookup: lookup_value
master: template-master
@ -25,7 +25,7 @@ values:
name: app-shells/bash
rootgroup: root
service:
name: systemd-journald
name: unbound
tofs:
files_switch:
- any/path/can/be/used/here
@ -36,5 +36,5 @@ values:
- os_family
source_files:
unbound-config-file-file-managed:
- example.tmpl.jinja
- unbound.conf.jinja
winner: pillar

View File

@ -6,7 +6,7 @@ values:
added_in_lookup: lookup_value
added_in_pillar: pillar_value
arch: amd64
config: /etc/template-formula.conf
config: /etc/unbound/unbound.conf
lookup:
added_in_lookup: lookup_value
master: template-master
@ -36,5 +36,5 @@ values:
- os_family
source_files:
unbound-config-file-file-managed:
- example.tmpl.jinja
- unbound.conf.jinja
winner: pillar

View File

@ -6,7 +6,7 @@ values:
added_in_lookup: lookup_value
added_in_pillar: pillar_value
arch: amd64
config: /etc/template-formula.conf
config: /etc/unbound/unbound.conf
lookup:
added_in_lookup: lookup_value
master: template-master
@ -22,10 +22,10 @@ values:
- Y:G@id
master: template-master
pkg:
name: bash
name: unbound
rootgroup: root
service:
name: systemd-journald
name: unbound
tofs:
files_switch:
- any/path/can/be/used/here
@ -36,5 +36,5 @@ values:
- os_family
source_files:
unbound-config-file-file-managed:
- example.tmpl.jinja
- unbound.conf.jinja
winner: pillar

View File

@ -6,7 +6,7 @@ values:
added_in_lookup: lookup_value
added_in_pillar: pillar_value
arch: amd64
config: /etc/template-formula.conf
config: /etc/unbound/unbound.conf
lookup:
added_in_lookup: lookup_value
master: template-master
@ -22,10 +22,10 @@ values:
- Y:G@id
master: template-master
pkg:
name: bash
name: unbound
rootgroup: root
service:
name: systemd-journald
name: unbound
tofs:
files_switch:
- any/path/can/be/used/here
@ -36,5 +36,5 @@ values:
- os_family
source_files:
unbound-config-file-file-managed:
- example.tmpl.jinja
- unbound.conf.jinja
winner: pillar

View File

@ -6,7 +6,7 @@ values:
added_in_lookup: lookup_value
added_in_pillar: pillar_value
arch: amd64
config: /etc/template-formula.conf
config: /etc/unbound/unbound.conf
lookup:
added_in_lookup: lookup_value
master: template-master
@ -22,10 +22,10 @@ values:
- Y:G@id
master: template-master
pkg:
name: bash
name: unbound
rootgroup: root
service:
name: systemd-journald
name: unbound
tofs:
files_switch:
- any/path/can/be/used/here
@ -36,5 +36,5 @@ values:
- os_family
source_files:
unbound-config-file-file-managed:
- example.tmpl.jinja
- unbound.conf.jinja
winner: pillar

View File

@ -6,7 +6,7 @@ values:
added_in_lookup: lookup_value
added_in_pillar: pillar_value
arch: amd64
config: /etc/template-formula.conf
config: /etc/unbound/unbound.conf
lookup:
added_in_lookup: lookup_value
master: template-master
@ -22,10 +22,10 @@ values:
- Y:G@id
master: template-master
pkg:
name: bash
name: unbound
rootgroup: root
service:
name: systemd-journald
name: unbound
tofs:
files_switch:
- any/path/can/be/used/here
@ -36,5 +36,5 @@ values:
- os_family
source_files:
unbound-config-file-file-managed:
- example.tmpl.jinja
- unbound.conf.jinja
winner: pillar

View File

@ -6,7 +6,7 @@ values:
added_in_lookup: lookup_value
added_in_pillar: pillar_value
arch: amd64
config: /etc/template-formula.conf
config: /etc/unbound/unbound.conf
lookup:
added_in_lookup: lookup_value
master: template-master
@ -22,10 +22,10 @@ values:
- Y:G@id
master: template-master
pkg:
name: bash
name: unbound
rootgroup: root
service:
name: systemd-journald
name: unbound
tofs:
files_switch:
- any/path/can/be/used/here
@ -36,5 +36,5 @@ values:
- os_family
source_files:
unbound-config-file-file-managed:
- example.tmpl.jinja
- unbound.conf.jinja
winner: pillar

View File

@ -6,7 +6,7 @@ values:
added_in_lookup: lookup_value
added_in_pillar: pillar_value
arch: amd64
config: /etc/template-formula.conf
config: /etc/unbound/unbound.conf
lookup:
added_in_lookup: lookup_value
master: template-master
@ -22,10 +22,10 @@ values:
- Y:G@id
master: template-master
pkg:
name: bash
name: unbound
rootgroup: root
service:
name: systemd-journald
name: unbound
tofs:
files_switch:
- any/path/can/be/used/here
@ -36,5 +36,5 @@ values:
- os_family
source_files:
unbound-config-file-file-managed:
- example.tmpl.jinja
- unbound.conf.jinja
winner: pillar

View File

@ -6,7 +6,7 @@ values:
added_in_lookup: lookup_value
added_in_pillar: pillar_value
arch: amd64
config: /etc/template-formula.conf
config: /etc/unbound/unbound.conf
lookup:
added_in_lookup: lookup_value
master: template-master
@ -22,10 +22,10 @@ values:
- Y:G@id
master: template-master
pkg:
name: bash
name: unbound
rootgroup: root
service:
name: systemd-journald
name: unbound
tofs:
files_switch:
- any/path/can/be/used/here
@ -36,5 +36,5 @@ values:
- os_family
source_files:
unbound-config-file-file-managed:
- example.tmpl.jinja
- unbound.conf.jinja
winner: pillar

View File

@ -43,7 +43,7 @@ unbound:
# For testing purposes
source_files:
unbound-config-file-file-managed:
- 'example.tmpl.jinja'
- 'unbound.conf.jinja'
# Just for testing purposes
winner: pillar

View File

@ -13,7 +13,7 @@ include:
unbound-config-file-file-managed:
file.managed:
- name: {{ unbound.config }}
- source: {{ files_switch(['example.tmpl'],
- source: {{ files_switch(['unbound.conf'],
lookup='unbound-config-file-file-managed'
)
}}
@ -22,6 +22,7 @@ unbound-config-file-file-managed:
- group: {{ unbound.rootgroup }}
- makedirs: True
- template: jinja
- check_cmd: unbound-checkconf
- require:
- sls: {{ sls_package_install }}
- context:

View File

@ -1,6 +0,0 @@
########################################################################
# File managed by Salt at <{{ source }}>.
# Your changes will be overwritten.
########################################################################
This is an example file from SaltStack template-formula.

View File

@ -1,11 +0,0 @@
########################################################################
# File managed by Salt at <{{ source }}>.
# Your changes will be overwritten.
########################################################################
This is another example file from SaltStack template-formula.
# This is here for testing purposes
{{ unbound | json }}
winner of the merge: {{ unbound['winner'] }}

View File

@ -0,0 +1,6 @@
# This is just a sample for testing purposes.
# Please provide your own config for your server(s)!
server:
interface: 0.0.0.0
interface: ::0

View File

@ -0,0 +1,11 @@
# This is just a sample for testing purposes.
# Please provide your own config for your server(s)!
server:
interface: 0.0.0.0
interface: ::0
# You have access to the unbound variable:
# winner of the merge: {{ unbound.winner }}
#
# {{ unbound | json }}

View File

@ -7,7 +7,7 @@ values:
pkg:
name: unbound
rootgroup: root
config: '/etc/unbound'
config: '/etc/unbound/unbound.conf'
service:
name: unbound
# Just here for testing

View File

@ -12,8 +12,6 @@
# values: {}
---
values:
pkg:
name: unbound-fedora
service:
name: service-fedora
config: '/etc/unbound/unbound.conf'
config_dir: '/etc/unbound'
...

View File

@ -11,8 +11,5 @@
# you can remove this file or provide at least an empty dict, e.g.
# values: {}
---
values:
pkg:
name: unbound-ubuntu
config: /etc/unbound.d/custom-ubuntu.conf
values: {}
...

View File

@ -11,9 +11,5 @@
# you can remove this file or provide at least an empty dict, e.g.
# values: {}
---
values:
pkg:
name: unbound-arch
service:
name: service-arch
values: {}
...

View File

@ -11,8 +11,5 @@
# you can remove this file or provide at least an empty dict, e.g.
# values: {}
---
values:
pkg:
name: unbound-debian
config: /etc/unbound.d/custom.conf
values: {}
...

View File

@ -13,4 +13,5 @@
---
values:
rootgroup: wheel
config: '/usr/local/etc/unbound/unbound.conf'
...

View File

@ -11,7 +11,5 @@
# you can remove this file or provide at least an empty dict, e.g.
# values: {}
---
values:
pkg:
name: unbound-gentoo
values: {}
...

View File

@ -12,7 +12,5 @@
# values: {}
---
values:
pkg:
name: unbound-redhat
config: /etc/unbound.conf
...

View File

@ -11,7 +11,5 @@
# you can remove this file or provide at least an empty dict, e.g.
# values: {}
---
values:
pkg:
name: unbound-suse
values: {}
...

View File

@ -11,8 +11,5 @@
# you can remove this file or provide at least an empty dict, e.g.
# values: {}
---
values:
pkg:
name: unbound-centos-6
config: /etc/unbound.d/custom-centos-6.conf
values: {}
...

View File

@ -11,6 +11,5 @@
# you can remove this file or provide at least an empty dict, e.g.
# values: {}
---
values:
config: /etc/unbound.d/custom-ubuntu-18.04.conf
values: {}
...