运维开发网

ansible内部handlers

运维开发网 https://www.qedev.com 2020-09-04 12:36 出处:51CTO 作者:菜机运维
handlers和tasks同级别调用handlers,在tasks的下级notify调用notify可以指定handlers的name或listenmeta:flush_handlers指定tasks任务结束就调用handlers示例如下[[email protected]]#cattest7.ymlhosts:PAremote_user:roottasks:name:checkapache

handlers 和tasks同级别

调用handlers,在tasks的下级notify调用

listen将被调用的多个handlers命名为组名

notify可以指定handlers的name或listen

meta: flush_handlers 指定tasks任务结束就调用handlers

示例如下

[[email protected] ansible]# cat test7.yml


  • hosts: PA

    remote_user: root

    tasks:

    • name: check apache

      shell: ss -nlt

      notify: reload

    handlers:

    • name: reload

      service:

      name: httpd

      state: reloaded

示例如下

[[email protected] ansible]# less test6.ym


  • hosts: PA

    remote_user: root

    tasks:

    • name: cron

      cron:

      name: echo hello

      user: root

      minute: '20'

      hour: '10'

      job: echo hello jack

      notify: h1

    • meta: flush_handlers

    • name: change 8888 to 8080

      lineinfile:

      path: /etc/httpd/conf/httpd.conf

      backrefs: yes

      regexp: Listen 8888

      line: Listen 8080

      backup: yes

      notify: h2

    handlers:

    • name: reload apache

      listen: h1

      service:

      name: httpd

      state: reloaded

    • name: touch file

      listen: h1

      file:

      path: /root/test.apache

      state: touch

      mode: 0755

      owner: jack

    • name: mkdir hao

      listen: h2

      file:

      path: /root/hao

      state: directory

      owner: jack

      mode: 0777

    • name: reload cron

      listen: h1

      service:

      name: crond

      state: restarted

扫码领视频副本.gif

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号