Make the formula fully pillar driven/customizable

- split package and param into separate state files
- use defaults.yml to specify all configurable options of the formula
- setup map.jinja to read in defaults.yml, filter by os_family for
  Arch, and merge in sysctl:lookup pillar
- Updated README
This commit is contained in:
puneet kandhari 2015-04-06 09:25:27 -05:00
parent b0c1b6ac56
commit 38eb852bce
7 changed files with 89 additions and 43 deletions

View File

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

View File

@ -1,11 +1,13 @@
sysctl:
lookup:
pkg: procps-ng
config:
location: '/etc/sysctl.d'
params:
fs.file-max:
-
name: fs.file-max
value: 100000
config: fs.conf
vm.swappiness:
-
name: vm.swappiness
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 %}
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 -%}
# -*- coding: utf-8 -*-
# vim: ft=sls
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': {
'pkg' : 'procps-ng',
'config_location' : '/etc/sysctl.d',
},
}, merge=salt['pillar.get']('sysctl:lookup')) %}
"config": {
"location": '/etc/sysctl.d',
}
}
}, 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 %}