# How do I access the cpu %usage in this example? I'm getting an error no matter what I try.

**URL:** <https://forum.ansible.com/t/how-do-i-access-the-cpu-usage-in-this-example-im-getting-an-error-no-matter-what-i-try/26896>\
**Category:** Ansible Project\
**Created:** [March 5, 2018, 7:47am UTC](https://forum.ansible.com/t/how-do-i-access-the-cpu-usage-in-this-example-im-getting-an-error-no-matter-what-i-try/26896 "2018-03-05T07:47:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![MarcG](https://avatars.discourse-cdn.com/v4/letter/m/bb73d2/32.png) [@MarcG](https://forum.ansible.com/u/MarcG)\
**Post date:** [March 5, 2018, 7:47am UTC](https://forum.ansible.com/t/how-do-i-access-the-cpu-usage-in-this-example-im-getting-an-error-no-matter-what-i-try/26896/1 "2018-03-05T07:47:28Z")

</div>

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  
}  
},

`

Using the debug module for troubleshooting, the following

`

- name: print data  
debug:  
msg: "{{ result.ansible\_facts.napalm\_environment.cpu }} "

`

outputs the following:

`"msg": { "0": { "%usage": 0.0 } }`

The question is how do I access the value for the key “%usage”.

`

- 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

---

<div class="post-metadata">

**Author:** ![Varun\_Chopra](https://avatars.discourse-cdn.com/v4/letter/v/54ee81/32.png) [@Varun\_Chopra](https://forum.ansible.com/u/Varun_Chopra)\
**Post date:** [March 5, 2018, 8:12am UTC](https://forum.ansible.com/t/how-do-i-access-the-cpu-usage-in-this-example-im-getting-an-error-no-matter-what-i-try/26896/2 "2018-03-05T08:12:13Z")

</div>

You can access the first element using result.ansible\_facts.napalm\_environment.cpu[0].%usage or so.

---

<div class="post-metadata">

**Author:** ![MarcG](https://avatars.discourse-cdn.com/v4/letter/m/bb73d2/32.png) [@MarcG](https://forum.ansible.com/u/MarcG)\
**Post date:** [March 5, 2018, 8:31am UTC](https://forum.ansible.com/t/how-do-i-access-the-cpu-usage-in-this-example-im-getting-an-error-no-matter-what-i-try/26896/3 "2018-03-05T08:31:38Z")

</div>

Thanks I had tried that but it does not work. See below.

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

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [March 5, 2018, 10:08am UTC](https://forum.ansible.com/t/how-do-i-access-the-cpu-usage-in-this-example-im-getting-an-error-no-matter-what-i-try/26896/4 "2018-03-05T10:08:12Z")

</div>

This should work

result.ansible\_facts.napalm\_environment.cpu['0']['%usage']

---

<div class="post-metadata">

**Author:** ![MarcG](https://avatars.discourse-cdn.com/v4/letter/m/bb73d2/32.png) [@MarcG](https://forum.ansible.com/u/MarcG)\
**Post date:** [March 6, 2018, 4:11am UTC](https://forum.ansible.com/t/how-do-i-access-the-cpu-usage-in-this-example-im-getting-an-error-no-matter-what-i-try/26896/5 "2018-03-06T04:11:24Z")

</div>

Thank you that did it.
