使用salt批量部署git客户端服务脚本
1、在salt-master 服务器家目录下创建git_install.sls文件
vim git_install.sls
{% set version = '1.8.2.3' %} {% set home_dir = 'opt' %} ##git.tar.gz git_source: file.managed: - name: /usr/local/src/git-{{version}}.tar.gz - unless: - test -e /usr/local/src/git-{{version}}.tar.gz - source: salt://scripts-tools/gitrsync/file/git-{{version}}.tar.gz ##remove_old_git remove_git: cmd.run: - name: rpm -e --nodeps git - require: - file: git_source ##extract_git.tar.gz extract_git: cmd.run: - cwd: /usr/local/src - names: - tar zxf git-{{version}}.tar.gz - unless: - test -d /usr/local/src/git-{{version}} - require: - file: git_source ##install git pkg git_install_update_pkg: pkg.installed: - pkgs: - gcc - libcurl-devel - expat-devel - gettext-devel - openssl-devel - zlib-devel - perl-ExtUtils-MakeMaker - nss ##git_make git_make: cmd.run: - cwd: /usr/local/src/git-{{version}} - name: make prefix=/usr/local/git all && make prefix=/usr/local/git install - require: - cmd: extract_git - unless: - test -d /usr/local/git ##add profile /etc/profile: file.append: - text: - 'export PATH=$PATH:/usr/local/git/bin' - require: - cmd: git_make ##add quote profile /{{home_dir}}/quote/.bash_profile: file.append: - text: - 'export PATH=$PATH:/usr/local/git/bin' - user: quote - group: quote - require: - cmd: git_make ##reload profile reload_profile: cmd.run: - name: source /etc/profile - user: root - group: root
2、执行命令进行部署git服务
salt -L 'salt-minion-IP' state.sls git_install