[摘要] saltstack再来一个测试配置,搭建java环境和配置环境变量:saltstack install jdk,办法比较土,参考网上的pillar,还是没有用好,简单期间直接写的sls配置,通过不容的配置来安装不同版本的jdk,另外遇到了删除jdk.tar.gz文件后重复推送的问题,可以通过unless解决掉。
jdk配置文件:
cat /srv/salt/jdk/jdk8.sls jdk-dir: file.directory: - name: '/usr/java' - clean: False jdk-file: file.managed: - source: salt://file/jdk/jdk1.8.0_20.tar.gz - name: /usr/java/jdk1.8.0_20.tar.gz - unless: 'test -e /usr/java/jdk1.8.0_20' - include_empty: True - require: - file: jdk-dir jdk-install: cmd.run: - name: '/bin/tar -zxf jdk1.8.0_20.tar.gz && /bin/ln -s jdk1.8.0_20 jdk' - cwd: /usr/java - unless: 'test -e jdk1.8.0_20' - require: - file: jdk-file /etc/profile.d/jdk.sh: file.append: - text: - export JAVA_HOME=/usr/java/jdk - export PATH=$JAVA_HOME/bin:$PATH
测试执行saltstack,安装jdk8
salt ‘saltest.sudops.com’ state.sls jdk.jdk8
结果如下:
saltest.sudops.com: ---------- ID: jdk-dir Function: file.directory Name: /usr/java Result: True Comment: Directory /usr/java is in the correct state Started: 12:06:35.242610 Duration: 1.01 ms Changes: ---------- ID: jdk-file Function: file.managed Name: /usr/java/jdk1.8.0_20.tar.gz Result: True Comment: unless execution succeeded Started: 12:06:35.244201 Duration: 8.205 ms Changes: ---------- ID: jdk-install Function: cmd.run Name: /bin/tar -zxf jdk1.8.0_20.tar.gz && /bin/ln -s jdk1.8.0_20 jdk Result: True Comment: unless execution succeeded Started: 12:06:35.253233 Duration: 8.128 ms Changes: ---------- ID: /etc/profile.d/jdk.sh Function: file.append Result: True Comment: File /etc/profile.d/jdk.sh is in correct state Started: 12:06:35.268708 Duration: 3.568 ms Changes: Summary ------------ Succeeded: 4 Failed: 0 ------------ Total states run: 4
如果需要安装其他版本的jdk如:jdk7,可以执行
salt ‘saltest.sudops.com’ state.sls jdk.jdk7
不过软链接需要修改一下
salt ‘saltest.sudops.com’ cmd.run “unlink /usr/java/jdk && ln -sf /usr/java/jdk1.7.0_71 /usr/java/jdk”