首页 > 其他 > 详细

ansible内部handlers

时间:2020-09-04 09:51:38      阅读:44      评论:0      收藏:0      [点我收藏+]
handlers 和tasks同级别

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

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

notify可以指定handlers的name或listen

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

示例如下

[root@jack7-1 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

示例如下

[root@jack7-1 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

ansible内部handlers

原文:https://blog.51cto.com/13434656/2528026

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!