binghai03 发表于 2018-8-1 09:27:07

自动化运维神器之saltstack (五)salt-ssh的应用场景

## 将所有的与minion部署相关的文件全部放在/srv/salt/epel目录下  
# pwd
  
/srv/salt/epel
  
# tree -f
  
.
  
├── ./epel-release-6-8.noarch.rpm
  
└── ./salt_install.sls
  

  
0 directories, 2 files
  
## salt_install文件内容
  
# cat salt_install.sls
  
## 首先要安装epel扩展源,然后才能使用yum的方式安装salt-minion
  
epel_install:
  
file.managed:
  
    - name: /tmp/epel-release-6-8.noarch.rpm    ## 指定4、5节点的epel安装包的存放路径
  
    - source: salt://epel/epel-release-6-8.noarch.rpm ## 指定从master的哪个位置拷贝epel的rpm包
  
    - user: root    ## 文件的拥有者
  
    - group: root   ## 文件的所属组
  
cmd.run:
  
    - name: rpm -ivh /tmp/epel-release-6-8.noarch.rpm    ## 执行rpm包的安装
  
    - unless: test -f /etc/yum.repos.d/epel.repo    ## 如果存在这个文件就不再执行安装程序
  
    - require:
  
      - file: epel_install    ## 安装epel包要在epel文件拷贝之后
  

  
cache_yum:
  
cmd.run:
  
    - name: yum makecache   ## 生成yum的缓存
  
    - require:
  
      - file: epel_install    ## 生成缓存要在epel安装之后
  

  
salt_install:
  
pkg.installed:            ## 安装salt-minion
  
    - name: salt-minion
  
    - require:                ## 安装minion要在epel安装之后
  
      - file: epel_install
  

  
## 远程执行
  
# salt-ssh'uadoop' state.sls epel.salt_install
  
uadoop4:
  
    ----------
  
    cmd_|-cache_yum_|-yum makecache_|-run:
  
      ----------
  
      __run_num__:
  
            2
  
      changes:
  
            ----------
  
            pid:
  
                1993
  
            retcode:
  
                0
  
            stderr:
  

  
            stdout:
  
                Loaded plugins: fastestmirror, security
  
                Loading mirror speeds from cached hostfile
  
               * base: ftp.stust.edu.tw
  
               * epel: ftp.cuhk.edu.hk
  
               * extras: mirrors.btte.net
  
               * updates: mirrors.btte.net
  
                Metadata Cache Created
  
      comment:
  
            Command "yum makecache" run
  
      name:
  
            yum makecache
  
      result:
  
            True
  
    cmd_|-epel_install_|-rpm -ivh /tmp/epel-release-6-8.noarch.rpm_|-run:
  
      ----------
  
      __run_num__:
  
            1
  
      changes:
  
            ----------
  
            pid:
  
                1991
  
            retcode:
  
                0
  
            stderr:
  
                warning: /tmp/epel-release-6-8.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY
  
            stdout:
  
                Preparing...                ##################################################
  
                epel-release                ##################################################
  
      comment:
  
            Command "rpm -ivh /tmp/epel-release-6-8.noarch.rpm" run
  
      name:
  
            rpm -ivh /tmp/epel-release-6-8.noarch.rpm
  
      result:
  
            True
  
    file_|-epel_install_|-/tmp/epel-release-6-8.noarch.rpm_|-managed:
  
      ----------
  
      __run_num__:
  
            0
  
      changes:
  
            ----------
  
            diff:
  
                New file
  
            mode:
  
                0644
  
      comment:
  
            File /tmp/epel-release-6-8.noarch.rpm updated
  
      name:
  
            /tmp/epel-release-6-8.noarch.rpm
  
      result:
  
            True
  
    pkg_|-salt_install_|-salt-minion_|-installed:
  
      ----------
  
      __run_num__:
  
            3
  
      changes:
  
            ----------
  
            PyYAML:
  
                ----------
  
                new:
  
                  3.10-3.1.el6
  
                old:
  

  
            libyaml:
  
                ----------
  
                new:
  
                  0.1.6-1.el6
  
                old:
  

  
            m2crypto:
  
                ----------
  
                new:
  
                  0.20.2-9.el6
  
                old:
  

  
            openpgm:
  
                ----------
  
                new:
  
                  5.1.118-3.el6
  
                old:
  

  
            python-babel:
  
                ----------
  
                new:
  
                  0.9.4-5.1.el6
  
                old:
  

  
            python-backports:
  
                ----------
  
                new:
  
                  1.0-3.el6.centos
  
                old:
  

  
            python-backports-ssl_match_hostname:
  
                ----------
  
                new:
  
                  3.4.0.2-4.el6.centos
  
                old:
  

  
            python-chardet:
  
                ----------
  
                new:
  
                  2.0.1-1.el6.centos
  
                old:
  

  
            python-crypto:
  
                ----------
  
                new:
  
                  2.0.1-22.el6
  
                old:
  

  
            python-jinja2:
  
                ----------
  
                new:
  
                  2.2.1-2.el6_5
  
                old:
  

  
            python-msgpack:
  
                ----------
  
                new:
  
                  0.1.13-3.el6
  
                old:
  

  
            python-ordereddict:
  
                ----------
  
                new:
  
                  1.1-2.el6.centos
  
                old:
  

  
            python-requests:
  
                ----------
  
                new:
  
                  1.1.0-4.el6.centos
  
                old:
  

  
            python-six:
  
                ----------
  
                new:
  
                  1.7.3-1.el6.centos
  
                old:
  

  
            python-urllib3:
  
                ----------
  
                new:
  
                  1.5-7.el6.centos
  
                old:
  

  
            python-zmq:
  
                ----------
  
                new:
  
                  14.3.1-1.el6
  
                old:
  

  
            salt:
  
                ----------
  
                new:
  
                  2014.7.0-3.el6
  
                old:
  

  
            salt-minion:
  
                ----------
  
                new:
  
                  2014.7.0-3.el6
  
                old:
  

  
            sshpass:
  
                ----------
  
                new:
  
                  1.05-1.el6
  
                old:
  

  
            zeromq3:
  
                ----------
  
                new:
  
                  3.2.4-1.el6
  
                old:
  

  
      comment:
  
            The following packages were installed/updated: salt-minion.
  
      name:
  
            salt-minion
  
      result:
  
            True
  
uadoop5:
  
    ----------
  
    cmd_|-cache_yum_|-yum makecache_|-run:
  
      ----------
  
      __run_num__:
  
            2
  
      changes:
  
            ----------
  
            pid:
  
                1937
  
            retcode:
  
                0
  
            stderr:
  

  
            stdout:
  
                Loaded plugins: fastestmirror, security
  
                Loading mirror speeds from cached hostfile
  
               * base: mirror.neu.edu.cn
  
               * epel: ftp.cuhk.edu.hk
  
               * extras: mirror.neu.edu.cn
  
               * updates: mirror01.idc.hinet.net
  
                Metadata Cache Created
  
      comment:
  
            Command "yum makecache" run
  
      name:
  
            yum makecache
  
      result:
  
            True
  
    cmd_|-epel_install_|-rpm -ivh /tmp/epel-release-6-8.noarch.rpm_|-run:
  
      ----------
  
      __run_num__:
  
            1
  
      changes:
  
            ----------
  
            pid:
  
                1935
  
            retcode:
  
                0
  
            stderr:
  
                warning: /tmp/epel-release-6-8.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY
  
            stdout:
  
                Preparing...                ##################################################
  
                epel-release                ##################################################
  
      comment:
  
            Command "rpm -ivh /tmp/epel-release-6-8.noarch.rpm" run
  
      name:
  
            rpm -ivh /tmp/epel-release-6-8.noarch.rpm
  
      result:
  
            True
  
    file_|-epel_install_|-/tmp/epel-release-6-8.noarch.rpm_|-managed:
  
      ----------
  
      __run_num__:
  
            0
  
      changes:
  
            ----------
  
            diff:
  
                New file
  
            mode:
  
                0644
  
      comment:
  
            File /tmp/epel-release-6-8.noarch.rpm updated
  
      name:
  
            /tmp/epel-release-6-8.noarch.rpm
  
      result:
  
            True
  
    pkg_|-salt_install_|-salt-minion_|-installed:
  
      ----------
  
      __run_num__:
  
            3
  
      changes:
  
            ----------
  
            PyYAML:
  
                ----------
  
                new:
  
                  3.10-3.1.el6
  
                old:
  

  
            libyaml:
  
                ----------
  
                new:
  
                  0.1.6-1.el6
  
                old:
  

  
            m2crypto:
  
                ----------
  
                new:
  
                  0.20.2-9.el6
  
                old:
  

  
            openpgm:
  
                ----------
  
                new:
  
                  5.1.118-3.el6
  
                old:
  

  
            python-babel:
  
                ----------
  
                new:
  
                  0.9.4-5.1.el6
  
                old:
  

  
            python-backports:
  
                ----------
  
                new:
  
                  1.0-3.el6.centos
  
                old:
  

  
            python-backports-ssl_match_hostname:
  
                ----------
  
                new:
  
                  3.4.0.2-4.el6.centos
  
                old:
  

  
            python-chardet:
  
                ----------
  
                new:
  
                  2.0.1-1.el6.centos
  
                old:
  

  
            python-crypto:
  
                ----------
  
                new:
  
                  2.0.1-22.el6
  
                old:
  

  
            python-jinja2:
  
                ----------
  
                new:
  
                  2.2.1-2.el6_5
  
                old:
  

  
            python-msgpack:
  
                ----------
  
                new:
  
                  0.1.13-3.el6
  
                old:
  

  
            python-ordereddict:
  
                ----------
  
                new:
  
                  1.1-2.el6.centos
  
                old:
  

  
            python-requests:
  
                ----------
  
                new:
  
                  1.1.0-4.el6.centos
  
                old:
  

  
            python-six:
  
                ----------
  
                new:
  
                  1.7.3-1.el6.centos
  
                old:
  

  
            python-urllib3:
  
                ----------
  
                new:
  
                  1.5-7.el6.centos
  
                old:
  

  
            python-zmq:
  
                ----------
  
                new:
  
                  14.3.1-1.el6
  
                old:
  

  
            salt:
  
                ----------
  
                new:
  
                  2014.7.0-3.el6
  
                old:
  

  
            salt-minion:
  
                ----------
  
                new:
  
                  2014.7.0-3.el6
  
                old:
  

  
            sshpass:
  
                ----------
  
                new:
  
                  1.05-1.el6
  
                old:
  

  
            zeromq3:
  
                ----------
  
                new:
  
                  3.2.4-1.el6
  
                old:
  

  
      comment:
  
            The following packages were installed/updated: salt-minion.
  
      name:
  
            salt-minion
  
      result:
  
            True
  
## 根据反馈的结果看到已经安装成功
页: [1]
查看完整版本: 自动化运维神器之saltstack (五)salt-ssh的应用场景