You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ansible 4.8.0环境下前序play报错能否继续执行后续play?

Ansible PLB2报错后继续执行PLB3的实现方案

可以实现,Ansible提供了错误忽略机制适配这类场景,兼容你使用的4.8.0版本,有两种常用配置方式:

方式1:仅忽略指定任务的错误(更推荐)

如果你只需要忽略PLB2中fail任务的报错,不影响该Play下其他任务的错误检测逻辑,可以直接给该任务添加ignore_errors: yes参数:

---
- name: "PLB1"
  hosts: localhost
  gather_facts: no
  tasks:
    - debug: 
       msg: "1"

- name: "PLB2"
  hosts: localhost
  gather_facts: no
  tasks:
    - fail:
       msg: "oh no"
      when: 1==1
      ignore_errors: yes  # 仅忽略当前fail任务的错误

- name: "PLB3"
  hosts: localhost
  gather_facts: no
  tasks:
    - debug: 
       msg: "2"

执行时fail任务会标记为已忽略错误状态,不会终止整个Playbook运行,PLB3会正常执行输出2。

方式2:忽略整个Play的所有错误

如果需要PLB2下所有任务的报错都不终止后续Play运行,可以把ignore_errors: yes配置在Play层级(和name、hosts参数同级):

- name: "PLB2"
  hosts: localhost
  gather_facts: no
  ignore_errors: yes  # 整个PLB2的所有任务错误都忽略
  tasks:
    - fail:
       msg: "oh no"
      when: 1==1

内容的提问来源于stack exchange,提问作者Riccardo79

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.25 16:45:04