apache-service:
service.running:
- name: httpd
- enable: True
- require:---------------------------->使用require,表示依赖
- pkg: apache-install--------------->依赖的状态模块为pkg模块,id为apache-install
- file: apache-config--------------->依赖的状态模块为file模块,id为apache-config
[iyunv@linux-node1 apache]# salt -S "192.168.56.11" state.highstate #执行模块提示会有报错,此时httpd不会正常启动
......
----------
ID: apache-config
Function: file.managed
Name: /etc/httpd/conf/httpd.conf
Result: False
Comment: Source file salt://apache/files/httpd1.conf not found
Started: 09:48:33.459243
Duration: 40.414 ms
Changes:
----------
ID: apache-service
Function: service.running
Name: httpd
Result: False
Comment: One or more requisite failed: apache.init.apache-config
Changes:
----------
......
Summary for linux-node1.example.com
------------
Succeeded: 6
Failed: 2
------------
Total states run: 8
Total run time: 1.110 s
[iyunv@linux-node1 apache]# systemctl status httpd
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
Active: inactive (dead) since Sat 2018-01-20 09:44:04 CST; 4min 59s ago
Docs: man:httpd(8)
man:apachectl(8)
Process: 65439 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=0/SUCCESS)
Main PID: 1025 (code=exited, status=0/SUCCESS)
Status: "Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec"
Jan 17 10:41:59 linux-node1 systemd[1]: Starting The Apache HTTP Server...
Jan 17 10:42:02 linux-node1 systemd[1]: Started The Apache HTTP Server.
Jan 18 03:49:02 linux-node1 systemd[1]: Reloaded The Apache HTTP Server.
Jan 20 09:43:53 linux-node1 systemd[1]: Stopping The Apache HTTP Server...
Jan 20 09:44:04 linux-node1 systemd[1]: Stopped The Apache HTTP Server.
[iyunv@linux-node1 apache]# salt -S "192.168.56.11" state.highstate
----------
ID: apache-config
Function: file.managed
Name: /etc/httpd/conf/httpd.conf
Result: True
Comment: File /etc/httpd/conf/httpd.conf updated------>检测文件有变化
Started: 10:10:08.493557
Duration: 53.016 ms
Changes:
----------
diff:
---
+++
@@ -1,4 +1,5 @@
#
+#hahahaaha
#hahahaaha
#hahahaaha
# This is the main Apache HTTP server configuration file. It contains the
----------
ID: apache-service
Function: service.running
Name: httpd
Result: True
Comment: Service reloaded---------------->服务重载
Started: 10:10:08.596434
Duration: 158.753 ms
Changes:
----------
httpd:
True
----------
#watch_in的使用和require_in是一样的
5、unless:状态间的条件判断
需求场景:给apache的admin目录进行加密登陆查看
(1)修改配置文件,添加认证功能
[iyunv@linux-node1 apache]# vim files/httpd.conf
<Directory "/var/www/html/admin">
AllowOverride All
Order allow,deny
Allow from all
AuthType Basic
AuthName "haha"
AuthUserFile /etc/httpd/conf/htpasswd_file
Require user admin
</Directory>
(2)修改状态文件init.sls
[iyunv@linux-node1 apache]# vim init.sls
apache-install:
pkg.installed:
- name: httpd