0

这是一个后续问题:

清除 ansible-playbook 中的错误输出

上面的帖子提出了一种在遇到错误时更改 ansible-playbook 输出格式的方法。但我发现它对于 ansible-molecule (https://molecule.readthedocs.io/en/latest/index.html)在很大程度上是无效的。当我运行测试套件时:

$ molecule converge

它仍然会生成带有大量转义字符的错误消息:

...
TASK [solo : copy wifi.sh] *****************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: #bash /tmp/setupwifi.sh > /log/setupwifi.log 2>&1
fatal: [instance]: FAILED! => {"changed": false, "msg": "AnsibleError: template error while templating string: unexpected char '#' at 1526. String: \ncat > /tmp/timeout.sh << 'SCRIPT'\n#!/bin/sh\n\n# Execute a command with a timeout\n\n# License: LGPLv2\n# Author:\n#    http://www.pixelbeat.org/\n# Notes:\n#    Note there is a timeout command packaged with coreutils since v7.0\n# ...

ansible-molecule 可能无法识别目录下的 ansible.cfg 文件。我应该如何在测试中正确配置它?

4

1 回答 1

2

快速而肮脏的背景信息(如果您需要更多详细信息,请深入了解文档以查找更多信息):分子不会在角色级别读取您的 ansible.cfg,但会在molecule/<scenario_dir>/.molecule/ansible.cfg.

您不能更改该文件中的所有内容(当然也不能自己手动编辑),但是您可以在文件的provisionner.config_options部分中设置很多配置选项molecule.yml。我没有具体检查,但我相信改变stdout_callbackandstderr_callback应该是可能的。这在文档的配置页面中进行了描述。试试看:

provisionner:
  name: ansible
  config_options:
    defaults:
      stdout_callback: debug
      stderr_callback: debug
于 2021-08-02T12:44:39.293 回答