# Send commands via CLI over SSH to unsupported network device

**URL:** <https://forum.ansible.com/t/send-commands-via-cli-over-ssh-to-unsupported-network-device/28590>\
**Category:** Ansible Project\
**Created:** [September 17, 2018, 10:57am UTC](https://forum.ansible.com/t/send-commands-via-cli-over-ssh-to-unsupported-network-device/28590 "2018-09-17T10:57:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sign](https://avatars.discourse-cdn.com/v4/letter/s/ecb155/32.png) [@sign](https://forum.ansible.com/u/sign)\
**Post date:** [September 17, 2018, 10:57am UTC](https://forum.ansible.com/t/send-commands-via-cli-over-ssh-to-unsupported-network-device/28590/1 "2018-09-17T10:57:02Z")

</div>

I need to send commands to 600 network devices (they are Fortinet Access Points) that have SSH enabled. Python is not available on the device, so I need to use something like network\_cli.  
I’ve tried all the ansible\_network\_os options (ios, nxos, vyos, eos…), but none work.

Is there a way of sending simple commands to a device without the requirement to specify & verify the device OS?  
I don’t care about gathering facts beforehand.

---

<div class="post-metadata">

**Author:** ![julian.mitchellkriel](https://avatars.discourse-cdn.com/v4/letter/j/e9c0ed/32.png) [@julian.mitchellkriel](https://forum.ansible.com/u/julian.mitchellkriel)\
**Post date:** [September 17, 2018, 10:59am UTC](https://forum.ansible.com/t/send-commands-via-cli-over-ssh-to-unsupported-network-device/28590/2 "2018-09-17T10:59:25Z")

</div>

Yeah, I struggled with this for a while.  
Found the expect module is what works.  
Look into it.

---

<div class="post-metadata">

**Author:** ![julian.mitchellkriel](https://avatars.discourse-cdn.com/v4/letter/j/e9c0ed/32.png) [@julian.mitchellkriel](https://forum.ansible.com/u/julian.mitchellkriel)\
**Post date:** [September 17, 2018, 11:00am UTC](https://forum.ansible.com/t/send-commands-via-cli-over-ssh-to-unsupported-network-device/28590/3 "2018-09-17T11:00:57Z")

</div>

- name: Check CPU Load  
hosts: all  
connection: local  
gather\_facts: yes

tasks:

- name: Get CPU Load  
expect:  
command: ssh [admin@10.170.170.100](mailto:admin@10.170.170.100)  
responses:  
admin@xx.xxx.xx0.xxx’s password:
- xxxxxxxxxxx
- ‘#’: ‘"show platform cpu-load summary "’

---

<div class="post-metadata">

**Author:** ![sign](https://avatars.discourse-cdn.com/v4/letter/s/ecb155/32.png) [@sign](https://forum.ansible.com/u/sign)\
**Post date:** [September 21, 2018, 4:28am UTC](https://forum.ansible.com/t/send-commands-via-cli-over-ssh-to-unsupported-network-device/28590/4 "2018-09-21T04:28:53Z")

</div>

Thanks to everyone that replied and emailed me.  
I couldn’t get the _expect_ module to do what I wanted, but ‘_raw_’ worked perfectly.

I needed to do three things on these network devices;

1. backup the current config via SSH, using a single line command ‘cfg -s’ and save the resulting output to a file on the ansible controller:
2. factory reset the device via SSH, using a single line command ‘cfg -x’
3. reboot the device via SSH, using ‘reboot’

I created an inventory file ‘aplist.txt’ with all the device IP’s, and the SSH creds;

[everything]

10.7.122.16

10.7.122.18

[all:vars]

ansible\_connection=ssh

ansible\_user=admin

ansible\_ssh\_pass=notTheRealPassword

Then created playbooks like this ‘fortiap\_backup.yml’

- name: FortiAP Backup Config

hosts: all

connection: local

gather\_facts: no

tasks:

- name: Connect to FortiAP and backup current config

raw: ‘cfg -s’

register: result

- name: Write config backup to file

local\_action: copy content=“{{ result.stdout }}” dest=“/home/admin/fortiap/configbackups/{{ inventory\_hostname }}-oldconfig.txt”

Then created an ‘ansible.cfg’ file in local dir to ignore SSH host checking

[defaults]

host\_key\_checking = false

Then ran the playbook, using the inventory file as input:

ansible-playbook -v ./fortiap\_backup.yml -i ./aplist.txt

---

<div class="post-metadata">

**Author:** ![Rudi\_Mocnik](https://avatars.discourse-cdn.com/v4/letter/r/858c86/32.png) [@Rudi\_Mocnik](https://forum.ansible.com/u/Rudi_Mocnik)\
**Post date:** [January 19, 2020, 9:04am UTC](https://forum.ansible.com/t/send-commands-via-cli-over-ssh-to-unsupported-network-device/28590/5 "2020-01-19T09:04:07Z")

</div>

Hi

I’ve got a similar issues connecting to a network device running KlasOS. I am not sure which connection type to use to make this work. I’ve tried with the code that @sign@L posted but no luck. In sign@L’s code I see he is using “connection: local” and “ansible\_connection=ssh”. Isn’t this the same thing? It picks the connection module to use. Which one is it using in this case; local or ssh? Reading the docs on the “local” connection module is states “This connection plugin allows ansible to execute tasks on the Ansible ‘controller’ instead of on a remote host.”  
Can you list the output of you playbook run with -vvv. I wonder how it looks compared to mine. To my understanding if I use local connection module I should be doing something like this in the tasks:

tasks:

- name: Connect to KlasOS

raw: ‘username@x.x.x.x’

and then use expect.

Can someone please shed some light into this.

Thanks
