如何使用log_plays为Ansible中的playbook执行生成日志文件

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

我正在运行Playbook在Windows目标计算机上安装内部软件。我在此过程中打印了一个“msg”日志,以便我可以将其转发给QA /合规团队。但是,我不知道如何使用debug>“msg”的输出生成日志文件并将其放在Windows主机上。我知道log_plays可能很有用,但我找不到任何关于如何实际使用该模块的示例。

任何示例代码将不胜感激。

ansible ansible-2.x
1个回答
1
投票

所以,遗憾的是,/var/log/ansible/hosts is hardcoded,否则它应该像你期望的那样表现。您可以通过ansible.cfg or the $ANSIBLE_STDOUT_CALLBACK environment variable启用回调:

env ANSIBLE_STDOUT_CALLBACK=log_plays ansible-playbook -i host1,host2 the_file.yml

请注意ad-hoc mode does not load callback plugins,因此您需要明确请求:

env ANSIBLE_LOAD_CALLBACK_PLUGINS=yes ANSIBLE_STDOUT_CALLBACK=log_plays \
    ansible -i host1,host2 -m ping '*'

如果/var/log/ansible/hosts部分让你烦恼,那么还有$ANSIBLE_LOG_PATH会导致ansible将日志输出复制到文件中,并且它在ad-hoc模式下工作正常:

env ANSIBLE_LOG_PATH=$PWD/my-log ansible -i host1,host2 -m ping '*'
© www.soinside.com 2019 - 2024. All rights reserved.