本站教程收集整理的这篇文章主要介绍了ansible handlers,本站教程本站觉得挺不错的,现在分享给大家,也给大家做个参考。
示例:安装Nginx
--- - hosts: hadoop #指定主机组 remote_user: root #远程执行命令的用户 gather_facts: no #是否获取远程主机的信息 tasks: - name: install Nginx vps云服务器 yum: name: Nginx state: present notify: restart Nginx #通知机制,当这个任务执行的时候,通知handlers执行 - name: start Nginx server service: name: Nginx state: started handlers: - name: restart Nginx service: name: Nginx state: restarted
注:在剧本编写完以后,可以使用–Syntax-check检查剧本的语法是否有问题,使用–check或者-C来预执行剧本。
handlers的用处:一般是当修改某个配置文件的时候,通过handlers来执行某个任务。
在某些情况下,可能需要同时调用多个handlers,或者handlers调用其他的handlers。
1、一个任务同时调用多个handlers。
- name: test command: /test.sh notify: - restart Nginx - restart MysqL
2、要handlers调用handlers,则在handlers中直接使用Notify
handlers: - name: test service: name: Nginx state: restarted notify: restart MysqL
?当剧本执行失败以后,handlers可能并没有被触发,也就不会执行了,如果想不管任务是否成功执行,都强制执行handlers。
在这个时候,可以在执行playboox的时候,添加–force-handlers来强制执行handlers
本站总结
以上是本站教程为你收集整理的ansible handlers全部内容,希望文章能够帮你解决ansible handlers所遇到的程序开发问题。
如果觉得本站教程网站内容还不错,欢迎将本站教程推荐给好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。