【问题标题】:Change error output format of ansible-molecule test/converge更改 ansible-molecule test/converge 的错误输出格式
【发布时间】:2021-07-29 17:45:30
【问题描述】:

这是一个后续问题:

Clean error output in 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 文件。我应该如何在测试中正确配置它?

【问题讨论】:

    标签: testing ansible molecule


    【解决方案1】:

    快速而肮脏的背景信息(如果您需要更多详细信息,请深入了解文档以查找更多信息):分子不会在角色级别读取您的 ansible.cfg,但会在 molecule/&lt;scenario_dir&gt;/.molecule/ansible.cfg 中重建自己的配置文件。

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

    provisionner:
      name: ansible
      config_options:
        defaults:
          stdout_callback: debug
          stderr_callback: debug
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-16
      • 1970-01-01
      • 2021-04-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-10
      • 1970-01-01
      相关资源
      最近更新 更多