Build & Run

docker build -t salt-stack:2017.7.6 .
docker run -it salt-stack:2017.7.6 /bin/bash

Configs & Resources

Run Salt Master, Salt API, Salt Minion

cd /root
./start_salt_stack.sh

Test Native Salt Stack Module

salt '*' cmd.run 'whoami' runas=test
salt -L 'minion1, minion2' cmd.run 'echo TEST'
salt -G 'os:centos' cmd.run 'echo test'
salt '*' grains.ls
salt '*' grains.item os osrelease oscodename
salt minion2 pkg.install httpd

Detailed documentation : https://docs.saltstack.com/en/latest/ref/modules/all/index.html

Test Native Salt API

  • Get an authentication token
curl -XPOST localhost:32001/login \
  -H 'Content-Type: application/json' \
  -d '
{
 "eauth": "pam",
 "username":"test",
 "password":"test"
}
'
{
 "return": [
  {
   "perms": [".*", "@runner"],
   "start": 1526355255.599695,
   "token": "[TOKEN]",
   "expire": 1526398455.599696,
   "user": "test",
   "eauth": "pam"
  }
 ]
}
  • Run 'local' client through API
curl -XPOST localhost:32001/run \
  -H 'Content-Type: application/json' \
  -H 'X-Auth-Token: [TOKEN]' \
  -d '
{
 "tgt_type": "glob",
  "tgt": "*",
  "client":"local",
  "fun": "cmd.run",
  "arg":["echo whoami", "runas=test"]
}
'
  • Run 'local' client, 'list' tgt through API
curl -XPOST localhost:32001/run \
  -H 'Content-Type: application/json' \
  -H 'X-Auth-Token: [TOKEN]' \
  -d '
{
 "tgt_type": "list",
 "tgt": ["minion1", "minion2"],
 "client":"local",
 "fun": "cmd.run",
 "arg":["echo whoami", "runas=test"]
}
'
  • Run 'local_async' client, 'list' tgt through API
curl -XPOST localhost:32001/run \
  -H 'Content-Type: application/json' \
  -H 'X-Auth-Token: [TOKEN]' \
  -d '
{
 "tgt_type": "list",
 "tgt": ["minion1", "minion2"],
 "client":"local_async",
 "fun": "cmd.run",
 "arg":["echo whoami", "runas=test"]
}
'
{
 "return": [
  {
   "jid": "[JID]",
   "minions": ["minion1", "minion2"]
  }
 ]
}
curl -XGET localhost:32001/jobs/[JID] \
  -H 'Content-Type: application/json' \
  -H 'X-Auth-Token: [TOKEN]'

Salt Stack Custom Module, State, Pillar

Sync to Salt Minion

  • Sync 'base' saltenv
salt '*' saltutil.sync_modules
salt '*' saltutil.sync_states
salt '*' saltutil.refresh_pillar
  • Sync 'other' saltenv
salt '*' saltutil.sync_modules saltenv=other
salt '*' saltutil.sync_states saltenv=other

Test Salt Stack Custom Module

salt '*' nhn.test
salt '*' nhn.test_param d=123 a b c
salt '*' nhn.dunder_salt test
salt '*' nhn.dunder_pillar

Test Salt Stack Custom Pillar

salt '*' pillar.get location
salt '*' pillar.get pkgs
salt '*' pillar.get pkgs:apache
salt '*' pillar.raw

Test Salt Stack Custom State

salt '*' state.apply state_test.run_cmd
salt '*' state.apply state_test.run_cmd pillar='{"pkgs":{"apache":"parameterized pillar"}}'
salt '*' state.apply state_test.apache
salt minion1 schedule.list
salt '*' state.apply state_test.monitor
salt '*' schedule.list
salt minion1 schedule.delete write_to_file

tail -f /tmp/scheduled_writing

Test Salt Stack Custom Module by saltenv

salt '*' nhn.test
salt '*' saltutil.sync_modules saltenv=dev
salt '*' nhn.test