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
You have them in the wrong order, it should be this way
- hosts: cisco-fw
vars:
cli:
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
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
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”}
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.