Salt: Difference between revisions

From DWIKI
 
(11 intermediate revisions by the same user not shown)
Line 8: Line 8:
*[https://techarena51.com/index.php/getting-started-with-saltstack/ Managing Linux server configs with the SaltStack]
*[https://techarena51.com/index.php/getting-started-with-saltstack/ Managing Linux server configs with the SaltStack]
*[https://github.com/saltstack/salt/wiki/Cheat-Sheet Cheat Sheet]
*[https://github.com/saltstack/salt/wiki/Cheat-Sheet Cheat Sheet]
*[https://github.com/harkx/saltstack-cheatsheet Cheat sheet 2]
*[https://blog.talpor.com/2014/07/saltstack-beginners-tutorial/ Salt - Beginners Tutorial]
*[https://blog.talpor.com/2014/07/saltstack-beginners-tutorial/ Salt - Beginners Tutorial]
*https://rizvir.com/articles/saltstack/
*https://rizvir.com/articles/saltstack/
Line 13: Line 14:
=Tools=
=Tools=
*[https://github.com/saltstack/salt-vim Vim bundle for salt]
*[https://github.com/saltstack/salt-vim Vim bundle for salt]
*[https://github.com/tinyclues/saltpad Saltpad GUI]


=Writing custom state modules=
=Writing custom state modules=
Line 24: Line 26:


=FAQ=
=FAQ=
=Apply just one part of role=
 
==test run==
salt "*" state.apply test=True
 
==check if minion has packages to update==
salt '*' cmd.run "yum check-update > /dev/null;echo $?"
==Add minion to master==
On client:
set master in /etc/salt/minion, maybe also define some role(s)
restart salt-minion
On master:
salt-key
if hostnamed indeed shows up,
salt-key -a hostname
 
and then
salt hostname state.highstate
 
 
==Remove minion from master==
 
==single line per minion==
salt "*" grains.item nodename group os osrelease --out=txt
(for a list of items use grains.items
 
==Apply just one part of role==
Assuming you have foo.sls in roles/
Assuming you have foo.sls in roles/
  salt '*' state.apply roles.myrole.foo
  salt '*' state.apply roles.myrole.foo
Line 40: Line 68:
==Rendering SLS 'base:roles.foo.bar' failed: Jinja variable 'dict object' has no attribute 'blergh'==
==Rendering SLS 'base:roles.foo.bar' failed: Jinja variable 'dict object' has no attribute 'blergh'==
Unless you made a typo, your minion probably doesn't have access in pillar
Unless you made a typo, your minion probably doesn't have access in pillar
==multiple parameters==
salt '*' param1,param2 arg1,arg2
==define a grain on minions==
salt minion1 grains.setvalue role foobar
==set role from init.sls==
roles:
  grains.present:
  -value: somerolename

Latest revision as of 12:00, 6 October 2016

Salt Configuration Management

Links

Tools

Writing custom state modules

Syntax checking etc:

python -m py__compile mymodule.py
saltutil.sync_states

FAQ

test run

salt "*" state.apply test=True

check if minion has packages to update

salt '*' cmd.run "yum check-update > /dev/null;echo $?"

Add minion to master

On client:

set master in /etc/salt/minion, maybe also define some role(s)
restart salt-minion

On master:

salt-key

if hostnamed indeed shows up,

salt-key -a hostname

and then

salt hostname state.highstate


Remove minion from master

single line per minion

salt "*" grains.item nodename group os osrelease --out=txt

(for a list of items use grains.items

Apply just one part of role

Assuming you have foo.sls in roles/

salt '*' state.apply roles.myrole.foo

Change minion hostname

On minion:

  • hostname new.host.name
  • update /etc/hostname
  • update /etc/salt/minion_id
  • restart salt-minion

On master: rename the key ( /srv/salt/pki/master/minions/old.host.name )

Rendering SLS 'base:roles.foo.bar' failed: Jinja variable 'dict object' has no attribute 'blergh'

Unless you made a typo, your minion probably doesn't have access in pillar

multiple parameters

salt '*' param1,param2 arg1,arg2


define a grain on minions

salt minion1 grains.setvalue role foobar


set role from init.sls

roles:
 grains.present:
 -value: somerolename