gpt4 book ai didi

ansible - 如何在ansible中控制救援模块的执行

转载 作者:行者123 更新时间:2023-12-04 02:02:24 26 4
gpt4 key购买 nike

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

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

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

最佳答案

没有rescue “模块”。它是 block 的一部分语法,并且不能应用 whenrescue部分。您可以申请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

关于ansible - 如何在ansible中控制救援模块的执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46266003/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com