Initialize saltstack minion

Many people will struggle between saltstack and ansible. Whether saltstack is good or ansible is good. First of all, we should realize the advantages and disadvantages between them.
Saltstack is based on zero mq messaging system, which can achieve high concurrency (theoretically, a salt-master can concurrently run 1000 minions in a short time), while ansible is based on ssh. Every request needs to establish SSH connection first, so it is inefficient, but it does not need to install the client, and saltstack needs to install the client, namely saltstack minion. This article encloses How to deploy minion client quickly around saltstack

First of all, suppose a scenario, we bought a cloud host in a cloud (ALI cloud / cloud cloud, and other cloud manufacturers), which hosts the key of salt-master. How can we make this host (minion) managed by salt-master? We can write a script specifically to initialize minon, and the script must be executed on the salt-master machine.

Current environment
IP Address Host Name Role
10.0.0.61 m01 salt-master
10.0.0.8 web01 newly initialized host

1. The minion initialization script is as follows

#!/bin/bash
Host=$1
sshpass='/usr/bin/sshpass'

# Judging the number of script parameters
if [ $# -ne 1 ];then
    echo "Please input use args {host}"
    exit 1
fi

# First determine whether the target host is reachable
ping -c 3 -W 1 ${Host} >/dev/null 2>&1
if [ $? -ne 0 ];then
   echo "Target host ${Host} Unreachable"
   exit 1
else
   echo "Target host ${Host} accessible"
fi

# Add salt rpm source
DATA1='ls /etc/yum.repos.d/salt-py3-*.repo'
${sh3pass} ssh ${Host} -o StrictHostKeyChecking=no "${DATA1}" >/dev/null 2>&1
if [ $? -eq 0 ];then
   echo "salt-minion rpm Package installed"
   exit 1
else
   echo "salt-minion rpm Package not installed"
fi

DATA2='sudo yum install -y https://repo.saltstack.com/py3/redhat/salt-py3-repo-2019.2.el7.noarch.rpm'
${shpass}  ssh ${Host} -o StrictHostKeyChecking=no "${DATA2}"  >/dev/null 2>&1
if [ $? -eq 0 ];then
    echo "Add to salt rpm source ->${DATA2} Success"
else
    echo "Add to salt rpm source ->${DATA2} fail"
    exit 1
fi
# Install salt-minion
DATA3='yum install -y salt-minion'
${shpass}  ssh ${Host} -o StrictHostKeyChecking=no "${DATA3}"  >/dev/null 2>&1
if [ $? -eq 0 ];then
    echo "install salt-minion ->${DATA3} Success"
else
    echo "install salt-minion ->${DATA3} fail"
    exit 1
fi

# Modify the salt-minion configuration file
DATA4="sed -i 's@^#master:.*@master: 10.0.0.61@g' /etc/salt/minion"
echo "Modify configuration files ${DATA4}"
${shpass}  ssh ${Host} -o StrictHostKeyChecking=no "${DATA4}"  >/dev/null 2>&1

if [ $? -eq 0 ];then
    echo "modify salt-minion configuration file ->${DATA4} Success"
else
    echo "modify salt-minion configuration file ->${DATA4} fail"
    exit 1
fi
# Restart salt-minion
DATA5='systemctl restart salt-minion'
${shpass}  ssh ${Host} -o StrictHostKeyChecking=no "${DATA5}" >/dev/null 2>&1

if [ $? -eq 0 ];then
    echo "restart salt-minion ->${DATA5} Success"
else
    echo "restart salt-minion ->${DATA5} fail"
    exit 1
fi

2. After executing the script

Keywords: Linux saltstack ssh RPM ansible

Added by php_blob on Sun, 06 Oct 2019 05:54:39 +0300