Initialization saltstack minion

Many people will tangle between saltstack and ansible a problem in the end is good ,, saltstack, or good ansible, first of all, we need to realize the advantages and disadvantages between them,
saltstack it is zero mq messaging system based, to achieve high concurrency (theoretically, a salt-master may be complicated by a thousand Minion, executable completed in a short time), and is based ansible ssh, ssh need to establish a connection for each request, it is inefficient, but it does not require installation client, and saltstack need to install client that is saltstack minion, the article how to quickly deploy minion clients around saltstack

First, suppose a scene, we have a cloud (cloud Ali / Tencent cloud, clouds and other manufacturers) and bought a cloud host (the host to bind the key salt-master's), to how to get this host (minion), to be managed by salt-master? We could write a special script to initialize minon, and the script must be executed on the salt-master machine

Initialization saltstack minion

The current environment
IP address of the host name of the role
10.0.0.61 Salt-M01 Master
10.0.0.8 web01 new initialization of the host

1, minion initialization script as follows

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

# 判断脚本传参个数
if [ $# -ne 1 ];then
    echo "Please input use args {host}"
    exit 1
fi

# 先判断目标主机是否可达
ping -c 3 -W 1 ${Host} >/dev/null 2>&1
if [ $? -ne 0 ];then
   echo "目标主机${Host} 不可达"
   exit 1
else
   echo "目标主机${Host} 可达"
fi

# 添加salt rpm源
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包已安装"
   exit 1
else
   echo "salt-minion rpm包未安装"
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 "添加salt rpm源 ->${DATA2} 成功"
else
    echo "添加salt rpm源 ->${DATA2} 失败"
    exit 1
fi
# 安装salt-minion
DATA3='yum install -y salt-minion'
${shpass}  ssh ${Host} -o StrictHostKeyChecking=no "${DATA3}"  >/dev/null 2>&1
if [ $? -eq 0 ];then
    echo "安装salt-minion ->${DATA3} 成功"
else
    echo "安装salt-minion ->${DATA3} 失败"
    exit 1
fi

# 修改salt-minion配置文件
DATA4="sed -i 's@^#master:.*@master: 10.0.0.61@g' /etc/salt/minion"
echo "修改配置文件 ${DATA4}"
${shpass}  ssh ${Host} -o StrictHostKeyChecking=no "${DATA4}"  >/dev/null 2>&1

if [ $? -eq 0 ];then
    echo "修改salt-minion配置文件 ->${DATA4} 成功"
else
    echo "修改salt-minion配置文件 ->${DATA4} 失败"
    exit 1
fi
# 重启salt-minion
DATA5='systemctl restart salt-minion'
${shpass}  ssh ${Host} -o StrictHostKeyChecking=no "${DATA5}" >/dev/null 2>&1

if [ $? -eq 0 ];then
    echo "重启salt-minion ->${DATA5} 成功"
else
    echo "重启salt-minion ->${DATA5} 失败"
    exit 1
fi

2, after executing script
Initialization saltstack minion

Guess you like

Origin blog.51cto.com/12643266/2437109