From 9a0c5cc6f179da61d0d3496a3127f6ccfb93f4a5 Mon Sep 17 00:00:00 2001 From: Mark Gomersbach Date: Tue, 16 Oct 2018 11:31:59 +0200 Subject: [PATCH] Move data to YAML files and keep map.jinja a template - Add Gentoo support - Add FreeBSD support --- sysctl/map.jinja | 52 +++++++++++++++++------------------------- sysctl/osfamilymap.yml | 12 ++++++++++ 2 files changed, 33 insertions(+), 31 deletions(-) create mode 100644 sysctl/osfamilymap.yml diff --git a/sysctl/map.jinja b/sysctl/map.jinja index 324edfc..d09c0e1 100644 --- a/sysctl/map.jinja +++ b/sysctl/map.jinja @@ -1,45 +1,35 @@ # -*- coding: utf-8 -*- # vim: ft=jinja -{## Start with defaults from defaults.sls ##} +{## Start with defaults from defaults.sls and osfamilymap.yml ##} {% import_yaml 'sysctl/defaults.yml' as default_settings %} +{% import_yaml "sysctl/osfamilymap.yml" as os_family_map %} -{% set sysctl_lookup = salt['pillar.get']('sysctl:lookup', {}).copy() %} - -{% if sysctl_lookup.params is defined %} -{% do sysctl_lookup.pop('params') %} -{% endif %} - -{% if sysctl_lookup.params2 is defined %} -{% do sysctl_lookup.pop('params2') %} -{% endif %} +{% set osfam = salt['grains.filter_by']( + os_family_map, + grain='os_family', + ) or {} +%} -{## setup variable using grains['os_family'] based logic ##} -{% set os_family_map = salt['grains.filter_by']({ - 'Arch': {}, - 'RedHat': { - "config": { - "location": '/etc/sysctl.conf', - } - }, - 'Suse': { - "pkg": "procps", - }, - 'Debian': { - "pkg": "procps", - }, - }, - grain="os_family", - merge=sysctl_lookup) +{% do salt['defaults.merge'](default_settings['sysctl'], osfam) %} +{% do salt['defaults.merge']( + default_settings['sysctl'], + salt['pillar.get']('sysctl:lookup',{}), + ) %} -{## Merge the flavor_map to the default settings ##} -{% do default_settings.sysctl.update(os_family_map) %} +{## Apply backwards compatiblility after merge ##} +{% if default_settings['sysctl']['params'] is defined %} +{% do default_settings['sysctl'].pop('params') %} +{% endif %} +{% if default_settings['sysctl']['params2'] is defined %} +{% do default_settings['sysctl'].pop('params2') %} +{% endif %} {## Merge in sysctl pillar ##} {% set sysctl_settings = salt['pillar.get']( 'sysctl', - default=default_settings.sysctl, - merge=True + default=default_settings['sysctl'], + merge=True, ) %} diff --git a/sysctl/osfamilymap.yml b/sysctl/osfamilymap.yml new file mode 100644 index 0000000..108ffa0 --- /dev/null +++ b/sysctl/osfamilymap.yml @@ -0,0 +1,12 @@ +RedHat: + config: + location: /etc/sysctl.conf +Suse: + pkg: procps +Debian: + pkg: procps +Gentoo: + pkg: sys-process/procps +FreeBSD: + config: + location: /etc/sysctl.conf \ No newline at end of file