- name: Testing PyATS
tasks:
- name: Read in parse_genie role
include_role:
name: clay584.parse_genie
- name: show interfaces
ios_command:
commands:
- show interfaces
register: interfaces
- name: Set Fact Genie Filter
set_fact:
pyats_interfaces: "{{ interfaces['stdout'][0] | parse_genie(command='show interfaces', os='iosxe') }}"
- name: Debug
debug:
var: pyats_interfaces.GigabitEthernet0/0
"ansible_facts": {
"pyats_interfaces": {
"GigabitEthernet0/0": {
"arp_timeout": "04:00:00",
"arp_type": "arpa",
"auto_negotiate": true,
"bandwidth": 1000000,
"counters": {
"in_broadcast_pkts": 0,
"in_crc_errors": 0,
"in_errors": 0,
"in_frame": 0,
"in_giants": 0, etc.
"pyats_interfaces.GigabitEthernet0/0": "VARIABLE IS NOT DEFINED!: 'dict object' has no attribute 'GigabitEthernet0'"
在搜索dict.for G0/0时,/似乎被视为转义字符,并导致变量显示为未定义
在ansible中,有两种等价的语法来处理字典中的变量:
这两种符号可以按您想要的方式混合使用,例如
some['var']['to'].address
虽然它们是等价的,但有些情况下会强制您使用括号表示法
my_var[item]
my_var['field with spaces']
你在这最新的案子里。因此,用以下内容替换调试行可以解决问题:
相关问题 更多 >
编程相关推荐