【发布时间】:2020-07-07 17:54:21
【问题描述】:
我有一些运行一些ansible-playbook 命令的持续集成检查。每个剧本可能会运行许多剧本,包括许多大型角色。
时不时,有人会引入一些更改,当ansible-playbook 运行时会导致警告,例如像这样:
[WARNING]: when statements should not include jinja2 templating delimiters
such as {{ }} or {% %}. Found: "{{ some_variable}}" not in
some_result.stdout
或:
[WARNING]: Consider using unarchive module rather than running tar
或一些弃用警告,例如:
[DEPRECATION WARNING]: ec2_facts is kept for backwards compatibility but usage
is discouraged. The module documentation details page may explain more about
this rationale.. This feature will be removed in a future release. Deprecation
warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.
等等。有时当我们升级 ansible 版本时会弹出这些警告。不管它们为什么会发生,我真的很想通过某种方式让 ansible-playbook 命令在导致其中一个警告时大声失败,而不是安静地继续并让我的 CI 检查成功。有没有办法做到这一点?我目前使用的是 ansible 2.4.3。
我发现很多关于如何隐藏这些警告的讨论,但没有发现任何关于将它们提升为硬错误的信息。
【问题讨论】:
-
非常好的问题,因为将警告视为错误可能在 CI 门上非常有用,因为它会迫使人们修复代码。
-
考虑到这种情况发生在 CI 环境中,您可能需要考虑在 CI 过程中使用 docs.ansible.com/ansible-lint 来查找警告和其他代码异味。
-
我打开了这个 -- github.com/ansible/ansible/issues/64175 -- 如果我有时间我会尝试处理一个拉取请求
-
我已经使用了
ansible-lint,但这在例如针对不存在的库存组运行剧本时无济于事。在这种情况下,ansible 会打印警告但没有错误,并且 CI 测试通过。我希望它在这种情况下失败。