split up common

This commit is contained in:
2023-12-22 15:58:35 -05:00
parent 92334f5aa1
commit c18d6cdb21
10 changed files with 30 additions and 62 deletions

View File

@@ -1,3 +0,0 @@
include:
- common.packages
- common.vimrc

View File

@@ -1,43 +0,0 @@
{% set common = salt['grains.filter_by']({
'Debian': {
'packages': [
'vim'
],
},
'RedHat': {
'packages': [
'vim-enhanced'
],
},
}) %}
{% set distro = salt['grains.filter_by']({
'Fedora': {
'packages': [
'pcp-system-tools'
]
},
'default': {
'packages': [
'dstat'
]
}
}, grain='os') %}
{% set defaults = {
'packages': [
'iotop',
'nano',
'screen',
'git'
]
} %}
{# custom deep merge #}
{% for key in distro.keys() %}
{% do common[key].extend(distro[key]) %}
{% endfor %}
{% for key in defaults.keys() %}
{% do common[key].extend(defaults[key]) %}
{% endfor %}

View File

@@ -1,11 +0,0 @@
{% from "common/map.jinja" import common with context %}
'base_packages':
pkg.installed:
- pkgs:
{% for package in common['packages'] %}
- {{ package|yaml_encode }}
{% endfor %}
{% for package in salt.pillar.get('packages', []) %}
- {{ package|yaml_encode }}
{% endfor %}

8
cron/init.sls Normal file
View File

@@ -0,0 +1,8 @@
{% from "cron/map.jinja" import cron with context %}
cron:
pkg.installed:
- name: {{ cron.pkg }}
service.running:
- name: {{ cron.svc }}
- reload: {{ cron.reload | yaml_encode }}

4
cron/map.jinja Normal file
View File

@@ -0,0 +1,4 @@
{% set cron = salt['grains.filter_by']({
'Debian': {'pkg': 'cron', 'svc': 'cron', 'reload': false},
'RedHat': {'pkg': 'cronie', 'svc': 'crond', 'reload': true},
}) %}

5
packages/init.sls Normal file
View File

@@ -0,0 +1,5 @@
{% for name, state in salt.pillar.get("packages", {}) %}
{{ "pkg_%s" | format(name) }}:
pkg.{{ state }}:
- name: {{ name | yaml_encode }}
{% endfor %}

View File

@@ -1,7 +1,9 @@
{{ saltenv }}:
'*':
- salt
- common
- cron
- vim
- packages
- users
{% if salt.pillar.get('restic:client', None) is not none
or salt.pillar.get('restic:server', None) is not none %}

View File

@@ -1,4 +1,7 @@
{% from "common/map.jinja" import common with context %}
{% from "vim/map.jinja" import vim with context %}
{{ vim.pkg }}:
pkg.installed: []
/root/.vimrc:
file.managed:
@@ -14,5 +17,4 @@
- user: {{ user }}
- group: {{ user }}
- mode: 644
{% endfor %}

4
vim/map.jinja Normal file
View File

@@ -0,0 +1,4 @@
{% set vim = salt.grains.filter_by({
'Debian': {'pkg': 'vim'},
'RedHat': {'pkg': 'vim-enhanced'},
}) %}