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

 

相关文章:

  • 2022-12-23
  • 2021-05-22
  • 2022-12-23
  • 2021-06-01
  • 2021-08-21
  • 2021-11-21
猜你喜欢
  • 2021-10-27
  • 2021-07-02
  • 2022-12-23
  • 2022-12-23
  • 2021-10-11
  • 2022-12-23
相关资源
相似解决方案