1.查看file_roots
file_roots: base: - /srv/salt/ dev: - /srv/salt/dev/ prod: - /srv/salt/prod/
2.目录结构如下
[root@saltstack1 prod]# pwd /srv/salt/prod [root@saltstack1 prod]# tree . |-- nginx | `-- files | `-- nginx-1.9.15.tar.gz |-- pcre | |-- files | | `-- pcre-8.38.tar.gz | `-- install.sls `-- php `-- files `-- php-7.0.6.tar.gz
3.在/srv/salt/prod/pcre/目录下面新建文件install.sls
pcre-source-install: file.managed: - name: /usr/local/src/pcre-8.38.tar.gz - source: salt://pcre/files/pcre-8.38.tar.gz - user: root - group: root - mode: 755 cmd.run: - name: cd /usr/local/src && tar zxf pcre-8.38.tar.gz && cd pcre-8.38 && ./configure --prefix=/usr/local/pcre && make && make install - unless: test -d /usr/local/pcre - require: - file: pcre-source-install
4.执行安装命令
[root@saltstack1 pcre]# salt 'saltstack1' state.sls pcre.install env=prod saltstack1: ---------- ID: pcre-source-install Function: file.managed Name: /usr/local/src/pcre-8.38.tar.gz Result: True Comment: File /usr/local/src/pcre-8.38.tar.gz is in the correct state Started: 16:10:24.148959 Duration: 41.8 ms Changes: ---------- ID: pcre-source-install Function: cmd.run Name: cd /usr/local/src && tar zxf pcre-8.38.tar.gz && cd pcre-8.38 && ./configure --prefix=/usr/local/pcre && make && make install Result: True Comment: unless execution succeeded Started: 16:10:24.192646 Duration: 8.637 ms Changes: Summary for saltstack1 ------------ Succeeded: 2 Failed: 0 ------------ Total states run: 2
5.安装nginx源码,在/srv/salt/prod/nginx/目录下新建install.sls文件
include:
- pcre.install
nginx-source-install:
file.managed:
- name: /usr/local/src/nginx-1.9.15.tar.gz
- source: salt://nginx/files/nginx-1.9.15.tar.gz
- user: root
- group: root
- mode: 755
cmd.run:
- name: cd /usr/local/src/ && tar zxf nginx-1.9.15.tar.gz && cd nginx-1.9.15 && ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_stub_status_module --with-file-aio --with-http_dav_module --with-pcre=/usr/local/src/pcre-8.38 && make && make install
- unless: test -d /usr/local/nginx
- require:
- file: nginx-source-install
- cmd: pcre-source-install