diff --git a/states/systemd/defaults.yaml b/states/systemd/defaults.yaml new file mode 100644 index 0000000..fb51b7c --- /dev/null +++ b/states/systemd/defaults.yaml @@ -0,0 +1,12 @@ +--- +systemd: + confdir: /etc/systemd + config: + journald: + Journal: + Storage: auto + Compress: "yes" + SystemMaxUse: 500M + networkd: + Network: + SpeedMeter: "yes" diff --git a/states/systemd/init.sls b/states/systemd/init.sls new file mode 100644 index 0000000..213cca9 --- /dev/null +++ b/states/systemd/init.sls @@ -0,0 +1,24 @@ +--- +{%- from "systemd/map.jinja" import systemd with context %} +{% for module,settings in systemd.config.items() %} +systemd-confdir-{{ module }}: + file.directory: + - name: {{ systemd.confdir }}/{{ module }}.conf.d/ + +systemd-configfile-{{ module }}: + file.managed: + - name: {{ systemd.confdir }}/{{ module }}.conf.d/custom.conf + - source: salt://systemd/templates/systemd_custom.conf.j2 + - template: jinja + - user: root + - group: root + - mode: 0644 + - context: + settings: {{ settings }} + +systemd-service-{{ module }}: + service.running: + - name: systemd-{{ module }} + - watch: + - file: systemd-configfile-{{ module }} +{% endfor %} diff --git a/states/systemd/kernelmap.yaml b/states/systemd/kernelmap.yaml new file mode 100644 index 0000000..40943f2 --- /dev/null +++ b/states/systemd/kernelmap.yaml @@ -0,0 +1,3 @@ +--- +Linux: + os: "linux" diff --git a/states/systemd/map.jinja b/states/systemd/map.jinja new file mode 100644 index 0000000..3f37ad9 --- /dev/null +++ b/states/systemd/map.jinja @@ -0,0 +1,14 @@ +{%- import_yaml "systemd/defaults.yaml" as default_settings -%} + +{%- import_yaml "systemd/kernelmap.yaml" as kernelmap %} +{%- import_yaml "systemd/osarchmap.yaml" as osarchmap %} + +{%- set defaults = salt['grains.filter_by'](default_settings, + default='systemd', + merge=salt['grains.filter_by'](osarchmap, grain='osarch', + merge=salt['grains.filter_by'](kernelmap, grain='kernel') + ) + ) +-%} + +{%- set systemd = salt['pillar.get']('systemd', default=defaults, merge=True) -%} diff --git a/states/systemd/osarchmap.yaml b/states/systemd/osarchmap.yaml new file mode 100644 index 0000000..05f0f25 --- /dev/null +++ b/states/systemd/osarchmap.yaml @@ -0,0 +1,24 @@ +--- +amd64: + arch: "amd64" + +x86_64: + arch: "amd64" + +386: + arch: "386" + +arm64: + arch: "arm64" + +aarch64: + arch: "arm64" + +armv6l: + arch: "arm" + +armv7l: + arch: "arm" + +armhf: + arch: "arm" diff --git a/states/systemd/templates/systemd_custom.conf.j2 b/states/systemd/templates/systemd_custom.conf.j2 new file mode 100644 index 0000000..c1f0e7d --- /dev/null +++ b/states/systemd/templates/systemd_custom.conf.j2 @@ -0,0 +1,6 @@ +{% for module, setting in settings.items() -%} +[{{ module }}] +{%- for key, value in setting.items() %} +{{ key }}={{ value }} +{%- endfor %} +{%- endfor %}