From d38292e590d5bae9b184d69bdc8d56de20370915 Mon Sep 17 00:00:00 2001 From: Gregory Ballantine Date: Tue, 23 May 2017 15:17:51 -0400 Subject: [PATCH] Added nsswitch configuration --- nsswitch/defaults.yaml | 4 ++++ nsswitch/files/nsswitch.conf | 18 ++++++++++++++++++ nsswitch/init.sls | 9 +++++++++ nsswitch/map.jinja | 26 ++++++++++++++++++++++++++ 4 files changed, 57 insertions(+) create mode 100644 nsswitch/defaults.yaml create mode 100644 nsswitch/files/nsswitch.conf create mode 100644 nsswitch/init.sls create mode 100644 nsswitch/map.jinja diff --git a/nsswitch/defaults.yaml b/nsswitch/defaults.yaml new file mode 100644 index 0000000..4609a6d --- /dev/null +++ b/nsswitch/defaults.yaml @@ -0,0 +1,4 @@ +nsswitch: + config_path: /etc/nsswitch.conf + config_mode: '0644' + diff --git a/nsswitch/files/nsswitch.conf b/nsswitch/files/nsswitch.conf new file mode 100644 index 0000000..13af859 --- /dev/null +++ b/nsswitch/files/nsswitch.conf @@ -0,0 +1,18 @@ +{% from "nsswitch/map.jinja" import nsswitch_settings as nsswitch with context -%} + +# /etc/nsswitch.conf +# +# Managed by Salt +# +# Example configuration of GNU Name Service Switch functionality. +# If you have the `glibc-doc-reference' and `info' packages installed, try: +# `info libc "Name Service Switch"' for information about this file. + +{%- for key, value in nsswitch.config.iteritems() %} + {%- if value is list %} +{{ key }}: {{ v for v in value }} + {%- else %} +{{ key }}: {{ value }} + {%- endif %} +{%- endfor %} + diff --git a/nsswitch/init.sls b/nsswitch/init.sls new file mode 100644 index 0000000..e6da1d6 --- /dev/null +++ b/nsswitch/init.sls @@ -0,0 +1,9 @@ +{% from "nsswitch/map.jinja" import nsswitch_settings as nsswitch with context %} + +nsswitch_config: + file.managed: + - name: {{ nsswitch.config_path }} + - template: jinja + - source: salt://nsswitch/files/nsswitch.conf + - mode: {{ nsswitch.config_mode }} + diff --git a/nsswitch/map.jinja b/nsswitch/map.jinja new file mode 100644 index 0000000..e6d7d3d --- /dev/null +++ b/nsswitch/map.jinja @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +# vim: ft=jinja + +{## Start with defaults from defaults.sls ##} +{% import_yaml 'nsswitch/defaults.yaml' as default_settings %} + +{## +Setup variable using grains['os_family'] based logic, only add key:values here +that differ from whats in defaults.yaml +##} +{% set flavor_map = salt['grains.filter_by']( + { + }, + grain='os_family', + merge=salt['pillar.get']('nsswitch:lookup') +) %} + +{## Merge the flavor_map over the default settings ##} +{% do default_settings.nsswitch.update(flavor_map) %} + +{## Merge in changes from the nsswitch:lookup pillar ##} +{% set nsswitch_settings = salt['pillar.get']( + 'nsswitch', + default=default_settings.nsswitch, + merge=True +) %}