---
- 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