Skip to content
This repository has been archived by the owner on Oct 12, 2020. It is now read-only.

05. SaltStack hello world

Khelil Sator edited this page Jul 17, 2017 · 12 revisions

Salt-master:

Install Salt on a Ubuntu VM:

# pip install git+https://github.com/saltstack/[email protected]

Salt version:

# salt --version
salt 2017.7.0-202-g3c8dee0 (Nitrogen)

salt-master configuration file:

The salt-master is configured via the master configuration file
The configuration file for the salt-master is located at /etc/salt/master by default.
Example:

# more /etc/salt/master 
file_roots:
 base:
  - /srv/salt

pillar_roots:
 base:
  - /srv/pillar

engines_dirs: 
  - /srv/engines

engines: 
  - junos_syslog: 
      port: 516

reactor:
  - 'jnpr/syslog/*/UI_COMMIT_COMPLETED':
        - /srv/reactor/on_commit.sls

nodegroups: 
 group1: 'L@ex4200-7,vqfx01'
 group2: 
  - minion_1
  - ex4200-7
 group3: 'G@os_family:junos or minion_1'

Get the Salt master ip address (you will need it for the minions):

# ifconfig ens33 | grep "inet addr"
          inet addr:192.168.233.17  Bcast:192.168.233.255  Mask:255.255.255.0

Start the salt-master:

to start it with a debug log level, use this command:

# salt-master -l debug

if you prefer to run the salt-master as a daemon, use this command:

# salt-master -d

Salt-minion:

Install salt on another Ubuntu VM:

# pip install git+https://github.com/saltstack/[email protected]

Salt version:

# salt --version
salt 2017.7.0-210-gc89cd2a (Nitrogen)

salt-minion configuration file:

the salt-minion is configured via the minion configuration file.
By default, the salt-minion configuration is /etc/salt/minion.
192.168.233.17 is the master ip address.

# more /etc/salt/minion
master: 192.168.233.17
id: minion_1

Start the salt-minion:

to start it with a debug log level, use this command:

# salt-minion -l debug

if you prefer to run the salt-minion as a daemon, use this command:

# salt-minion -d

keys:

On the master, accept the key:

# salt-key -L
Accepted Keys:
Denied Keys:
Unaccepted Keys:
minion_1
Rejected Keys:
# salt-key -a minion_1 -y
The following keys are going to be accepted:
Unaccepted Keys:
minion_1
Key for minion minion_1 accepted.
# salt-key -L
Accepted Keys:
minion_1
Denied Keys:
Unaccepted Keys:
Rejected Keys:

Salt help:

# salt --help

test if the minion is up and responding to the master:

test.ping documentation:

# sudo salt "minion_1" sys.doc test.ping
test.ping:

    Used to make sure the minion is up and responding. Not an ICMP ping.

    Returns ``True``.

    CLI Example:

        salt '*' test.ping
    

This command also returns the documentation:

# sudo salt "minion_1" test.ping -d
test.ping:

    Used to make sure the minion is up and responding. Not an ICMP ping.

    Returns ``True``.

    CLI Example:

        salt '*' test.ping
    

test.ping execution:

# sudo salt "minion_1" test.ping
minion_1:
    True

This command also displays the job id:

# sudo salt "minion_1" test.ping -v
Executing job with jid 20170626143114314899
-------------------------------------------

minion_1:
    True

Execute Salt modules on the master:

cmd module:

# salt "minion_1" cmd.run "pwd"
minion_1:
    /home/ksator

disk module:

disk module documentation:

# sudo salt "minion_1" sys.doc disk

disk.usage documentation:

# sudo salt "minion_1" sys.doc disk.usage
disk.usage:

    Return usage information for volumes mounted on this minion

    CLI Example:

        salt '*' disk.usage

disk.usage execution:

# sudo salt "minion_1" disk.usage

file module:

on the master:

# sudo salt "minion_1" file.touch "/tmp/test.txt"
minion_1:
    True
# sudo salt "minion_1" file.write "/tmp/test.txt" "hello"
minion_1:
    Wrote 1 lines to "/tmp/test.txt"

on the minion:

# more /tmp/test.txt 
hello