首页 » 翻译 » Ansible 入门 » 正文

ansible 入门教程03 notice

当一个文件修改了的时候,我们可能需要重启相应的服务

例如:

-name: template configuration file

  template: src=template.j2 dest=/etc/foo.conf
  notify:
       – restart memcached
       – restart apache


notify 中的两个,我们叫做handlers

hadlers 是一系列的任务,和普通的任务一样,通过name引用,只不过如果没有Notify,这些任务是不会执行的,而且这个只会运行一次在一个play中

handlers:

      – name: restart memcached
         service: name=memcached state=restarted
      – name: restart apache
         service: name=apache state=restarted


如何执行一个play book
ansible-playbook palybook.yml -f 10
在你运行之前可以先查看那些host会执行playbook中的命令
ansible-playbook playbook.yml –list-hosts
欢迎转载,转载请注明出处:http://www.503error.com/

Zhiming Zhang

Senior devops at Appannie
一个奔跑在运维路上的胖子
Zhiming Zhang

Latest posts by Zhiming Zhang (see all)