Tuesday, December 29, 2015

SaltStack Quick start

Reference: This blog post is prepared by referring the book "Salt Essentials; Craig Sebenik & Thomas Hatch; Oreilly publications"

Installation

  • yum list salt salt-master salt-minion
  • yum install -y salt salt-minion   #Install these 2 packages on minions & master
  • yum install -y salt-master   # Install this package on master

Configuring master IP/DNS in minions

The basic minion configuration is located in /etc/salt/minion.You need to configure each minion with the DNS name or IP address of your Salt master. 

The default Salt master configured is

$ grep '#master:' /etc/salt/minion
#master: salt

This needs to be changed to our master IP or DNS name


$ vi /etc/salt/minion 
master 10.0.2.15

Starting Daemons

  • service salt-master start   # start this only on master
  • service salt-minion start  # start this both in master & minions

What is my minion-id?

  • cat /etc/salt/minion_id    #vagrant-centos65.vagrantup.com

What are the publish port and the return port numbers?

  • 4505 and 4506 respectively

Where is the minion log file?

  • /var/log/salt/minion

Key management

  • salt-key   
Without any arguments, salt-key will simply list all of the states and then each  minion in each of those states.

Example:
$ salt-key
Accepted Keys:
Denied Keys:
Unaccepted Keys:
vagrant-centos65.vagrantup.com
Rejected Keys:
  • salt-key --list=unaccepted  # view just the keys in the unaccepted state

Accepting a key

  • salt-key --accept=vagrant-centos65.vagrantup.com --yes
  • salt-key --accept-all
 To print fingerprints of each key file
  • salt-key --finger ubuntu-14.04-amd64-vbox
  • salt-key --finger-all
 To view the fingerprint of the key on the minion itself
  • salt-call --local key.finger
  • salt-call --local key.finger_master # to view fingerprint of the master
 If keys gets screwed up, just do
  • salt-key --delete-all   # on master
  • service salt-minion restart  # on all minions including master
  • salt-key --accept-all
The keys are stored in
  • /etc/salt/pki/master
  • /etc/salt/pki/minion

salt-call: Execution on the Minion

  • salt-call test.ping   # salt-call will run an execution module or enforce a state, but only on localhost.
  • salt-call --log-level=debug disk.percent /    # debug mode
These commands will still attempt to return data to the master via the return port (4506). If you truly want to only run locally, you just have to add the --local flag. This will ignore returning data to the master
  • salt-call --local test.ping

salt

  • Format:   salt target command
  • salt vagrant-centos65.vagrantup.com test.ping       #Target is Minion ID
  • salt * test.ping                              # Target is Glob
  • salt -L centos65-minion,ubuntu-14.04-amd64-vbox test.ping     # Target is List (-L)
  • salt 'ubun*' test.ping       # Glob
  • salt -E 'minion(1|2)\.example' test.ping     # Regular expression (-E)
  • salt -G 'os:CentOS' test.ping       # Grains (-G)
  • salt -G 'os:ubuntu' test.ping    # Grains (-G)
  • salt -C 'centos* or G@os:Ubuntu' test.ping    # Compound (-C)

salt-run: Coordination of Jobs on the Master

Say you want to deploy a new application to 10 hosts, but you only want to take one down at a time. When you use the salt command with a target set of minions, the command is sent asynchronously to every minion. But if you want to run a command sequentially across many minions, a runner can help.The salt-run command is a master-only command. It does not take a target set of minions.
  • salt-run manage.up
[root@vagrant-centos65 ~]# salt-run manage.up
- vagrant-centos65.vagrantup.com

This particular module, manage.up, uses the test.ping execution module, to determine whether a minion is healthy.

Difference between Modules and Functions

An execution module is actually a collection of execution functions. You run specific execution functions on a minion. For example, the test execution module has a function called ping. So, you run the test.ping execution function on a minion. Specifically, an execution module is a Python file. Each public method defined in that Python file is exposed as an execution function. Again, in our example, when you call test.ping, Salt looks for a file called test.py and then for a public function called ping inside that file.

No comments: