CentOS 7
Sponsored Link

Salt : Basic Usage2016/10/08

 
This is the basic usage to execute commands from Salt Master to Salt Minion remotely.
  ⇒ salt [option] [target] [function] [arguments]
For description of all embeded functions, Refer to the official site.
  ⇒ https://docs.saltstack.com/en/latest/ref/modules/all/index.html
[1] It's possible to see functions with the command, too.
(many lines are output, so use less or more command to read)
[root@dlp ~]#
salt '*' sys.doc

'acl.delfacl:'

    Remove specific FACL from the specified file(s)

    CLI Examples:

        salt '*' acl.delfacl user myuser /tmp/house/kitchen
        salt '*' acl.delfacl default:group mygroup /tmp/house/kitchen

.....
.....
[2] It's possible to specify targets with various way.
# specify all Minions

# test.ping means that make sure Minions are acitive

[root@dlp ~]#
salt '*' test.ping

node02.srv.world:
    True
node01.srv.world:
    True

# specify a Minion "node01.srv.world"

# disk.usage means that make sure current disk usage

[root@dlp ~]#
salt 'node01.srv.world' disk.usage
node01.srv.world:
    ----------
    /:
        ----------
        1K-blocks:
            27740944
        available:
            26176776
        capacity:
            6%
        filesystem:
            /dev/mapper/centos-root
        used:
            1564168
.....
.....

# specify some Minions with List(comma separated)

# status.loadavg means that make sure load averages

[root@dlp ~]#
salt -L 'node01.srv.world,node02.srv.world' status.loadavg
node02.srv.world:
    ----------
    1-min:
        0.0
    15-min:
        0.05
    5-min:
        0.01
node01.srv.world:
.....
.....

# specify Minions with expression (example means "node00-99.srv.world")

# selinux.getenforce means that make sure SELinux operating mode

[root@dlp ~]#
salt -E 'node[0-9][0-9].srv.world' selinux.getenforce
node02.srv.world:
    Enforcing
node01.srv.world:
    Enforcing

# specify Minions which OS is CentOS with Grains Data

# grains.item kernelrelease means that make sure Kernel version from grains.item data

# Grains is the word used in Salt and which keeps Minions' OS data and others

[root@dlp ~]#
salt -G 'os:CentOS' grains.item kernelrelease

node01.srv.world:
    ----------
    kernelrelease:
        3.10.0-327.36.1.el7.x86_64
node02.srv.world:
    ----------
    kernelrelease:
        3.10.0-327.36.1.el7.x86_64

# specify multiple conditions with "C" option

# the follow specifies Minions which OS is CentOS and hostname is node01-node05

# cmd.run means that it executes commands

[root@dlp ~]#
salt -C 'G@os:CentOS and E@node0[1-5].srv.world' cmd.run 'uptime'

node02.srv.world:
     09:46:43 up 18 min,  0 users,  load average: 0.00, 0.01, 0.03
node01.srv.world:
     09:46:43 up 18 min,  0 users,  load average: 0.07, 0.05, 0.03
[3] It's also possible to specify target with Groups.
[root@dlp ~]#
vi /etc/salt/master
# line 12: uncomment

default_include: master.d/*.conf
[root@dlp ~]#
mkdir /etc/salt/master.d

[root@dlp ~]#
vi /etc/salt/master.d/nodegroups.conf
# create new

# group01 : specify List with "L@" (comma separated)

# group02 : specify node03-node05 with expression

# group03 : specify OS is CentOS

nodegroups:
  group01: 'L@node01.srv.world,node02.srv.world'
  group02: 'E@node0[3-5].srv.world'
  group03: 'G@os:CentOS'

[root@dlp ~]#
systemctl restart salt-master
# run to a target group01

# firewalld.list_services means that make sure allowed services by firewalld

[root@dlp ~]#
salt -N 'group01' firewalld.list_services

node01.srv.world:
    - dhcpv6-client
    - ssh
node02.srv.world:
    - dhcpv6-client
    - ssh
Matched Content