Send commands via CLI over SSH to unsupported network device

1,522 views
Skip to first unread message

sign@L

unread,
Sep 17, 2018, 6:57:02 AM9/17/18
to Ansible Project
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.


Julian Kriel

unread,
Sep 17, 2018, 6:59:48 AM9/17/18
to ansible...@googlegroups.com
Yeah, I struggled with this for a while.
Found the expect module is what works. 
Look into it. 



--
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 post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/bcada677-5a4b-4a1f-afb5-ee11263fa555%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Julian Kriel

unread,
Sep 17, 2018, 7:01:17 AM9/17/18
to ansible...@googlegroups.com
- name: Check CPU Load
  hosts: all
  connection: local
  gather_facts: yes


  tasks:
       
  - name: Get CPU Load
    expect:
      command: ssh ad...@10.170.170.100
      responses:
        ad...@xx.xxx.xx0.xxx's password:
         - xxxxxxxxxxx
         - '#': '"show platform cpu-load summary "'

sign@L

unread,
Sep 21, 2018, 12:28:53 AM9/21/18
to Ansible Project
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

Rudi Močnik

unread,
Jan 19, 2020, 4:04:07 AM1/19/20
to Ansible Project
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: 'user...@x.x.x.x'


and then use expect.

Can someone please shed some light into this.

Thanks
Reply all
Reply to author
Forward
0 new messages