码迷,mamicode.com
首页 > 其他好文 > 详细

ansible内部handlers

时间:2020-09-17 12:47:12      阅读:29      评论:0      收藏:0      [点我收藏+]

标签:less   mkdir   backup   user   tar   sts   结束   started   hello   

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

标签:less   mkdir   backup   user   tar   sts   结束   started   hello   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!