Community discussions

MikroTik App
 
OlofL
Member Candidate
Member Candidate
Topic Author
Posts: 113
Joined: Mon Oct 12, 2015 2:37 pm

Any success with ansible over SSH in 2018?

Tue Nov 13, 2018 6:08 pm

Hello, Im trying to do some simple ansible scripts to push some config to routeros.

Im on routeros 6.43 and ansible 2.7 and trying the ansible modules: raw, command and the new routeros_command https://docs.ansible.com/ansible/latest ... odule.html. None succeeeds, and they just hang. Full debug shows its just hangs on this command:
<172.16.179.1> SSH: EXEC ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/home/olof/.ansible/cp/5edf2db020 -tt 172.16.179.1 '/ip address print'
I have tried using -u user and --ask-pass but normally use ssh keys. Both result in the same failure.



Some examples:
ansible mikrotik -m command -a "executable= /ip address print" 
 [WARNING]: sftp transfer mechanism failed on [172.16.179.1]. Use ANSIBLE_DEBUG=1 to see detailed information

 [WARNING]: scp transfer mechanism failed on [172.16.179.1]. Use ANSIBLE_DEBUG=1 to see detailed information

raw module...
ansible mikrotik -m raw -a "/ip address print"
and in a playbook
playbook.yml
- hosts: mikrotik
  gather_facts: no
  tasks:
  - name: Display resource statistics (routeros)
    raw:
      commands: /system routerboard print
#      wait_for: result[0] contains MikroTik
#    register: routeros_resources



normal SSH works fine with no magic needed.
ssh 172.16.179.1 "ip addr pri"
Flags: X - disabled, I - invalid, D - dynamic 
 #   ADDRESS            NETWORK         INTERFACE                              
 0   172.24.31.242/29   172.24.31.240   ether1   
...
 
djdrastic
Member
Member
Posts: 367
Joined: Wed Aug 01, 2012 2:14 pm

Re: Any success with ansible over SSH in 2018?

Thu Nov 29, 2018 10:29 pm

Mi mate did you ever manage to sort this out ? Running to a similar issue atm.
 
gilito
just joined
Posts: 7
Joined: Thu Nov 13, 2014 10:02 am

Re: Any success with ansible over SSH in 2018?

Mon Dec 24, 2018 4:37 pm

Hello!

I'm in learning phase, but I can say something

For using raw commands, you need to edit ansible.cfg and uncomment this line

Code: Select all

[paramiko_connection]
And config connectino plugin by paramiko

# by default, Ansible requests a pseudo-terminal for commands executed under sudo. Uncomment this
# line to disable this behaviour.
pty=False
To use routeros_commands you must configure as connection: network_cli

example:

root@ansible:~# cat mikrotik.yml

Code: Select all

---
- name: Test routers_commands
hosts: your hosts list
connection: network_cli
remote_user: you_username
gather_facts: false
tasks:
- name: run command on remote devices
routeros_command:
commands: /system routerboard print

- name: run command and check to see if output contains routeros
routeros_command:
commands: /system resource print
wait_for: result[0] contains MikroTik

- name: run multiple commands on remote nodes
routeros_command:
commands:
- /system routerboard print
- /system identity print
To run it:

Code: Select all

ansible-playbook mikrotik.yml -k
-k for entering ssh password


I don't understand alot, but the best is using routeros_commands, nor raw connections

bye!
 
seraph88
just joined
Posts: 1
Joined: Tue Nov 05, 2019 2:34 pm

Re: Any success with ansible over SSH in 2018?

Tue Nov 05, 2019 2:48 pm

Hi,

i have a problem with connection to mikrotik via ansible.

my mikrotik yaml file:
---
- name: Test routers
  hosts: mikrotik
  connection: network_cli
  ansible_network_os: routeros
  remote_user: mikrotik_user
  gather_facts: false
  tasks:
  - name: run command on remote devices
  routeros_command:
  commands: /system routerboard print
after save this file i run ansible like below:
ansible-playbook  mikrotik_test.yaml  -k
and i recive this:
ERROR! 'commands' is not a valid attribute for a Play

The error appears to have been in '/etc/ansible/mikrotik_test.yaml': line 2, column 3, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

---
- name: Test routers
  ^ here
Please help because i sit on this all day and i have no idea what am i doing wrong.

Who is online

Users browsing this forum: araqiel, Bing [Bot], Maggiore81 and 98 guests