zoukankan      html  css  js  c++  java
  • Ansible 小手册系列 十五(Blocks 分组)

    当我们想在满足一个条件下,执行多个任务时,就需要分组了。而不再每个任务都要用when。

      tasks: 
       - block:
         - command: echo 1
         - shell: echo 2
         - raw: echo 3
         when: ansible_distribution == 'CentOS'
    

    错误处理

    tasks:
      - block:
          - debug: msg='i execute normally'
          - command: /bin/false
          - debug: msg='i never execute, cause ERROR!'
        rescue:
          - debug: msg='I caught an error'
          - command: /bin/false
          - debug: msg='I also never execute :-('
        always:
          - debug: msg="this always executes"
    

    block中的任务在执行中,如果有任何错误,将执行rescue中的任务。 无论在block和rescue中发生或没有发生错误,always部分都运行。

    发生错误后,运行handlers

     tasks:
      - block:
          - debug: msg='i execute normally'
            notify: run me even after an error
          - command: /bin/false
        rescue:
          - name: make sure all handlers run
            meta: flush_handlers
     handlers:
       - name: run me even after an error
         debug: msg='this handler runs even on error'
    

    测试的时候,设置meta: flush_handlers时,handlers 不执行,rescue的任务还是执行的。



  • 相关阅读:
    0428备份
    1
    0416工作备份
    Bootstrap dropdown a标签或者button 点击事件
    禁止Html5在手机上屏幕页面缩放
    查看端口占用情况
    cakephp 中的find的用法
    cakephp 中连接查询多表 或group by
    cakephp 中的in的用法
    php批量下载文件
  • 原文地址:https://www.cnblogs.com/wanstack/p/8651241.html
Copyright © 2011-2022 走看看