# gathering facts on network devices

**URL:** <https://forum.ansible.com/t/gathering-facts-on-network-devices/25093>\
**Category:** Ansible Project\
**Tags:** ansible-lint\
**Created:** [July 26, 2017, 3:09pm UTC](https://forum.ansible.com/t/gathering-facts-on-network-devices/25093 "2017-07-26T15:09:53Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andrew\_Meyer1](https://avatars.discourse-cdn.com/v4/letter/a/df705f/32.png) [@Andrew\_Meyer1](https://forum.ansible.com/u/Andrew_Meyer1)\
**Post date:** [July 26, 2017, 3:09pm UTC](https://forum.ansible.com/t/gathering-facts-on-network-devices/25093/1 "2017-07-26T15:09:53Z")

</div>

I seem to be having some issues making this playbook work. I want to just do a show run on all my cisco devices, but it keeps throwing errors about the ‘- vars:’ or something else. I am on the latest version.

rpm -qa|grep -i ansible  
ansible-inventory-grapher-2.3.2-1.el7.noarch  
ansible-2.3.1.0-1.el7.noarch  
ansible-review-0.13.0-2.el7.noarch  
ansible-openstack-modules-0-20140902git79d751a.el7.noarch  
ansible-lint-3.4.12-1.el7.noarch  
ansible-doc-2.3.1.0-1.el7.noarch

- vars:  
hosts: cisco-fw  
cli:  
hosts: “{{ cisco-fw }}”  
username: user  
password: password  
authorize: yes  
auth\_pass: password  
transport: cli

tasks:

- asa\_command:  
commands:

- show version  
provider: “{{ cli }}”

- asa\_command:  
commands:

- show run

- show memory  
provider: “{{ cli }}”

- asa\_command:  
commands:

- show version  
provider: “{{ cli }}”  
context: system

Here is my output:

sudo ansible-playbook asa-showrun.yml --check  
ERROR! Syntax Error while loading YAML.

The error appears to have been in ‘/home/andrew.meyer/playbooks/asa-showrun.yml’: line 3, column 8, but may  
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

hosts: cisco-fw  
cli:  
^ here

---

<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:** [July 26, 2017, 6:28pm UTC](https://forum.ansible.com/t/gathering-facts-on-network-devices/25093/2 "2017-07-26T18:28:24Z")

</div>

You have them in the wrong order, it should be this way

- hosts: cisco-fw  
&nbsp;&nbsp;&nbsp;vars:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cli:

---

<div class="post-metadata">

**Author:** ![Andrew\_Meyer1](https://avatars.discourse-cdn.com/v4/letter/a/df705f/32.png) [@Andrew\_Meyer1](https://forum.ansible.com/u/Andrew_Meyer1)\
**Post date:** [July 26, 2017, 6:45pm UTC](https://forum.ansible.com/t/gathering-facts-on-network-devices/25093/3 "2017-07-26T18:45:35Z")

</div>

So I figured that out. But now i’m not able to connect to any of the network devices.

All of them are showing unreachable when running ansible-playbook with --check.

Here is my config:

cat asa-showrun.yml

---

<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:** [July 26, 2017, 6:54pm UTC](https://forum.ansible.com/t/gathering-facts-on-network-devices/25093/4 "2017-07-26T18:54:25Z")

</div>

> So I figured that out. But now i'm not able to connect to any of the  
> network devices.
> 
> All of them are showing unreachable when running ansible-playbook with  
> --check.
> 
> Here is my config:
> 
> &nbsp;&nbsp;cat asa-showrun.yml  
> ---  
> - hosts: "cisco-fw-ip"

\<snip\>

> PLAY [cisco-fw-ip]  
> \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
> 
> TASK [Gathering Facts]  
> \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
> fatal: : UNREACHABLE! =\> {"changed": false, "msg": "Failed to connect to  
> the host via ssh: Permission denied (publickey,password).\r\n",  
> "unreachable": true}

You can't use ssh directly or gather facts against most network devices as they do not have python install.

To make it work add connection and gather\_facts as shown bellow.

- hosts: cisco-fw-ip  
&nbsp;&nbsp;&nbsp;connection: local  
&nbsp;&nbsp;&nbsp;gather\_facts: false

---

<div class="post-metadata">

**Author:** ![Andrew\_Meyer1](https://avatars.discourse-cdn.com/v4/letter/a/df705f/32.png) [@Andrew\_Meyer1](https://forum.ansible.com/u/Andrew_Meyer1)\
**Post date:** [July 26, 2017, 6:58pm UTC](https://forum.ansible.com/t/gathering-facts-on-network-devices/25093/5 "2017-07-26T18:58:38Z")

</div>

Ok now i’m getting this -

{“failed”: true, “msg”: “the field ‘args’ has an invalid value, which appears to include a variable that is undefined. The error was: ‘password’ is undefined\n\nThe error appears to have been in ‘/home/andrew.meyer/playbooks/asa-showrun.yml’: line 7, column 5, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n tasks:\n - name:\n ^ here\n”}

---

<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:** [July 26, 2017, 7:03pm UTC](https://forum.ansible.com/t/gathering-facts-on-network-devices/25093/6 "2017-07-26T19:03:48Z")

</div>

It says password is undefined.

Since you are using the variable password you need to set in some how in you play, extra\_vars, inventory or some other place you cat set variables in Ansible.
