我有这样的输出:
ospf_struct: - Neighbor: 1.1.1.2 Neighbor_is_up: 1w2d interface_address: 1.1.1.2 via_interface: GigabitEthernet0/1
你能帮我创建一个只存储"via_inteface: GigabitEthernet0/1“的变量吗?
我的剧本是这样的:
---
- name: "REPORT -"
hosts: ios
connection: network_cli
become: yes
become_method: enable
gather_facts: no
vars:
OSPF_command: show ip ospf nei det
tasks:
- name: "Run command"
ios_command:
commands: "{{ OSPF_command }}"
register: ospf
- name: "Run Template"
set_fact:
ospf_struct: "{{ ospf.stdout[0] | parse_cli_textfsm('/etc/ansible/playbooks/test.template') }}"
- name: Display outuput
debug:
var: ospf_struct
#- name Print only one-variable with the value "GigabitEthernet0/1"
#How could i get this happen.谢谢!
/Mohammed
我试着做一个很好的json "ospf_struct:"{{ ospf.stdout[0] | parse_cli_textfsm('/etc/ansible/playbooks/test.template') | to_nice_json }}"
并尝试进行调试,但也不起作用。
debug:
var: ospf_struct.via_interface发布于 2019-06-07 03:57:42
现在,它与msg一起工作,而不是var: debug: msg: "{{ ospf_struct.0.via_interface }}",感谢#Alassane的支持-
https://stackoverflow.com/questions/56481828
复制相似问题