---
- hosts: webser
remote_user: root
tasks:
- name: install httpd package
yum: name=httpd
tages: inshttpd #標簽,可以根據標簽執行某個指定動作 命令:ansible-playbook -t reshttpd httpd.yml
- name: copy conf file
copy: src=files/httpd.conf dest=/etc/httpd/conf backup=yes
notify:
- restart service
- check service
#單個可以寫成一行: notify: restart service
#這邊的名稱需要跟handlers中的name保持一致,才能觸發handlers的動作,此處可以定義多個action,對應的handler處需要做多個以匹配
- name: start service
service: name=httpd state=started enabled=yes
tages: rshttpd #多個標簽可以同時執行 命令:ansible-playbook -t inshttpd,rshttpd httpd.yml。另外,此處一系列動作可以定義成同一個標簽,當執行該標簽時,執行定義的一系列動作。
handlers:
- name: restart service
service: name=httpd state=restarted enabled=yes #一個notify對應一個handler的action
- name: checke service
service: killall -0 httpd > /tmp/http.log