如何在没有颜色的情况下运行ansible molecular?

问题描述 投票:0回答:2

运行分子时,日志显示颜色:

 molecule lint -s preprod
 --> [36mValidating schema /home/singuliere/software/enough/infrastructure/molecule/letsencrypt-nginx/molecule.yml.[0m

[0m[0m[0m[32m验证成功完成。[0m [0m[0m[0m--> [36m验证架构 /home/singuliere/software/enough/infrastruction/molecule/postfix/molecule.yml.[0m ...

可以通过将输出通过管道传输到

cat
来禁用(它仅在输出为 tty 时显示)

 molecule lint -s preprod | cat

--> 验证架构 /home/singuliere/software/enough/infrastruction/molecule/letsencrypt-nginx/molecule.yml。 验证成功完成。 ...

有没有永久的方法可以做到同样的事情?我尝试在环境中设置 ANSIBLE_NOCOLOR=true 但没有达到预期的效果。

ansible molecule
2个回答
1
投票

这个行为似乎是硬编码的。

您可以修补分子的记录器类以禁用颜色。
使用

python -c 'import molecule; print(molecule.__file__)'
查找模块的路径。
修改该文件夹中的
logger.py

def color_text(color, msg):
    return msg
    # return '{}{}{}'.format(color, msg, colorama.Style.RESET_ALL)

0
投票

对于

molecule --version
6.0.2
这有效:

export PY_COLORS=0 
molecule --version
# no colors in output
© www.soinside.com 2019 - 2024. All rights reserved.