-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New task module for configuring #33
Comments
I definitely agree on that. This collection currentl only provides basic modules for talking with RouterOS devices, and nothing more fancy. I'm not familiar with other networking collections, but I know that people did a lot of work for solving such things. So it's probably worth to investigate what other networking collections do before starting to implement something new :) AFAIK resource modules are currently a big thing. (Unfortunately I forgot the little I knew about what they are...) |
Okay, so I'll just dump more of my thoughts about this approach:
But you are right, there are other platforms without "commit". Cisco IOS comes to my mind, and indeed they have a bunch of resource modules instead of just one. The generic So yes, having resource modules for every path in the RouterOS config would be ideal (from a user perspective). A However, I fear this would also require a ridiculous amount of work to write all these modules for this seemingly small community. Then again, maybe it's all a question of smart "templating" of these resource modules. And starting with one (e.g. |
Изходен текст note: set can be use via "cmd" also check: https://galaxy.ansible.com/nikolaydachev/routeros_api |
I looked a bit more at the resource modules. They are generated/scaffolded by the resource_module_builder. There's also a cli_rm_builder, but they assume a CLI which is probably not what we want: The resource modules work by first fetching the existing configuration of some resource (like "firewall") as facts, comparing them to the wanted configuration and generate commands to migrate from "have" to "want". This approach might work for RouterOS to some extent (e.g. interfaces, IP addresses), since the RouterOS API gives us nicely formatted JSON data for each such resource. But I haven't seen a good handling of network resources yet where order is relevant. Other network OS have numbers in such cases, like Cisco ACLs or EdgeOS firewall rules. fortios_firewall_policy also don't have explicit ordering, and they solved this via some special "move" command with internal IDs returned by earlier invocations. This could be viable for RouterOS, too, but they apparently don't use the aforementioned resource_module_builder. Also, FortiOS too uses a HTTP API instead of SSH (like iOS and others). If I'm not mistaken, the first step would be to write a httpapi plugin, analogous to the cliconf plugin we already have. This would make using the API feel more native to Ansible, using the usual host, username and password information instead of module arguments. But I'm also feeling like there is almost 0 code in this collection that could be reused for this whole adventure. |
To ease the pain at hand, I wrote a role that implements an API in the spirit of what I outlined in my initial post. |
At least some of this should be solved by #91. |
Guess I'll finally have to deal with deploying certificates from a self-hosted CA to all Mikrotiks in order to use the API without transmitting the password in cleartext. |
Fortunately Ansible can help with that (community.crypto has all tools to create the PKI, and https://docs.ansible.com/ansible/latest/collections/community/routeros/docsite/api-guide.html#installing-a-certificate-on-a-mikrotik-router shows how to install the certificate with SSH access to the router). |
SUMMARY
Add a new task module that makes it easier to idempotently modify RouterOS config.
ISSUE TYPE
COMPONENT NAME
ADDITIONAL INFORMATION
Currently, it's a huge PITA to idemtpotently modify RouterOS config. My roles have RouterOS script snippets like this all over the place, to be executed via CLI:
This looks for a firewall rule in the forward chain with action "fasttrack-connection". If it finds such a rule, it sets "ipsec-policy=out,none" on it. If it doesn't find such a rule, it adds one.
Obviously it's quite impossible to catch all edge cases (especially ordering etc.), because RouterOS config is damn complex. But I'd imagine something like this:
One could also think about adding more parameters, like "place-before" (ideally accepting something like
[find ...]
), which would obviously only be used for adding, not for updating.Also, this would make check mode and proper change detection possible.
Or is there a more elegant way to do this?
The text was updated successfully, but these errors were encountered: