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
For using raw commands, you need to edit ansible.cfg and uncomment this line
[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
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:
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
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.