如何在之前的失败后始终运行一些 ansible 角色? [英] How to always run some ansible roles after previous failures?

查看:25
本文介绍了如何在之前的失败后始终运行一些 ansible 角色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一套看起来像的剧本

I have a set of playbooks that do look like

- name: Run test
  hosts: tester
  roles:
    - { role: setup_repos }
    - { role: setup_environment }
    - { role: install_packages }
    - { role: run_tests }
    - { role: collect_logs }

当前的问题是,在前 4 个角色中,我们都有 ignore_errors: true 这不是一个好的做法,因为它使读取输出和调试变得非常困难.

The current problem is that all over the first 4 roles we have ignore_errors: true which is not a good practice as it makes very hard to read the output and to debug.

ignore_errors 被滥用的唯一原因是因为我们希望能够在最后执行 collect_logs,而不管结果如何.

The only reason why ignore_errors was abused was because we wanted to be able to perform the collect_logs at the end, regardless the outcome.

我们如何重构它以消除 ignore_errors 并拥有更多的快速失败策略.

How can we refactor this in order to remove the ignore_errors and have a more of a fail-fast strategy.

请注意,我们有很多 playbook 调用 collect_logs 角色,因此在 playbook 中移动代码"并不是真正重用它的方法.

Please note that we have lots of playbooks calling collect_logs role, so "moving code inside playbook" is not really a way to reuse it.

推荐答案

在 ansible 2.4 或更新版本中,应该用 role_include 之类的任务替换 role: 块role_import,它使您能够使用任务使用的正常逻辑.您可以使用处理程序、ignore_errors 等.

On ansible 2.4 or newer one should replace role: block with tasks like role_include or role_import, which gives you the ability to use normal logic used by tasks. You could use handlers, ignore_errors, and so on.

这篇关于如何在之前的失败后始终运行一些 ansible 角色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆