Networking 如何跟踪现有的ansible项目

Networking 如何跟踪现有的ansible项目,networking,automation,ansible,yaml,Networking,Automation,Ansible,Yaml,我不太确定如何跟踪用YAML编写的用于网络设备的现有项目。 我已经正确地设置了系统,并完美地执行了所有任务。但我想检查分配的所有数据 有没有一种方法可以像python一样跟踪ansible 例如:在python中,我可以使用ipdb模块或只使用print()语句来查看所有类型的内容。Ansible提供了一个可用于跟踪任务执行情况的函数 如果您想调试一出戏中的所有内容,可以传递debugger:always - name: some play hosts: all debugger: al

我不太确定如何跟踪用YAML编写的用于网络设备的现有项目。 我已经正确地设置了系统,并完美地执行了所有任务。但我想检查分配的所有数据

有没有一种方法可以像python一样跟踪ansible

例如:在python中,我可以使用ipdb模块或只使用print()语句来查看所有类型的内容。

Ansible提供了一个可用于跟踪任务执行情况的函数

如果您想调试一出戏中的所有内容,可以传递
debugger:always

- name: some play
  hosts: all
  debugger: always
  tasks: ...
然后您可以使用
c
命令继续执行下一个任务,
p task\u vars
查看变量或
p result.\u result
查看结果

调试器也可用于任务或角色级别,如下所示:

- hosts: all
  roles:
    - role: dj-wasabi.zabbix-agent
      debugger: always
# 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
它有助于避免使用
debug
任务污染角色,同时限制调试的范围

另一种方法是使用,这类似于在python中使用print语句。您可以在以下任务中使用:

- hosts: all
  roles:
    - role: dj-wasabi.zabbix-agent
      debugger: always
# 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

Ansible playbooks就是这样设计的,因此您应该能够再次运行playbook,而无需任何更改。但是,更安全的选择是在检查模式
-C
下重新运行,并在
-v
-vvv
上进行详细打印。Diff more
-D
在您寻找更改时也很好
ansible playbook-C-D-vv your_play.yml
将是获得调试输出的完整命令。谢谢Mike。如果我想检查变量中存储了什么呢。调试是我唯一的选择吗?据我所知,调试是查看变量中存储的值的唯一选择非常感谢Andrew。我一直在找这个!