Salt Cheat Sheet
Salt Cheat Sheet
http://www.xenuser.org/saltstack-cheat-sheet/
https://github.com/saltstack/salt/wiki/Cheat-Sheet
.
Minions
Minion status
You can also use several commands to check if minions are alive and kicking but I
prefer manage.status/up/down.
salt-run manage.status #
What is the status of all my minions? (both up and down)
salt-run manage.up #
Any minions that are up?
salt-run manage.down #
Any minions that are down?
salt-run manage.alived #
Show all alive minions
salt '*' test.version #
Display salt version
salt '*' test.ping #
Use test module to check if minion is up and responding.
#
(Not an ICMP ping!)
Target minion with state files
Apply a specific state file to a (group of..) minion(s). Do not use the .sls
extension. (just like in the state files!)
salt '*' grains.item os # Show the value of the OS grain for every minion
salt '*' grains.item roles # Show the value of the roles grain for every minion
Manipulate grains.
salt 'minion-x-*' system.reboot # Let's reboot all the minions that match minion-
x-*
salt '*' status.uptime # Get the uptime of all our minions
Packages
salt '*' pkg.version bash # get current version of the bash package
salt '*' pkg.install bash # install or upgrade bash package
salt '*' pkg.install bash refresh=True # install or upgrade bash package but
# refresh the package database before
installing.
Check status of a service and manipulate services
wget -O - https://repo.saltstack.com/apt/ubuntu/ubuntu14/latest/SALTSTACK-GPG-
KEY.pub | sudo apt-key add -
echo 'deb http://repo.saltstack.com/apt/ubuntu/ubuntu14/latest trusty main' | sudo
tee -a /etc/apt/sources.list
sudo apt-get update
# Master installation
apt-get install salt-master
# Minion installation
apt-get install salt-minion
#Examples:
salt '*' sys.doc status
salt '*' sys.doc pkg
salt '*' sys.doc network
salt '*' sys.doc system
salt '*' sys.doc cloud
# Examples:
salt '*' sys.doc auth django
salt '*' sys.doc sdb sqlite3
SaltStack Modules And Functions
# Joining
salt -C 'webserv* and G@os:Debian or E@web-dc1-srv.*' test.ping
salt -C '( ms-1 or G@id:ms-3 ) and G@id:ms-3' test.ping
# Excluding
salt -C 'not web-dc1-srv' test.ping
Upgrades & Versions
#
# Listing upgrades
salt '*' pkg.list_upgrades
# Upgrading
salt '*' pkg.upgrade
# Installation
salt '*' pkg.install apache2
# Removing package(s)
salt '*' pkg.remove vim
# Purging package(s)
salt '*' pkg.purge apache2 mysql-server
# Reboot
salt '*' system.reboot
#Uptime
salt '*' status.uptime
Using Grains
# Syncing grains
salt '*' saltutil.sync_grains
# Grains have values that could be called via �grains.get <grain_name>� (path is
the name of a grain)
salt '*' grains.get path
Syncing Data
# Syncing grains
salt '*' saltutil.sync_grains
# Apache example
# Get hostname
salt '*' network.get_hostname
# Test connectivity
salt '*' network.connect google-public-dns-a.google.com port=53 proto=udp timeout=3
# Execute dig
salt '*' network.dig eon01.com
#
Job Management
# List active jobs
salt-run jobs.active
# List multiple information about the job with the id:20151101225221651308 like the
result output
salt-run jobs.lookup_jid 20151101225221651308
# Starting 20 minions
wget https://raw.githubusercontent.com/saltstack/salt/develop/tests/minionswarm.py;
python minionswarm.py -m 20 --master salt-master;
State Declaration Structure
# Source: https://docs.saltstack.com/en/latest/ref/states/highstate.html#state-
declaration
# Standard declaration
<ID Declaration>:
<State Module>:
- <Function>
- <Function Arg>
- <Function Arg>
- <Function Arg>
- <Name>: <name>
- <Requisite Declaration>:
- <Requisite Reference>
- <Requisite Reference>
Initial Configuration
In /etc/salt/master delete all the entries, in the beginning you only need the
following:
interface: 0.0.0.0
max_open_files: 100000
file_roots:
base:
- /salt/states/base
Minion configuration /etc/salt/minion, the bare minimum:
master: master_ip
#id:
Minions
Minion status
You can also use several commands to check if minions are alive and kicking but I
prefer manage.status/up/down.
salt-run manage.status #
What is the status of all my minions? (both up and down)
salt-run manage.up #
Any minions that are up?
salt-run manage.down #
Any minions that are down?
salt '*' test.ping #
Use test module to check if minion is up and responding.
#
(Not an ICMP ping!)
Target minion with state files
Apply a specific state file to a (group of..) minion(s). Do not use the .sls
extension. (just like in the state files!)
nodegroups:
deb: 'debian8, ubuntu1404'
rpm: 'centos7, centos6'
salt '*' grains.item os # Show the value of the OS grain for every minion
salt '*' grains.item roles # Show the value of the roles grain for every minion
Manipulate grains.
salt 'minion-x-*' system.reboot # Let's reboot all the minions that match minion-
x-*
salt '*' status.uptime # Get the uptime of all our minions
Packages
salt '*' pkg.version bash # get current version of the bash package
salt '*' pkg.install bash # install or upgrade bash package
salt '*' pkg.install bash refresh=True # install or upgrade bash package but
# refresh the package database before
installing.
Check status of a service and manipulate services
Minion Overview
Targetting Minions
Job Management
States
Grains