zoukankan      html  css  js  c++  java
  • Handlers

    示例:

    ---
    - hosts: zabbix
      gather_facts: False
      tasks:
    
      - name: edit server
        lineinfile: dest=/usr/local/zabbix/etc/zabbix_agentd.conf backrefs=yes regexp='^Server=.*' line='Server=10.1.32.45,10.3.32.67'
        notify: reload zabbix
    
      - name: edit serveractive
        lineinfile: dest=/usr/local/zabbix/etc/zabbix_agentd.conf backrefs=yes regexp='^ServerActive=.*' line='ServerActive=10.1.32.45,10.3.32.67'
        notify: reload zabbix
    
      - name: edit iptables
        lineinfile: dest=/etc/sysconfig/iptables insertafter='-A INPUT -s 10.1.32.0/24 -p tcp -m tcp --dport 0:65522 -j ACCEPT' line='-A INPUT -s 10.3.32.0/24 -p tcp -m tcp --dport 0:65522 -j ACCEPT'
        notify: reload iptables
    
      handlers:
    
      - name: reload zabbix
        service: name=zabbix_agentd state=reloaded
    
      - name: reload iptables
        service: name=iptables state=reloaded

    说明:

    handlers是ansible支持的一种状态形式.handler类似于task,但是它只有被task通知后才能运行(notify).
    task会触发通知 如果ansible意识到task改变了系统的状态(playbook执行后会返回task是否改变节点系统的状态 是changed=1)
    task把handler的名字作为参数来通告handler
    只有在所有的task都执行后(如果某个task执行失败 并且没有设置ignore_errors 后续的操作都不会再执行 包括被通告的handlers) handler才运行 而且只会运行一次 即使被多次被通告 handler按照在playbook中的先后顺序执行 而不是被通告的顺序

  • 相关阅读:
    [树形dp] Jzoj P5814 树
    [快速幂][数学][dp] Jzoj P5813 计算
    [差分] Jzoj P5812 区间
    [贪心][模拟] Jzoj P5811 简单的填数
    如何用c++发出音乐
    网络流初步详解
    【纪中模拟2019.08.01】【JZOJ2644】数列
    【纪中模拟2019.08.02】【JZOJ1308】取数游戏
    2019.08纪中 XC谈OI学习方法论
    C++STL容器
  • 原文地址:https://www.cnblogs.com/metasequoia/p/5198306.html
Copyright © 2011-2022 走看看