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

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

问题描述

有时,ansible 不会做你想做的事.增加冗长也无济于事.例如,我现在正在尝试启动 coturn 服务器,它带有 systemd 操作系统(Debian Jessie)上的 init 脚本.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?

推荐答案

调试模块

  • 最基本的方法是运行 ansible/ansible-playbook,通过将 -vvv 添加到执行线.

  • 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/ansible-playbookANSIBLE_KEEP_REMOTE_FILES 设置为 1(在控制机器上).

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 Debugger 允许调试交互失败的任务:检查、修改数据;重新运行任务.

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天全站免登陆