如何控制ansible中rescue模块的执行

qia*_*ang 4 ansible

我有一个像下面这样的剧本,我想在块出错时控制救援的执行\xe3\x80\x82\n我在when: is_debug is defined救援\xef\xbc\x8c之后添加,但是当我运行时ansible-playbook dashboard.yml ,不给出is_debug值,救援是当块有错误时仍然执行。

\n\n

我想知道如何控制ansible中rescue模块的执行?

\n\n
[root@ansiable-test update]# cat dashboard.yml\n---\n- hosts: controller\n  vars_files:\n        - "vars/vars.yml"\n  tasks:\n    - name: update horizon\n    - block:\n        - include: "roles/dashboard/tasks/update-horizon.yml"\n      rescue:\n      when: is_debug is defined\n        - debug: msg=\'An error occurred during the upgrade,roll back to the old version\'\n        - include: "roles/dashboard/tasks/rollback.yml"\n
Run Code Online (Sandbox Code Playgroud)\n

lar*_*sks 5

没有rescue“模块”。它是语法的一部分block,您不能when仅应用于该rescue部分。您可以将when条件应用于节内的一个或多个任务rescue

- hosts: controller
  vars_files:
        - "vars/vars.yml"
  tasks:
    - name: update horizon
    - block:
        - include: "roles/dashboard/tasks/update-horizon.yml"
      rescue:
        - debug: msg='An error occurred during the upgrade,roll back to the old version'
          when: is_debug is defined

        - include: "roles/dashboard/tasks/rollback.yml"
          when: is_debug is defined
Run Code Online (Sandbox Code Playgroud)