From 40ad4fe142ec6a696e80790f57dbd13c3745da30 Mon Sep 17 00:00:00 2001 From: Niels Abspoel Date: Sat, 24 Jan 2015 17:14:58 +0100 Subject: [PATCH] sysctl-formula --- README.rst | 27 +++++++++++++++++++++++++++ pillar.example | 11 +++++++++++ sysctl/init.sls | 23 +++++++++++++++++++++++ sysctl/map.jinja | 6 ++++++ 4 files changed, 67 insertions(+) create mode 100644 README.rst create mode 100644 pillar.example create mode 100644 sysctl/init.sls create mode 100644 sysctl/map.jinja diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..fb85c52 --- /dev/null +++ b/README.rst @@ -0,0 +1,27 @@ +sysctl +====== + +This formula ensures that a sysctl parameter is present on the system +from a pillar file. + + +Here's a small pillar data sample:: + + sysclt: + lookup: + pkg: procps-ng + config_location: /etc/sysctl.d + params: + vm.swappines: + value: 20 + config: 10-swap.conf + fs.file-max: 10000 + + +The state sysclt will ensure these are present on the system +based on the sysctl module of salt. + +if no config value is given the key value will be written based host system. +on systemd systems this will be /etc/sysctl.d/99-salt.conf +on sysv init systems it will be /etc/sysctl.conf + diff --git a/pillar.example b/pillar.example new file mode 100644 index 0000000..c632b30 --- /dev/null +++ b/pillar.example @@ -0,0 +1,11 @@ +sysctl: + lookup: + pkg: procps-ng + params: + fs.file-max: + value: 100000 + config: fs.conf + vm.swappiness: + value: 20 + + diff --git a/sysctl/init.sls b/sysctl/init.sls new file mode 100644 index 0000000..33cb305 --- /dev/null +++ b/sysctl/init.sls @@ -0,0 +1,23 @@ +{% 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 -%} + diff --git a/sysctl/map.jinja b/sysctl/map.jinja new file mode 100644 index 0000000..b02095f --- /dev/null +++ b/sysctl/map.jinja @@ -0,0 +1,6 @@ +{% set sysctl = salt['grains.filter_by']({ + 'Arch': { + 'pkg' : 'procps-ng', + 'config_location' : '/etc/sysctl.d', + }, +}, merge=salt['pillar.get']('sysctl:lookup')) %}