如何调试Ansible问题? [英] How to debug Ansible issues?

查看:250
本文介绍了如何调试Ansible问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有时,ansible不会执行您想要的操作.而且增加冗长性也无济于事.例如,我现在正在尝试启动coturn服务器,该服务器随systemd OS(Debian Jessie)上的初始化脚本一起提供. Ansible认为它正在运行,但事实并非如此.我如何看待引擎盖下发生的事情?哪些命令被执行,什么输出/退出代码?

Sometimes, ansible doesn't do what you want. And increasing verbosity doesn't help. For example, I'm now trying to start coturn server, which comes with init script on systemd OS (Debian Jessie). Ansible considers it running, but it's not. How do I look into what's happening under the hood? Which commands are executed, and what output/exit code?

推荐答案

调试模块

  • 最基本的方法是通过将-vvv添加到执行行来以更高的详细度级别运行ansible/ansible-playbook.

  • The most basic way is to run ansible/ansible-playbook with an increased verbosity level by adding -vvv to the execution line.

使用Python(Linux/Unix)编写的模块的最彻底的方法是在环境变量ANSIBLE_KEEP_REMOTE_FILES设置为1的情况下(在控制计算机上)运行ansible/ansible-playbook.

The most thorough way for the modules written in Python (Linux/Unix) is to run ansible/ansible-playbook with an environment variable ANSIBLE_KEEP_REMOTE_FILES set to 1 (on the control machine).

这会使Ansible将其执行的Python脚本的准确副本(无论成功与否)保留在目标计算机上.

It causes Ansible to leave the exact copy of the Python scripts it executed (either successfully or not) on the target machine.

脚本的路径打印在Ansible日志中,对于常规任务,它们存储在SSH用户的主目录下:~/.ansible/tmp/.

The path to the scripts is printed in the Ansible log and for regular tasks they are stored under the SSH user's home directory: ~/.ansible/tmp/.

确切的逻辑嵌入在脚本中,并且取决于每个模块.有些使用带有标准库或外部库的Python,有些则调用外部命令.

The exact logic is embedded in the scripts and depends on each module. Some are using Python with standard or external libraries, some are calling external commands.

调试剧本

  • 类似于调试模块,使用-vvv参数增加详细级别会导致将更多数据打印到Ansible日志中

  • Similarly to debugging modules increasing verbosity level with -vvv parameter causes more data to be printed to the Ansible log

从Ansible 2.1开始, Playbook调试器可以调试交互式失败的任务:检查,修改数据;重新运行任务.

Since Ansible 2.1 a Playbook Debugger allows to debug interactively failed tasks: check, modify the data; re-run the task.

调试连接

  • ansible/ansible-playbook调用中添加-vvvv参数会导致日志中包含连接的调试信息.
  • Adding -vvvv parameter to the ansible/ansible-playbook call causes the log to include the debugging information for the connections.

这篇关于如何调试Ansible问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆