...phew
# /srv/salt/top.sls
base:
'*':
- default
'db*':
- mariaDB
development:
'app*':
- mailcatcher
production:
'app*':
- smtp
# Short notation
apache2:
pkg.installed
# Verbose
install_apache:
pkg:
- installed
- name: apache2
# /srv/salt/top.sls
base:
'*':
- apache
Top file
# /srv/salt/apache.sls OR /srv/salt/apache/init.sls
apache:
pkg.installed:
- name: apache2
State configuration
# /srv/pillar/top.sls
base:
'os:Debian':
- match: grain
- debian_packages
'os:RedHat':
- match: grain
- redhat_packages
Pillar top file
# /srv/salt/apache.sls
apache:
pkg.installed:
- name: {{ pillar['pkgs']['apache'] }}
State configuration
# /srv/pillar/debian_packages.sls
pkgs:
apache: apache2
# /srv/pillar/redhat_packages.sls
pkgs:
apache: httpd
Pillars configuration
# /srv/salt/top.sls
base:
'*':
- website
Top file
# /srv/salt/website/init.sls
include:
- apache.install
extend:
apache:
service:
- running
- enable: True
Website
# /srv/salt/apache/install.sls
apache:
pkg.installed:
- name: {{ salt['pillar.get']('pkgs:apache', 'apache2') }}
Apache
# /srv/salt/nginx/init.sls
nginx:
pkgrepo:
- managed
- name: deb http://nginx.org/packages/ubuntu/ trusty nginx
- key_url: http://nginx.org/keys/nginx_signing.key
Package repository
service:
- running
- watch:
- pkg: nginx
- file: /etc/nginx/nginx.conf
Configure service
pkg:
- installed
- require:
- pkgrepo: nginx
Install package
/etc/nginx/nginx.conf:
file:
- managed
# /srv/salt/nginx/nginx.conf.jinja
- source: salt://nginx/nginx.conf.jinja
- user: root
- group: root
- mode: 644
- template: jinja
Manage file
# /srv/salt/nginx/nginx.conf.jinja
user www-data;
worker_processes {{ 2 * grains['num_cpus'] }};
pid /run/nginx.pid;
Managed file template
master $ salt '*' state.highstate
masterless-minion $ salt-call --local state.highstate
Marin Crnković
@anorgan
https://joind.in/13779