|
(1)require使用 [root@linux-node1 apache]# pwd
/srv/salt/prod/apache
[root@linux-node1 apache]# systemctl stop httpd
[root@linux-node1 apache]# vim init_require.sls
apache-install:
pkg.installed:
- name: httpd
apache-config:
file.managed:
- name: /etc/httpd/conf/httpd.conf
- source: salt://apache/files/httpd1.conf----->将此处的文件改错,模拟配置错误
- user: root
- group: root
- mode: 644
apache-service:
service.running:
- name: httpd
- enable: True
- require:---------------------------->使用require,表示依赖
- pkg: apache-install--------------->依赖的状态模块为pkg模块,id为apache-install
- file: apache-config--------------->依赖的状态模块为file模块,id为apache-config
[root@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
[root@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]:> 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.
(2)require_in使用
[root@linux-node1 apache]# vim init_require_in.sls
apache-install:
pkg.installed:
- name: httpd
- require_in:------------------>被依赖
- service: apache-service---->被依赖的模块是service,id为apache-service
apache-config:
file.managed:
- name: /etc/httpd/conf/httpd.conf
- source: salt://apache/files/httpd.conf
- user: root
- group: root
- mode: 644
- require_in:
- service: apache-service
apache-service:
service.running:
- name: httpd
- enable: True
解释说明:require和require_in都能实现依赖的功能,主动和被动的关系不同 |
|
|
|
|
|
|