歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> 關於Linux >> ansible學習筆記(二) -- roles

ansible學習筆記(二) -- roles

日期:2017/3/1 11:55:27   编辑:關於Linux

上一節把整個布局大概列了一下,這節重點記錄一下 /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動作之後執行的腳本
Copyright © Linux教程網 All Rights Reserved