zoukankan      html  css  js  c++  java
  • ansible-playbook 之handlers和notify(三)

    一 、handlers和notify结合触发条件

    handlers(触发器): 定义一些task列表,与之前剧本中task没有关系,只有资源发送变化才会采取一定的操作

    notify:notify中调用handler中定义的操作

    二、修改配置文件,重启服务

    1、yum安装httpd

    [root@linux-node1 ~]# tree ansible/
    ansible/
    ├── files
    │   └── httpd.conf
    ├── file.yaml
    └── httpd.yaml
    [root@linux-node1 ansible]# cat httpd.yaml 
    ---
    - hosts: date
      remote_user: root
      
      tasks:
        - name: install httpd package
          yum: name=httpd
        - name: copy conf file
          copy: src=files/httpd.conf dest=/etc/httpd/conf backup=yes
        - name: start service
          service: name=httpd state=started enabled=yes
    

    2、修改配置文件端口8081,在次执行,httpd服务没有重启

    [root@linux-node1 ansible]# cat httpd.yaml 
    ---
    - hosts: date
      remote_user: root
      
      tasks:
        - name: install httpd package
          yum: name=httpd
        - name: copy conf file
          copy: src=files/httpd.conf dest=/etc/httpd/conf backup=yes
          notify: restart service
        - name: start service
          service: name=httpd state=started enabled=yes
    
      handlers:
        - name: restart service
          service: name=httpd state=restarted
    

     

     三、定义多个notify

     

  • 相关阅读:
    毕业设计-1.11
    毕业设计-1.10
    毕业设计-1.09
    毕业设计-1.08
    毕业设计-1.07
    [工具]Maven的安装和配置【MyEclipse】
    毕业设计-1.06
    tomcat部署项目时省略项目名
    Jenkins实现iOS项目自动化打包(含踩坑记录)
    钉钉小程序封装网络请求
  • 原文地址:https://www.cnblogs.com/zhaojingyu/p/12115681.html
Copyright © 2011-2022 走看看