上一節把整個佈局大概列了一下,這節重點記錄一下 /etc/ansible/roles/tomcat 這個目錄下的各目錄的意義
此目錄的目錄結構如下:
.
├── files
│ └── tomcat-initscript.sh
├── handlers
│ └── main.yml
├── tasks
│ └── main.yml
└── templates
├── iptables-save
├── server.xml
└── tomcat-users.xml
tasks/main.yml 裏面有如下行:
- name: Configure Tomcat server
template: src=server.xml dest=/usr/share/tomcat/conf/
notify: restart tomcat
- name: Configure Tomcat user
template: src=tomcat-users.xml dest=/usr/share/tomcat/conf/
notify: restart tomcat
template模塊官方的解釋爲: Templates a file out to a remote server. 大概意思就是當 src=config_file 這些文件發生變化的時候,觸發notify的動作
templates目錄就是存放這些文件用的(一般都是一些配置文件)
handlers目錄裏有一個main.yml文件,就是用來執行notify動作的
大概的流程爲:
templates/config_file 發生變化 --> 觸發notify: action --> action定義在 handlers/main.yml 中
notify後面的動作名字必須與handlers/main.yml裏面的name後面的名字一致,例:
- name: Configure Tomcat user
template: src=tomcat-users.xml dest=/usr/share/tomcat/conf/
notify: restart tomcat
handlers:
- name: restart tomcat
service: name=tomcat state=restart
而files目錄下存放的是一些腳本, 通過copy模塊可以transport到remote hosts上的,而後觸發notify動作之後執行的腳本