Collects a base set of device facts from a remote device that is running RouterOS. This module prepends all of the base network fact keys with ansible_net_<fact>. The facts module will always collect a base set of facts from the device and can enable or disable collection of additional facts.
Facts returned by this module are added/updated in the hostvars host facts and can be referenced by name just like any other host fact. They do not need to be registered in order to use them.
Allows to find entries for a path by conditions and modify the values of these entries.
Use the community.routeros.api_find_and_modify module to set all entries of a path to specific values, or change multiple entries in different ways in one step.
Sends arbitrary commands to an RouterOS node and returns the results read from the device. This module includes an argument that will cause the module to wait for a specific condition before returning or timing out if the condition is not met.
The module always indicates a (changed) status. You can use the changed_when task property to determine whether a command task actually resulted in a change or not.
No special setup is needed; the module needs to be run on a host that can connect to the device’s API. The most common case is that the module is run on localhost, either by using hosts:localhost in the playbook, or by using delegate_to:localhost for the task. The following example shows how to run the equivalent of /ipaddressprint:
Using the community.routeros.api module defaults group
+
Using the community.routeros.api module defaults group
To avoid having to specify common parameters for all the API based modules in every task, you can use the community.routeros.api module defaults group:
----name:RouterOS test with API
@@ -221,7 +221,7 @@
Here all three tasks will use the options set for the module defaults group.
It is recommended to always use tls=true when connecting with the API, even if you are only connecting to the device through a trusted network. The following options control how TLS/SSL is used:
force_no_cert:
@@ -239,11 +239,11 @@
We recommend to create a CA certificate that is used to sign the certificates for your RouterOS devices, and have the certificates include the correct hostname(s), including the IP of the device. That way, you can fully enable TLS and be sure that you always talk to the correct device.
Please follow the instructions in the community.cryptoHow to create a small CA guide to set up a CA certificate and sign a certificate for your router. You should add a Subject Alternative Name for the IP address (for example IP:192.168.1.1) and - if available - for the DNS name (for example DNS:router.local) to the certificate.
Installing the certificate is best done with the SSH connection. (See the How to connect to RouterOS devices with SSH guide for more information.) Once the certificate has been installed, and the HTTPS API enabled, it’s easier to work with the API, since it has a quite a few less problems, and returns data as JSON objects instead of text you first have to parse.
First you have to convert the certificate and its private key to a PKCS #12 bundle. This can be done with the community.crypto.openssl_pkcs12. The following playbook assumes that the certificate is available as keys/{{inventory_hostname}}.pem, and its private key is available as keys/{{inventory_hostname}}.key. It generates a random passphrase to protect the PKCS#12 file.
When using the community.routeros.command module or the community.routeros.api module modules, you need to pass text data in quoted form. While in some cases quoting is not needed (when passing IP addresses or names without spaces, for example), in other cases it is required, like when passing a comment which contains a space.
The community.routeros collection provides a set of Jinja2 filter plugins which helps you with these tasks:
The SSH-based modules do not support arbitrary symbols in the router’s identity. If you are having trouble connecting to your device, please make sure that your MikroTik’s identity contains only alphanumeric characters and dashes. Also make sure that the identity string is not longer than 19 characters (see issue for details). Similar problems can happen for unsupported characters in your username.
The community.routeros.command module does not support nesting commands and expects every command to start with a forward slash (/). Running the following command will produce an error:
The following index documents all environment variables declared by plugins in collections.
Environment variables used by the ansible-core configuration are documented in Ansible Configuration Settings.
Collects a base set of device facts from a remote device that is running RouterOS. This module prepends all of the base network fact keys with ansible_net_<fact>. The facts module will always collect a base set of facts from the device and can enable or disable collection of additional facts.
Facts returned by this module are added/updated in the hostvars host facts and can be referenced by name just like any other host fact. They do not need to be registered in order to use them.
-name:Join arguments for a RouterOS CLI commandansible.builtin.set_fact:arguments:"{{['foo=bar','comment=foo is bar']|community.routeros.join}}"
@@ -190,7 +190,7 @@
This describes keyword parameters of the filter. These are the values key1=value1, key2=value2 and so on in the following
example: input|community.routeros.list_to_dict(key1=value1,key2=value2,...)
-name:Convert a list to a dictionaryansible.builtin.set_fact:dictionary:"{{['foo=bar','comment=foo is bar']|community.routeros.list_to_dict}}"
@@ -230,7 +230,7 @@ example: input
-
-name:Quote a RouterOS CLI command argumentansible.builtin.set_fact:quoted:"{{'comment=this is a "comment"'|community.routeros.quote_argument}}"
@@ -190,7 +190,7 @@
-name:Quote a RouterOS CLI command argument's valueansible.builtin.set_fact:quoted:"{{'this is a "comment"'|community.routeros.quote_argument_value}}"
@@ -190,7 +190,7 @@
-name:Split command into list of argumentsansible.builtin.set_fact:argument_list:"{{'foo=bar comment="foo is bar" baz'|community.routeros.split}}"
@@ -189,7 +189,7 @@