一键部署Saltstack脚本

最近一批新机器需要安装Saltstack,由于操作系统版本之繁杂,涉及到的问题之多,索性写了个脚本,一键运行安装,解决所有操作系统遇到的问题,省去重复工作的时间。

#!/bin/bash
HOSTNAME=$(hostname)
HOST_IP=$(ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:"| awk "NR==1")
SYS_VERSION=$(cat /etc/issue)
if [[ $SYS_VERSION =~ "SUSE" ]];then
  :;
else
  SYS_VER=$(cat /etc/redhat-release)
fi
DIR=$(pwd)
function common(){
   cd /etc/yum.repos.d/
   yum clean all
   yum makecache
   yum install salt-minion
   cd $DIR
   wget http://xxxxxx/mirrors/saltstack/yum/redhat/6/x86_64/minion
   cp minion /etc/salt/minion
   sed -i "s/client_ehp4/${HOSTNAME}_${HOST_IP}/g" /etc/salt/minion
   service salt-minion start

}
if [[ $SYS_VERSION =~ "SUSE" ]];then
  :;
else
  cd /etc/yum.repos.d
  mkdir backup
  mv *.repo backup/
  wget http://xxxxxx/mirrors/saltstack/yum/redhat/6/x86_64/salt-2018.3.repo
fi
if [[ $SYS_VER =~ "Red Hat" ]]; then
  if [[ $SYS_VER =~ "6.5" ]]; then
    cd $DIR
    rpm -qa|grep yum|xargs rpm -e --nodeps
    rpm -e python-urlgrabber --nodeps
    wget http://xxxxxxx/mirrors/rhel/6.5/yum_install_rpm/python-urlgrabber-3.9.1-11.el6.noarch.rpm
    wget http://xxxxxxx/mirrors/rhel/6.5/yum_install_rpm/yum-plugin-fastestmirror-1.1.30-41.el6.noarch.rpm
    wget http://xxxxxxx/mirrors/rhel/6.5/yum_install_rpm/yum-metadata-parser-1.1.2-16.el6.x86_64.rpm
    wget http://xxxxxxx/mirrors/rhel/6.5/yum_install_rpm/yum-3.2.29-81.el6.centos.noarch.rpm
    rpm -ivh python-urlgrabber-3.9.1-11.el6.noarch.rpm yum-plugin-fastestmirror-1.1.30-41.el6.noarch.rpm yum-metadata-parser-1.1.2-16.el6.x86_64.rpm yum-3.2.29-81.el6.centos.noarch.rpm
    common
  elif [[ $SYS_VER =~ "7.2" ]] || [[ $SYS_VER =~ "7.0" ]]; then
    cd /software
    wget http://xxxxxxx/mirrors/rhel/7/saltstack/saltstack-rhel7.repo
    mv saltstack-rhel7.repo /etc/yum.repos.d/
    rm -rf saltstack-rhel7.repo
    common
  fi
elif [[ $SYS_VER =~ "CentOS" ]];then
  if [[ $SYS_VER =~ "7.6" ]] || [[ $SYS_VER =~ "7.3" ]];then
    cd /software
    wget http://xxxxxxx/mirrors/rhel/7/saltstack/saltstack-rhel7.repo
    mv saltstack-rhel7.repo /etc/yum.repos.d/
    rm -rf saltstack-rhel7.repo
    common
  elif [[ $SYS_VER =~ "6.5" ]];then
    common
  fi
elif [[ $SYS_VER =~ "SUSE Linux Enterprise Server 11 SP2" ]]  || [[ $SYS_VERSION =~ "SUSE Linux Enterprise Server 11 SP2" ]];then
  zypper addrepo http://xxxxxxx//mirrors/saltstack/opensuse/SLE_11_SP4 SLE_11_SP4
  zypper addrepo http://xxxxxxx//mirrors/SLES-11-SP2 SLE-11-SP2
  zypper refresh
  cd $DIR
  wget http://xxxxxxx/mirrors/python-requests-2.12.4-2.1.x86_64.rpm
  rpm -ivh python-requests-2.12.4-2.1.x86_64.rpm
  zypper install salt-minion
  cd /usr/lib64/python2.6/site-packages/salt/config/
  sed -i "s/'multiprocessing': True/'multiprocessing': False/g" __init__.py
  cd $DIR
  wget http://xxxxxxx/mirrors/saltstack/yum/redhat/6/x86_64/minion
  mv minion /etc/salt/minion
  sed -i "s/client_ehp4/${HOSTNAME}_${HOST_IP}/g" /etc/salt/minion
  echo 'xxx.xxx.xxx    xxx.com.cn' >> /etc/hosts
  echo 'xxx.xxx.xxx    xxx.com.cn'>> /etc/hosts
  service salt-minion start
else
  zypper addrepo http://xxxxxxx/mirrors/saltstack/opensuse/SLE_12_SP2/ SLE_12_SP2
  zypper addrepo http://xxxxxxx/mirrors/saltstack/dev/opensuse/SLE_12_SP1 SLE_12_SP1_dev
  zypper refresh
  zypper install salt-minion
  cd $DIR
  wget http://xxxxxxx/mirrors/saltstack/yum/redhat/6/x86_64/minion
  mv minion /etc/salt/minion
  sed -i "s/client_ehp4/${HOSTNAME}_${HOST_IP}/g" /etc/salt/minion
  service salt-minion start
fi

 

你可能感兴趣的:(Shell,自动化运维,saltstack)