示例:

---
- 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中的先后顺序执行 而不是被通告的顺序

Handlers的更多相关文章

  1. A little bit about Handlers in JAX-WS

    by Rama Pulavarthi Handlers are message interceptors that can be easily plugged in to the JAX-WS run ...

  2. (spring-第7回【IoC基础篇】)BeanDefinition的载入与解析&&spring.schemas、spring.handlers的使用

    报错信息:Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http: ...

  3. Creating Icon Overlay Handlers / 创建图标标记 Handlers (翻译自MSDN) / VC++, Windows, DLL, ATL, COM

    创建图标标记 Handlers Creating Icon Overlay Handlers 图标标记是放在代表着某个 Shell 对象的图标之左下角的小图像.它们通常被加在一个对象的图标的身上来提供 ...

  4. 1.6.2 Uploading Data with Index Handlers

    1.Uploading Data with Index Handlers 索引处理器就是Request Handlers,用于添加,更新,删除索引中的文档.另外,使用Tika抽取富文档数据,使用Dat ...

  5. Ehcache(2.9.x) - API Developer Guide, Cache Exception Handlers

    About Exception Handlers By default, most cache operations will propagate a runtime CacheException o ...

  6. A Tour of Go Exercise: HTTP Handlers

    Implement the following types and define ServeHTTP methods on them. Register them to handle specific ...

  7. IIS 7.0, ASP.NET, pipelines, modules, handlers, and preconditions

    1.0 What is the IIS Pipeline Conceptually, the IIS pipeline is a state machine with the following st ...

  8. Registering Shell Extension Handlers

    最近在做Windows shell extension 的开发工作,对shell extension handler的注册机制有点疑问,以下摘自MSDN:http://msdn.microsoft.c ...

  9. WebApi2官网学习记录--HttpClient Message Handlers

    在客户端,HttpClient使用message handle处理request.默认的handler是HttpClientHandler,用来发送请求和获取response从服务端.可以在clien ...

随机推荐

  1. 建立mvc过程

    1.public class   dbContext:Dbcontext { private readonly static string CONNECTION_STRING="name=d ...

  2. script实现的日期表示

    function clockon(bgclock){ var now=new Date(); var year=now.getYear(); var month=now.getMonth(); var ...

  3. caffe的python接口学习(1):生成配置文件

    caffe是C++语言写的,可能很多人不太熟悉,因此想用更简单的脚本语言来实现.caffe提供matlab接口和python接口,这两种语言就非常简单,而且非常容易进行可视化,使得学习更加快速,理解更 ...

  4. Wabpack系列:在webpack+vue开发环境中使用echarts导致编译文件过大怎么办?

    现象,在一个webpack+vue的开发环境中,npm install echarts --save了echarts,然后在vue文件中直接使用 import echarts from 'echart ...

  5. java实战之解析xml

    在java中解析xml有现成的包提供方法,常用的有四类:Dom,JDom,Sax以及Dom4j.其中前者是java中自带的,后三者需要大家从开源诸如sourceforge这样的网站下载jar包,然后在 ...

  6. C/C++实践笔记_002编译和链接

    1.要卡死程序用异步,同步的话开一个就关一个值为非0死循环.预处理优先于编译,别称预编译main函数死循环2.程序总是从main函数开始执行的C语言本身不提供输入输出语句print等来自于stdio库 ...

  7. 用js转换joson返回数据库的时间格式为/Date(*************)/

    原理是取中间的毫秒数,再转换成js的Date类型 function ChangeDateFormat(val) { if (val != null) { var date = new Date(par ...

  8. ASP.NET 系列:单元测试

    单元测试可以有效的可以在编码.设计.调试到重构等多方面显著提升我们的工作效率和质量.github上可供参考和学习的各种开源项目众多,NopCommerce.Orchard等以及微软的asp.net m ...

  9. WinForm程序执行JS代码的多种方法以及使用WebBrowser与JS交互

    方法一 使用微软官方组件Interop.MSScriptControl 1.msscript.ocx下载的地址   http://www.microsoft.com/downloads/details ...

  10. BroadcastReceiver之应用卸载和安装监听

    首先创建一个类继承BroadcastReceiver,然后配置Manifest.xml <receiver android:name=".PackageAddRemove"& ...