ansible:促进对错误的警告

问题描述 投票:9回答:3

我有一些持续的集成检查,运行一些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。

我发现很多关于隐藏这些警告的方法的讨论,但没有找到任何关于将它们提升为硬错误的信息。

ansible warnings
3个回答
0
投票

any_errors_fatal有一个选项ansible.cfg,怎么样推杆

any_errors_fatal = True

0
投票

我有完全一样的问题。我的解决方法是:

  • 用--check和'tee'运行playbook到一个临时文件
  • 做一些grep-magic来过滤掉'警告':'
  • 做一些grep-sed-magic来过滤掉非零的结果(ok / skipped除外)

我知道这不太理想,所以如果你带来了一个很好的解决方案请分享:-)


-1
投票

要隐藏所述[DEPRECATION WARNING],您可以“通过在ansible.cfg中设置deprecation_warnings = False来禁用”。

但这可能并不理想,因为将来您无法看到可能会发生变化或被折旧的情况。

如果你完全确定你可以忽略这样的警告,你可以使用::

args:
 warn: false

或者按照警告消息中的建议修改代码。

其他::

如果你想提出任何警告的错误,你可以

注册结果并应用failed_when如下例所示。

- hosts: localhost gather_facts: false tasks: - name: Fail if there is any warnings shell: touch a.txt register: result failed_when: result.warnings is defined


-1
投票

做什么的?他们是否干扰了剧本的实施?最有可能的不是。只需修复剧本代码即可。

根据我的理解删除这样的警告要么不可能要么非常困难(无论如何,当我尝试时它对我不起作用):

[WARNING]: when statements should not include jinja2 templating delimiters
such as {{ }} or {% %}. Found: "{{ some_variable}}" not in
some_result.stdout

只需使用:

some_variable not in some_result.stdout

在“when”条件下,没有必要设置{{}}来获取变量值

就个人而言,我更喜欢搜索“查找”:

some_result.stdout.find(some_variable) == -1

这个警告:

[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.

可以通过设置从输出中删除:

deprecation_warnings = false

在文件ansible.cfg中

这警告:

[WARNING]: Consider using unarchive module rather than running tar

如果在“命令”中使用模块ansible而不是tar,则很容易删除:

unarchive: src=file.tgz dest=/opt/dest
© www.soinside.com 2019 - 2024. All rights reserved.