Managing Mikrotik via API with Ansible

Hi,

first I would like to say I am new to Ansible, so some of my questions might not be the wisest…

As a part of my bachelor’s project, I am supposed to create Ansible module that would be used to configure Mikrotik devices. I decided to go with Mikrotik’s API instead of SSH, as I thought it would give me more possibilities. Now I have find out that I have no idea how to connect Ansible to Mikrotik’s API. Originally I thought I would just write python code using MT’s python API class and passed Ansible parameters into it, including IP, login etc.

So my question is: What would be the “proper” way of doing this? Should I either create some connection plugin to MT’s API or find a way (if possible) to make the module do the hard work, including connection? Could someone please point me to the right direction?

Thank you for any advice.

Hi Miroslav,

Your best approach would be to build your module code and then use the connection: local in your task (or playbook). This will cause your custom module to run locally on the Ansible control host allowing you to develop your own transport API. Essentially the module would work similar to other cloud or network devices that implement an API as opposed to SSH.

If you are planning to develop more than one module that uses a set of common functions, you might also consider developing a shared module that can be imported from module_utils. This is how the current network modules work for Cisco, Arista, etc…

For reference take a look at the following examples:

https://github.com/ansible/ansible-modules-core/pull/2588

https://github.com/ansible/ansible/blob/devel/lib/ansible/module_utils/eapi.py

As you develop your modules please be sure to reference https://github.com/ansible/ansible/blob/devel/docsite/rst/developing_modules.rst#module-checklist to make sure they can be accepted into the extras repo.

Regards,
Peter