Send commands via CLI over SSH to unsupported network device

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.

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

  • name: Check CPU Load
    hosts: all
    connection: local
    gather_facts: yes

tasks:

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

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

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