saltstack 批量部署tomcat 服务: [root@zabbix-server state]# salt -E '(jenkins|gitlab).saltstack.me' test.ping jenkins.saltstack.me: True gitlab.saltstack.me: True [root@zabbix-server state]# cat /etc/salt/master.d/file_roots.conf file_roots: base: - /etc/salt/state ...... [root@zabbix-server state]# tree /etc/salt/state/ /etc/salt/state/ ├── jdk │ ├── files │ │ └── jdk-8u112-linux-x64.tar.gz │ └── install.sls ├── tomcat │ ├── files │ │ └── apache-tomcat-7.0.64-1.tar.gz │ └── install.sls └── top.sls [root@zabbix-server jdk]# cat install.sls jdk-install: file.managed: - name: /usr/local/src/jdk-8u112-linux-x64.tar.gz - source: salt://jdk/files/jdk-8u112-linux-x64.tar.gz - user: root - group: root - mode: 755 cmd.run: - name: cd /usr/local/src && tar xf jdk-8u112-linux-x64.tar.gz && mv jdk1.8.0_112 /usr/local/jdk && chown -R root:root /usr/local/jdk - unless: test -d /usr/local/jdk - require: - file: jdk-install jdk-config: file.append: - name: /etc/profile - text: - export JAVA_HOME=/usr/local/jdk - export CLASSPATH=.$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/lib/tools.jar - export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH [root@zabbix-server tomcat]# cat install.sls include: - jdk.install tomcat-install: file.managed: - name: /usr/local/src/apache-tomcat-7.0.64-1.tar.gz - source: salt://tomcat/files/apache-tomcat-7.0.64-1.tar.gz - user: root - group: root - mode: 755 cmd.run: - name: cd /usr/local/src && tar xf apache-tomcat-7.0.64-1.tar.gz && mv apache-tomcat-7.0.64-1 /usr/local/tomcat && chown -R root:root /usr/local/tomcat - unless: test -d /usr/local/tomcat - require: - file: tomcat-install tomcat-config: file.managed: - name: /etc/profile - text: - export: TOMCAT_HOME=/usr/local/tomcat [root@zabbix-server state]# cat top.sls base: '(jenkins|gitlab).saltstack.me': - match: pcre - tomcat.install 执行部署命令: [root@zabbix-server state]# salt -E '(jenkins|gitlab).saltstack.me' state.highstate [root@zabbix-server state]# salt -E '(jenkins|gitlab).saltstack.me' saltutil.running
转载于:https://blog.51cto.com/zhagyilig/1908130