fun with pillars

- map distros to package names
- create users on saltlab minions
- ditch cowsay
- replace nginx with apache (and pull pkg name from pillar data)
This commit is contained in:
John Bowdre 2023-03-24 23:11:25 -05:00
parent 6ac3b8ad19
commit 2fb3b6e340
13 changed files with 40 additions and 27 deletions

11
srv/pillar/pkg/init.sls Normal file
View file

@ -0,0 +1,11 @@
pkgs:
{% if grains['os_family'] == 'RedHat' %}
apache: httpd
vim: vim-enhanced
{% elif grains['os_family'] == 'Debian' %}
apache: apache2
vim: vim
{% else %}
apache: apache
vim: vim
{% endif %}

4
srv/pillar/top.sls Normal file
View file

@ -0,0 +1,4 @@
base:
'*':
- users
- pkg

View file

@ -0,0 +1,6 @@
users:
jake: 1001
jason: 1002
john: 1003
jon: 1004
jordan: 1005

7
srv/salt/apache/init.sls Normal file
View file

@ -0,0 +1,7 @@
install_apache:
pkg.installed:
- name: {{ pillar['pkgs']['apache'] }}
service.running:
- require:
- pkg: {{ pillar['pkgs']['apache'] }}
- name: {{ pillar['pkgs']['apache'] }}

View file

@ -0,0 +1,3 @@
uninstall_apache:
pkg.removed:
- name: {{ pillar['pkgs']['apache'] }}

View file

@ -1,3 +0,0 @@
install_cowsay:
pkg.installed:
- name: cowsay

View file

@ -1,3 +0,0 @@
uninstall_cowsay:
pkg.removed:
- name: cowsay

View file

@ -1,6 +0,0 @@
nginx:
pkg.installed: []
service.running:
- require:
- pkg: nginx

View file

@ -1,3 +0,0 @@
nginx:
pkg.removed

View file

@ -3,7 +3,7 @@ base:
- vim
'roles:saltlab':
- match: grain
- cowsay
- users
'roles:web':
- match: grain
- nginx
- apache

5
srv/salt/users/init.sls Normal file
View file

@ -0,0 +1,5 @@
{% for user, uid in pillar.get('users', {}).items() %}
{{user}}:
user.present:
- uid: {{uid}}
{% endfor %}

View file

@ -1,10 +1,6 @@
install_vim:
pkg.installed:
{% if grains['os_family'] == 'RedHat'%}
- name: vim-enhanced
{% else %}
- name: vim
{% endif %}
- name: {{ pillar['pkgs']['vim'] }}
/etc/vimrc:
file.managed:

View file

@ -1,10 +1,6 @@
uninstall_vim:
pkg.removed:
{% if grains['os_family'] == 'RedHat'%}
- name: vim-enhanced
{% else %}
- name: vim
{% endif %}
- name: {{ pillar['pkgs']['vim'] }}
/etc/vimrc:
file.absent