Salt-ssh批量部署minion

1. 配置salt-ssh

1.1 Master节点安装salt-ssh软件包

yum -y install salt-ssh 

1.2 生成主机ip文件

cat > host.txt <<EOF
172.16.32.46
172.16.32.47
172.16.32.49
172.16.32.50
172.16.32.51
172.16.32.52
172.16.32.53
172.16.32.54
EOF
cat host.txt

1.3 利用脚本导入主机ip到/etc/salt/roster文件

#!/bin/bash
USERNAME=root
USERPASSWD=saltstack00
PORT=22
for i in $(cat host.txt)
do
  cat >> /etc/salt/roster <<EOF
$i:
  host: $i
  user:  $USERNAME
  password:  $USERPASSWD
  port:  $PORT

EOF
done
cat /etc/salt/roster

1.4 测试ssh是否连通

salt-ssh \* test.ping

2. 批量部署minion客户端

cat > /srv/salt/install.sls <<EOF
yum_remove:
  file.absent:
    - name: /etc/yum.repos.d

yum_copy:
  file.recurse:
    - name: /etc/yum.repos.d
    - source: salt://yum.repos.d
    - user: root
    - group: root
    - file_mode: 644
    - dir_mode: 755

dns_copy:
  file.managed:
    - name: /etc/resolv.conf
    - source: salt://resolv.conf
    - user: root
    - group: root
    - mode: 644

minion_install:
  pkg.installed:
    - pkgs:
      - salt-minion

minion_conf:
  file.managed:
    - name: /etc/salt/minion
    - source: salt://minion
    - user: root
    - group: root
    - mode: 640

minion_service:
  service.running:
    - name: salt-minion
    - enable: True

minion_enable:
  service.enabled:
    - name: salt-minion
    - enable: True
EOF
salt \* state.sls install test=True

 

posted @ 2018-07-16 13:07  Testder探索者  阅读(308)  评论(0编辑  收藏  举报