02-05-2022 06:17 PM
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
Solved! Go to Solution.
02-07-2022 12:51 PM
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.
02-06-2022 12:55 AM
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
02-06-2022 09:46 AM
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
02-06-2022 09:58 AM
Hello,
what if you use:
ansible_network_os=ios
ansible_ssh_user=admin
ansible_ssh_password=admin
ansible_connection=ssh
02-06-2022 06:30 PM
It still cannot work.
It looks like ssh issue, but it can access the router with raw command via ssh. its strange
02-07-2022 01:15 AM
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.
02-07-2022 11:34 AM - edited 02-07-2022 11:37 AM
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
02-07-2022 12:51 PM
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.
02-07-2022 01:47 PM
Thank you! Resolved!
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide