使用requisites對(duì)狀態(tài)進(jìn)行排序控制,結(jié)合前面的file.managed
文件下發(fā)和-watch
requisites實(shí)現(xiàn)自動(dòng)化
直接上程序
install_httpd:
pkg.installed:
- name: httpd
httpd_running:
service.running:
- name: httpd
- enable: True
- reload: True
- require:
- pkg: install_httpd
- watch:
- file: httpd_conf
httpd_conf: ## <========================= -watch
file.managed:
- name: /etc/httpd/conf/httpd.conf
- source: salt://httpd.conf
- user: root
- group: root
- mode: 600
- 在這里用了狀態(tài)排序控制
-require
,指定了httpd_running的執(zhí)行前提是 -pkg: install_httpd(安裝了httpd) - 這里使用了
-watch
監(jiān)控httpd_conf
(不是http.conf)碰逸,一旦httpd_conf
更改蔑担,就觸發(fā)httpd_running
reload重啟 -
httpd_conf
用file.managed
下發(fā)文件穴亏,將/srv/salt/httpd.conf
文件同步給minion端的/etc/httpd/conf/httpd.conf
文件妄迁,所以要提前創(chuàng)建自定義的/srv/salt/httpd.conf
文件 - file.manage下發(fā)文件指定了文件(同步)來源卵渴、用戶和組以及權(quán)限瓣赂。
- 通過
- require
和- watch
兩個(gè)requisites我們可以完成絕大多數(shù)的順序控制榆骚,另外還有其他的一些requisites,可查閱官方文檔煌集。另外每個(gè)requisites都對(duì)應(yīng)著一個(gè)_in形式妓肢,功能一樣,只是放置位置不同(依賴于……和被……依賴)推薦只用原型苫纤。 - sys.list_functions service跟service.running非常像碉钠,所以要注意纲缓,前者是命令,后者是state模塊的文件格式喊废。
部署lamp架構(gòu)
2017.7.1版本祝高,指定依賴
require
要用- pkg/pkgs,pkg.installed后如果是一個(gè)軟件包污筷,用name/names工闺,兩個(gè)或以上的話用pkgs/names。
install_httpd:
pkg.installed:
- pkgs:
- httpd
- httpd-devel
httdp_conf:
file.managed:
- name: /etc/httpd/conf/httpd.conf
- source: salt://httpd.conf
- user: root
- group: root
- mode: 600
httpd_running:
service.running:
- name: httpd
- enable: True
- require:
- pkg: install_httpd ## 這里注意瓣蛀!
- watch:
- file: httdp_conf
install_php:
pkg.installed:
- pkgs:
- php
- php-mysql
- php-common
- php-gd
- php-mbstring
- php-devel
- php-xml
- php-fpm
php_running:
service.running:
- name: php-fpm
- enable: True
- reload: True
- watch:
- file: php_conf
php_conf:
file.managed:
- name: /etc/php.ini
- source: salt://php.ini
- user: root
- group: root
- mode: 600
mysql_install:
pkg.installed:
- pkgs:
- mysql
- mysql-server
- mysql-devel
service.running:
- name: mysqld
- enable: True
- reload: True
- require:
- pkg: install_httpd
- watch:
- file: mysql_conf
mysql_conf:
file.managed:
- name: /etc/my.cnf
- source: salt://my.cnf
- user: root
- group: root
- mode: 600