cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
3817
Views
0
Helpful
8
Replies

Playbook cannot go through to send command to router

interfacedy
Spotlight
Spotlight

Hi, The playbook is configured as below in order to send command to router, but it cannot go through. Anyone can help to take a look at it? Thank you

 

admin2@Lenovo10:/etc/ansible/playbooks$ ansible-playbook show_version.yml
[WARNING]: ansible.utils.display.initialize_locale has not been called, this may result in incorrectly calculated text widths that can
cause Display to print incorrect line lengths

PLAY [Cisco show version example] *****************************************************************************************************

TASK [run show version on the routers] ************************************************************************************************
fatal: [192.168.1.15]: FAILED! => {"changed": false, "msg": "Connection type ssh is not valid for this module"}

PLAY RECAP ****************************************************************************************************************************
192.168.1.15 : ok=0 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0

 

 

admin2@Lenovo10:/etc/ansible/playbooks$ cat show_version.yml
---

- name: Cisco show version example
hosts: routers
gather_facts: false

tasks:
- name: run show version on the routers
ios_command:
commands: show version | incl Version
register: output

- name: print output
debug:
var: output.stdout_lines


admin2@Lenovo10:/etc/ansible/inventory$ cat host-file
[routers]
192.168.1.15


[routers:vars]
ansible_network_os=ios
ansible_user=admin
ansible_password=admin
ansible_connection=network_cli

 

admin2@Lenovo10:/etc/ansible$ tree
.
├── ansible.cfg
├── hosts
├── inventory
│   └── host-file
└── playbooks
└── show_version.yml

 

 

1 Accepted Solution

Accepted Solutions

Hello,

 

try and adapt the script so it runs the exec command 'terminal length 0' first. This command gets rid of the 'more' in the output.

View solution in original post

8 Replies 8

Hello,

 

change:

 

ansible_network_os=ios
ansible_user=admin
ansible_password=admin
ansible_connection=network_cli

 

to 

 

ansible_network_os=ios
ansible_ssh_user=admin
ansible_ssh_password=admin
ansible_connection=network_cli

interfacedy
Spotlight
Spotlight

Thank you Georg for your reply!

I changed it into the bleow, and then it still shows the same 

 

admin2@Lenovo10:/etc/ansible/inventory$ cat host-file
[routers]
192.168.1.15


[routers:vars]
ansible_network_os=ios
ansible_ssh_user=admin
ansible_ssh_password=admin
ansible_connection=network_cli

Hello,

 

what if you use:

 

ansible_network_os=ios
ansible_ssh_user=admin
ansible_ssh_password=admin
ansible_connection=ssh

interfacedy
Spotlight
Spotlight

It still cannot work.

It looks like ssh issue, but it can access the router with raw command via ssh. its strange

Hello,

 

as far as I recall, the group name needs to be the same as the .yml file. In your case, the group name is 'routers' and the .yml file is 'show_version.yml'. Make sure both file names are identical.

interfacedy
Spotlight
Spotlight

It can work after making the below change: 

sudo apt-get install -y python3-paramiko

ansible-playbook show_version.yml -i /etc/ansible/inventory/host-file

 

But do not know why the output is only seen partly instead of full output of command show version. The below is only output that i can see:

 

admin2@Lenovo10:/etc/ansible/playbooks$ ansible-playbook show_version.yml -i /etc/ansible/inventory/host-file

PLAY [Cisco show version example] **************************************************************************************

TASK [run show version on the routers] *********************************************************************************
ok: [192.168.1.15]

TASK [print output] ****************************************************************************************************
ok: [192.168.1.15] => {
"output.stdout_lines": [
[
"Cisco IOS Software, 3700 Software (C3725-ADVENTERPRISEK9-M), Version 12.4(15)T14, RELEASE SOFTWARE (fc2)",
"ROM: 3700 Software (C3725-ADVENTERPRISEK9-M), Version 12.4(15)T14, RELEASE SOFTWARE (fc2)"
]
]
}

PLAY RECAP *************************************************************************************************************
192.168.1.15 : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0

Hello,

 

try and adapt the script so it runs the exec command 'terminal length 0' first. This command gets rid of the 'more' in the output.

interfacedy
Spotlight
Spotlight

Thank you! Resolved!