首页 > 解决方案 > Ansible 在遇到 fata 错误 (awx) 后不会取消作业

问题描述

我有以下关于 ansible (awx) 的问题:当作业失败时fatal: [IP]: FAILED!,ansible 不会取消此作业,并且 awx 会一直显示“正在运行”。我需要取消那些很烦人的工作手册。ansible 失败的原因在这里无关紧要。我试图通过添加来解决这个问题

- name: Fail task when the command error output prints FAILED
  ansible.builtin.command: /usr/bin/example-command -x -y -z
  register: command_result
  failed_when: "'FAILED' in command_result.stderr"

在剧本的顶部,但它不起作用。

如果你有什么想法...

谢谢!

标签: ansibleansible-awx

解决方案


Playbooks 支持异步模式,如果您需要为您的任务设置超时,您可以使用它。Ansible 等待任务完成、失败或超时。为此,您应该使用asyncpoll参数,async确定任务的超时时间并poll确定 ansible 检查任务状态的时间。两者都必须在几秒钟内。

您可以尝试如下

- name: Fail task when the command error output prints FAILED
  ansible.builtin.command: /usr/bin/example-command -x -y -z
  register: command_result
  async: 60
  poll: 15

了解更多信息:

https://docs.ansible.com/ansible/latest/user_guide/playbooks_async.html#asynchronous-playbook-tasks


推荐阅读