gathering facts on network devices

112 views
Skip to first unread message

Andrew Meyer

unread,
Jul 26, 2017, 11:09:53 AM7/26/17
to Ansible Project
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

Kai Stian Olstad

unread,
Jul 26, 2017, 2:28:34 PM7/26/17
to ansible...@googlegroups.com
On 26. juli 2017 17:09, Andrew Meyer wrote:
> 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:

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

- hosts: cisco-fw
vars:
cli:

--
Kai Stian Olstad

Andrew Meyer

unread,
Jul 26, 2017, 2:46:08 PM7/26/17
to ansible...@googlegroups.com
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
---
- hosts: "cisco-fw-ip"

  tasks:
  - name: sho run
    set_fact:
      cli:
        host: "{{ cisco-fw-ip }}"
        username: "rancid"
        password: "{{ password }}"
        authorize: yes
        auth_pass: "{{ password }}"
        transport: cli

  - 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:

ansible-playbook asa-showrun.yml --check

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}
fatal: []: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: Permission denied (password).\r\n", "unreachable": true}
fatal: []: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: Permission denied (password).\r\n", "unreachable": true}
fatal: []: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: Permission denied (publickey,password).\r\n", "unreachable": true}
fatal: []: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: Permission denied (publickey,password).\r\n", "unreachable": true}
fatal: []: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: Connection timed out during banner exchange\r\n", "unreachable": true}
fatal: []: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: Connection timed out during banner exchange\r\n", "unreachable": true}
fatal: []: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: Connection timed out during banner exchange\r\n", "unreachable": true}





Please remember to reply to all if there are multiple recipients.



--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/mIo1cOaimrU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/fe46bf8b-7bf4-ee58-af9c-fa7f06b9413e%40olstad.com.

For more options, visit https://groups.google.com/d/optout.

Kai Stian Olstad

unread,
Jul 26, 2017, 2:54:53 PM7/26/17
to ansible...@googlegroups.com
On 26. juli 2017 20:45, Andrew Meyer wrote:
> 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
> ---
> - 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
connection: local
gather_facts: false


--
Kai Stian Olstad

Andrew Meyer

unread,
Jul 26, 2017, 2:59:11 PM7/26/17
to ansible...@googlegroups.com
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"}






Please remember to reply to all if there are multiple recipients.




--
Kai Stian Olstad

--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/mIo1cOaimrU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.

Kai Stian Olstad

unread,
Jul 26, 2017, 3:04:08 PM7/26/17
to ansible...@googlegroups.com
On 26. juli 2017 20:58, Andrew Meyer wrote:
> 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

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.


--
Kai Stian Olstad
Reply all
Reply to author
Forward
0 new messages