在以前的故障之后,如何始终运行一些恼人的角色? [英] How to always run some ansible roles after previous failures?

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

问题描述

我有一组看起来像的剧本

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 }

当前的问题是,在前四个角色中,我们都有 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.

请注意,我们有很多剧本都调用collect_logs角色,因此在剧本中移动代码"实际上并不是重用它的方法.

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:块替换为 role_include 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.

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

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