Merge pull request #2 from puneetk/master

Make the formula fully pillar driven/customizable
This commit is contained in:
Niels Abspoel 2015-04-06 20:39:21 +02:00
commit 411d98b6e0
7 changed files with 89 additions and 43 deletions

View File

@ -10,7 +10,8 @@ Here's a small pillar data sample::
sysctl: sysctl:
lookup: lookup:
pkg: procps-ng pkg: procps-ng
config_location: /etc/sysctl.d config:
location: /etc/sysctl.d
params: params:
vm.swappines: vm.swappines:
value: 20 value: 20

View File

@ -1,11 +1,13 @@
sysctl: sysctl:
lookup: lookup:
pkg: procps-ng pkg: procps-ng
config:
location: '/etc/sysctl.d'
params: params:
fs.file-max: -
name: fs.file-max
value: 100000 value: 100000
config: fs.conf config: fs.conf
vm.swappiness: -
name: vm.swappiness
value: 20 value: 20

14
sysctl/defaults.yml Normal file
View File

@ -0,0 +1,14 @@
# -*- coding: utf-8 -*-
# vim: ft=yaml
sysctl:
pkg: procps-ng
config:
location: '/etc/sysctl.d'
params:
-
name: fs.file-max
value: 100000
config: fs.conf
-
name: vm.swappiness
value: 20

View File

@ -1,23 +1,6 @@
{% from "sysctl/map.jinja" import sysctl with context %} # -*- coding: utf-8 -*-
# vim: ft=sls
sysctl:
pkg.installed:
- name: {{ sysctl.pkg|json }}
{%- set config = pillar.get("sysctl", {} )%}
{%- for name, item in config.get('params', {}).items() %}
{%- if item == None -%}
{% set item = {} -%}
{%- endif -%}
{%- set value = item.get('value', {}) %}
{%- set config = item.get('config') %}
{{ name }}:
sysctl.present:
- name: {{ name }}
- value: {{ value }}
{%- if 'config' in item %}
- config: {{ sysctl.config_location}}/{{ config }}
{%- endif %}
{%- endfor -%}
include:
- sysctl.package
- sysctl.param

View File

@ -1,6 +1,25 @@
{% set sysctl = salt['grains.filter_by']({ # -*- coding: utf-8 -*-
# vim: ft=jinja
{## Start with defaults from defaults.sls ##}
{% import_yaml 'sysctl/defaults.yml' as default_settings %}
{## setup variable using grains['os_family'] based logic ##}
{% set os_family_map = salt['grains.filter_by']({
'Arch': { 'Arch': {
'pkg' : 'procps-ng', "config": {
'config_location' : '/etc/sysctl.d', "location": '/etc/sysctl.d',
}, }
}, merge=salt['pillar.get']('sysctl:lookup')) %} }
}, grain="os_family")
%}
{## Merge the flavor_map to the default settings ##}
{% do default_settings.sysctl.update(os_family_map) %}
{## Merge in sysctl:lookup pillar ##}
{% set sysctl_settings = salt['pillar.get'](
'sysctl:lookup',
default=default_settings.sysctl,
merge=True
)
%}

10
sysctl/package.sls Normal file
View File

@ -0,0 +1,10 @@
# -*- coding: utf-8 -*-
# vim: ft=sls
{## import settings from map.jinja ##}
{% from "sysctl/map.jinja" import sysctl_settings with context %}
sysctl-pkg:
pkg.installed:
- name: {{ sysctl_settings.pkg }}
- failhard: True

17
sysctl/param.sls Normal file
View File

@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-
# vim: ft=sls
{## import settings from map.jinja ##}
{% from "sysctl/map.jinja" import sysctl_settings with context %}
{% for param in sysctl_settings.get('params', {}) %}
{% if param is mapping %}
sysctl-present-{{ param.name }}:
sysctl.present:
- name: {{ param.name }}
- value: {{ param.version }}
{% if param.config is defined %}
- config: {{ sysctl_settings.config.location }}/{{ param.config }}
{% endif %}
{% endif %}
{% endfor %}