networking - 如何跟踪现有的 ansible 项目
问题描述
我不太确定如何跟踪用 YAML 编写的用于网络设备的现有项目。我已正确设置系统并完美执行所有任务。但我想检查所有数据都被分配了什么。
有没有办法像 python 一样跟踪 ansible?
例如:在 python 中,我可以使用 ipdb 模块或只使用 print() 语句来查看各种东西。
解决方案
Ansible 提供了一个Playbook Debugger,可用于跟踪任务的执行。
如果你想调试一个剧中的所有东西,你可以通过debugger: always
- name: some play
hosts: all
debugger: always
tasks: ...
然后您可以使用c
命令继续下一个任务,p task_vars
查看变量或p result._result
查看结果。
调试器也可以像这样用于任务或角色级别:
- hosts: all
roles:
- role: dj-wasabi.zabbix-agent
debugger: always
它有助于不让debug
任务污染你的角色,同时限制调试的范围。
另一种方法是使用debug module,类似于在 python 中使用 print 语句。您可以像这样在您的任务中使用:
# Example that prints the loopback address and gateway for each host
- debug:
msg: System {{ inventory_hostname }} has uuid {{ ansible_product_uuid }}
- debug:
msg: System {{ inventory_hostname }} has gateway {{ ansible_default_ipv4.gateway }}
when: ansible_default_ipv4.gateway is defined
# Example that prints return information from the previous task
- shell: /usr/bin/uptime
register: result
- debug:
var: result
verbosity: 2
推荐阅读
- reactjs - 使用 redux 反应原生导航 v3
- php - 在显示星级系统中使用 css 生成 PHP HTML
- javascript - javascript 在慢速互联网上无法在 html div 中工作
- docker - docker-compose 以 root 身份执行卷脚本
- azure-storage - 以编程方式运行 Azure 存储模拟器
- typescript - 在生成的 Javascript 中保存来自 Typescript 的硬编码日期?
- spring-mvc - java.lang.IllegalStateException:Bean 名称的 BindingResult 和普通目标对象都不能用作请求属性
- java - 从静态方法访问非静态成员。我收到错误 - 无法对非静态字段进行静态引用
- angular - 在 .net core 2.1 项目中将 angular 5 迁移到 angular 6 时面临问题。
- google-cloud-platform - 如何使用 kubernetes 监控和验证 gcp 上托管的 python REST 应用程序的响应数据