我不太确定如何为网络设备跟踪用YAML编写的现有项目。我已经正确设置了系统,并且可以完美地执行所有任务。但是我想检查所有的数据都被分配了。
有没有办法像python一样追踪ansible?
例如:在python中,我可以使用ipdb模块,也可以只使用print()语句查看所有内容。
Ansible提供了Playbook调试器,可用于跟踪任务的执行。
如果您想调试游戏中的所有内容,可以通过 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模块,这类似于在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
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句