示例:

---
- 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. CoffeeScript的类继承的工具函数extends

    __hasProp = {}.hasOwnProperty, __extends = function(child, parent) { // 派生类时,如果基类的类属性值是对象,那么子类的类属性只是 ...

  2. scala 学习笔记(04) OOP(上)主从构造器/私有属性/伴生对象(单例静态类)/apply方法/嵌套类

    一.主从构造器 java中构造函数没有主.从之分,只有构造器重载,但在scala中,每个类都有一个主构造器,在定义class时,如果啥也没写,默认有一个xxx()的主构造器 class Person ...

  3. Eclipse设置和必装插件

    文章长期更新,主要是记录Eclipse好用的插件和规范的设置 插件篇: 1. StartExplorer. 在Eclipse内定位项目目录,和打开项目目录下的命令行,总是非常麻烦.有了这个插件以后,这 ...

  4. 关于code reiview

    先谈谈三个code review的关键因素: 一.创建review要简单 code reivew是一个程序员日常工作中经常做的一件事,理论上来讲,任何一个将要submit到SCM的change,都必须 ...

  5. CentOS7 下安装JDK1.7 和 Tomcat7

    一.下载JDK 和 Tomcat安装包 1.JDK1.7 下载地址:http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downl ...

  6. 如何优化 FineUI 控件库的性能,减少 80% 的数据上传量!

    在开始正文之前,请帮忙为当前排名前 10 唯一的 .Net 开源软件 FineUI 投一票: 投票地址: https://code.csdn.net/2013OSSurvey/gitop/codevo ...

  7. Theano2.1.14-基础知识之理解为了速度和正确性的内存别名

    来自:http://deeplearning.net/software/theano/tutorial/aliasing.html Understanding Memory Aliasing for ...

  8. 发布园友设计的新款博客皮肤BlueSky

    园友#a为大家设计了一款“简单.纯粹,一点淡雅,一点宁静”的博客皮肤——BlueSky,欢迎您的享用!感谢#a的精心设计! 如果您有兴趣为大家设计博客皮肤,请将您设计的html/css/images文 ...

  9. dev gridcontrol纵向合并单元格设置

    1.要设置gridcontrol中指定列(columns中选中指定列)的AllowMerge属性为true; 2.要设置gridview中AllowCellMerge的属性为true; 3.如果只合并 ...

  10. 自己留存:小经验在asp.net 4.5或者asp.net mvc 5解决A potentially dangerous Request.Form value was detected from the client

    以前的解决办法是 <configuration>    <system.web>        <pages  validateRequest="false&q ...