Hi,
I am using the Napalm module with Ansible and using its get_facts module to obtain some basic information from the device. The relevant output is below,
"ansible_facts": {
"napalm_environment": {
"cpu": {
"0": {
"%usage": 0.0
}
},
- name: print data
debug:
msg: "{{ result.ansible_facts.napalm_environment.cpu }} "
"msg": {
"0": {
"%usage": 0.0
}
}- name: print data
debug:
msg: "{{ result.ansible_facts.napalm_environment.cpu.0}} "
- name: print data
debug:
msg: "{{ result.ansible_facts.napalm_environment.cpu.'0'. }} "
The error was: dict object has no element 0
Many thanks
You can access the first element using result.ansible_facts.napalm_environment.cpu[0].%usage or so.
On Monday, March 5, 2018 at 1:17:28 PM UTC+5:30, Marcos Georgopoulos wrote:
PLAY [Device Pre testing] ********************************************************************************************************************************************************************************************************************
TASK [get facts from device] *****************************************************************************************************************************************************************************************************************
ok: [172.16.1.127]
TASK [print data] ****************************************************************************************************************************************************************************************************************************
fatal: [172.16.1.127]: FAILED! => {"failed": true, "msg": "template error while templating string: expected name or number. String: {{ result.ansible_facts.napalm_environment.cpu[0].%usage }} "}
to retry, use: --limit @/Users/marcosgeorgopoulos/Documents/Ansible/napalm/test.retry
PLAY RECAP ***********************************************************************************************************************************************************************************************************************************
172.16.1.127 : ok=1 changed=0 unreachable=0 failed=1