Connection to local switch via Mikrotik router jumphost using Ansible

319 Views Asked by At

I am using Ansible on my Debian client machine. I am trying to setup inventory file and ansible playbook for showing simple version of local devices from remote site that is behind NAT by using jumphost (bastion) which is my mikrotik/routeros using ssh called "jumphost" and then connect to final local mikrotik routeros switch called "localswitch" I get the following error: "msg": "ssh connection failed: ssh connect failed: Socket error: Connection reset by peer"

Please help by using ansible_ssh_common_args for routeros as jumphost

inventory.yaml

all:
  switches:
    hosts:
      localswitch.company.local:
        vars:
          ansible_ssh_common_args: '-o ProxyCommand="ssh -W %h:%p -q [email protected]"'

playbook.yaml:

- hosts: all
  connection: network_cli
  gather_facts: true
  vars:
    ansible_network_os: routeros
  tasks:
    - name: Print RouterBoard version
      routeros_command:
        commands:
          - /system routerboard print
      register: result

    - name: Display command output
      debug: 
        var: result.stdout_lines
1

There are 1 best solutions below

0
On

It feels like its not picking up the variable and know to use it correctly. Here is another example to try:

ansible_ssh_common_args='-o ProxyCommand="ssh -p 2222 -W %h:%p -q [email protected]"'

Is the SSH port as well open to the device? Have you tried to add the variable at the playbook level or inventory level and see if it works that way?

see also