community.routeros.api_find_and_modify module – Find and modify information using the API
Note
This module is part of the community.routeros collection (version 3.0.0).
It is not included in ansible-core
.
To check whether it is installed, run ansible-galaxy collection list
.
To install it, use: ansible-galaxy collection install community.routeros
.
You need further requirements to be able to use this module,
see Requirements for details.
To use it in a playbook, specify: community.routeros.api_find_and_modify
.
New in community.routeros 2.1.0
Synopsis
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.
Requirements
The below requirements are needed on the host that executes this module.
librouteros
Python >= 3.6 (for librouteros)
Parameters
Parameter |
Comments |
---|---|
Whether to allow that no match is found. If not specified, this value is induced from whether Choices:
|
|
PEM formatted file that contains a CA certificate to be used for certificate validation. See also |
|
Use the specified encoding when communicating with the RouterOS device. Default is Default: |
|
Fields to search for. The module will only consider entries in the given Use YAML Note that if the dictionary specified here is empty, every entry in the path will be matched. |
|
Set to See also Note: this forces the use of anonymous Diffie-Hellman (ADH) ciphers. The protocol is susceptible to Man-in-the-Middle attacks, because the keys used in the exchange are not authenticated. Instead of simply connecting without a certificate to “make things work” have a look at Choices:
|
|
RouterOS hostname API. |
|
RouterOS user password. |
|
Path to query. An example value is |
|
RouterOS api port. If Defaults are |
|
Make sure that there are no more matches than this number. If there are more matches, fail instead of modifying anything. If not specified, there is no upper limit. |
|
Make sure that there are no less matches than this number. If there are less matches, fail instead of modifying anything. Default: |
|
Timeout for the request. Default: |
|
If is set TLS will be used for RouterOS API connection. Choices:
|
|
RouterOS login user. |
|
Set to See also Choices:
|
|
Set to See also Note: instead of simply deactivating certificate validations to “make things work”, please consider creating your own CA certificate and using it to sign certificates used for your router. You can tell the module about your CA certificate with the Choices:
|
|
On all entries matching the conditions in Use YAML |
Attributes
Attribute |
Support |
Description |
---|---|---|
Action group: community.routeros.api |
Use |
|
Support: full |
Can run in |
|
Support: full |
Will return details on what has changed (or possibly needs changing in |
|
Platform: RouterOS |
Target OS/families that can be operated against. |
Notes
Note
If you want to change values based on their old values (like change all comments ‘foo’ to ‘bar’) and make sure that there are at least N such values, you can use
require_matches_min=N
together withallow_no_matches=true
. This will make the module fail if there are less than N such entries, but not if there is no match. The latter case is needed for idempotency of the task: once the values have been changed, there should be no further match.
See Also
See also
- community.routeros.api
Ansible module for RouterOS API.
- community.routeros.api_facts
Collect facts from remote devices running MikroTik RouterOS using the API.
- community.routeros.api_modify
Modify data at paths with API.
- community.routeros.api_info
Retrieve information from API.
- How to connect to RouterOS devices with the RouterOS API
How to connect to RouterOS devices with the RouterOS API
Examples
---
- name: Rename bridge from 'bridge' to 'my-bridge'
community.routeros.api_find_and_modify:
hostname: "{{ hostname }}"
password: "{{ password }}"
username: "{{ username }}"
path: interface bridge
find:
name: bridge
values:
name: my-bridge
- name: Change IP address to 192.168.1.1 for interface bridge - assuming there is only one
community.routeros.api_find_and_modify:
hostname: "{{ hostname }}"
password: "{{ password }}"
username: "{{ username }}"
path: ip address
find:
interface: bridge
values:
address: "192.168.1.1/24"
# If there are zero entries, or more than one: fail! We expected that
# exactly one is configured.
require_matches_min: 1
require_matches_max: 1
Return Values
Common return values are documented here, the following are the fields unique to this module:
Key |
Description |
---|---|
The number of entries that were modified. Returned: success Sample: |
|
A list of all elements for the current path after a change was made. Returned: success Sample: |
|
A list of all elements for the current path before a change was made. Returned: success Sample: |