如何绕过失败的ansible任务,但仍然报告失败?


哈哈
2025-01-06 06:15:39 (2月前)


我有一个剧本,它只对我的库存进行了一系列检查,我想知道每个主机上有多少次失败。





  • 主持人:全部
    gather_facts:错误
    remote_user:root

瓦尔:


3 条回复
  1. 0# 晴天3 | 2019-08-31 10-32



    作为一种解决方法,我在每个任务中都放置了以下“虚拟”救援块





    1.   - block:
      • name: check backups
        command: /usr/nagios/plugins/check_backups
        changed_when: False
        register: OUTPUT_CHECK_backups
        tags: backups
        rescue:

          • fail:
            failed_when: false



      但我不确定是否有一种“正确”的方式来代替。


    2. 1# Jacob | 2019-08-31 10-32



      可以处理可恢复的错误

      拯救

      。在这种情况下 ”

      failed_when:false

      “我认为,”不需要继续进行。



      1.   - block:
      2. - name: check backups
      3.   command: /usr/checks/check_backups
      4.   register: OUTPUT_CHECK_backups
      5. rescue:

      6. - debug: var=OUTPUT_CHECK_backups
      7. tags: backups

      8. </code>


      例如,include_tasks检查[1-3] .yml



      1.   - block:
      2. - command: /bin/false
      3.   register: result
      4. rescue:

      5. - debug: msg="check1 failed."
      6. - debug: var=result
      7. </code>


      给(grep msg :)




      1. msg: non-zero return code
        msg: check1 failed.
        msg: non-zero return code
        msg: non-zero return code
        msg: check2 failed.
        msg: non-zero return code
        msg: non-zero return code
        msg: check3 failed.
        msg: non-zero return code

      2. </code>

    登录 后才能参与评论