Ansible Ad-Hoc command - raw module not working on Cisco IOS devices

221 views
Skip to first unread message

Abdellah Chadid

unread,
Jun 4, 2022, 7:57:28 PM6/4/22
to Ansible Project

trying to use Ad Hoc commands on both my Cisco ios Router and Switch with the -m raw Module. But getting the following error instead.

$ansible -i inventory_file02.ini netgrp -m raw -a "show version" -u abdo -K

Error====

BECOME password: R1 | FAILED | rc=127 >> /bin/sh: 1: show: not found non-zero return code SW1 | FAILED | rc=127 >> /bin/sh: 1: show: not found non-zero return code

Inventory file=====

R1 ansible_host=192.168.20.1 SW1 ansible_host=192.168.10.2 [netgrp] R1 SW1

group_vars/netgrp.yml===

--- ansible_connection: network_cli ansible_network_os: ios ansible_user: abdo absible_password: kali/abdo ansible_become: yes ansible_become_method: enable ansible_ssh_pass: kali/abdo

$ ansible -i inventory_file02.ini netgrp -m raw -a "show version" -u abdo -kK -vvv

ansible [core 2.12.6] config file = /etc/ansible/ansible.cfg configured module search path = ['/home/kali/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/local/lib/python3.10/dist-packages/ansible ansible collection location = /home/kali/.ansible/collections:/usr/share/ansible/collections executable location = /usr/local/bin/ansible python version = 3.10.4 (main, Mar 24 2022, 13:07:27) [GCC 11.2.0] jinja version = 3.0.3 libyaml = True Using /etc/ansible/ansible.cfg as config file SSH password: BECOME password[defaults to SSH password]: host_list declined parsing /home/kali/ansible_play01/net_play02/inventory_file02.ini as it did not pass its verify_file() method script declined parsing /home/kali/ansible_play01/net_play02/inventory_file02.ini as it did not pass its verify_file() method auto declined parsing /home/kali/ansible_play01/net_play02/inventory_file02.ini as it did not pass its verify_file() method yaml declined parsing /home/kali/ansible_play01/net_play02/inventory_file02.ini as it did not pass its verify_file() method Parsed /home/kali/ansible_play01/net_play02/inventory_file02.ini inventory source with ini plugin Skipping callback 'default', as we already have a stdout callback. Skipping callback 'minimal', as we already have a stdout callback. Skipping callback 'oneline', as we already have a stdout callback. META: ran handlers redirecting (type: connection) ansible.builtin.network_cli to ansible.netcommon.network_cli redirecting (type: connection) ansible.builtin.network_cli to ansible.netcommon.network_cli redirecting (type: terminal) ansible.builtin.ios to cisco.ios.ios redirecting (type: cliconf) ansible.builtin.ios to cisco.ios.ios redirecting (type: terminal) ansible.builtin.ios to cisco.ios.ios redirecting (type: become) ansible.builtin.enable to ansible.netcommon.enable redirecting (type: cliconf) ansible.builtin.ios to cisco.ios.ios redirecting (type: become) ansible.builtin.enable to ansible.netcommon.enable <192.168.10.2> ESTABLISH LOCAL CONNECTION FOR USER: kali <192.168.10.2> EXEC show version <192.168.20.1> ESTABLISH LOCAL CONNECTION FOR USER: kali <192.168.20.1> EXEC show version SW1 | FAILED | rc=127 >> /bin/sh: 1: show: not found

Sagar Paul

unread,
Jun 7, 2022, 9:52:53 AM6/7/22
to Ansible Project
Hey,

You might want to use the ios_command module for Cisco IOS specific commands.
ansible ios -m cisco.ios.ios_command -a "commands='show version'" -vvvv

Regards,
Sagar Paul

abdo chadid

unread,
Jun 7, 2022, 9:56:17 AM6/7/22
to ansible...@googlegroups.com
I'm not sure.. I did try it, but it result with an error message indicating that the module should be used in a playbook not on ad-hoc command.. have you tried that yourself !?

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/d98557f9-d0bf-4b11-b281-28a19cccad12n%40googlegroups.com.

Sagar Paul

unread,
Jun 8, 2022, 1:01:57 PM6/8/22
to Ansible Project
Hey,

Please check the op attached in the gist below
https://gist.github.com/KB-perByte/09397b462462bd6db3f52bac8c097d04

Regards,
Sagar Paul
Reply all
Reply to author
Forward
0 new messages