community / community.routeros / 2.14.0 / module / api_find_and_modify Find and modify information using the API | "added in version" 2.1.0 of community.routeros" Authors: Felix Fontein (@felixfontein)community.routeros.api_find_and_modify (2.14.0) — module
Install with ansible-galaxy collection install community.routeros:==2.14.0
collections: - name: community.routeros version: 2.14.0
Allows to find entries for a path by conditions and modify the values of these entries.
Use the M(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.
--- - 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
tls: aliases: - ssl default: false description: - If is set TLS will be used for RouterOS API connection. required: false type: bool find: description: - Fields to search for. - The module will only consider entries in the given O(path) that match all fields provided here. - Use YAML V(~), or prepend keys with V(!), to specify an unset value. - Note that if the dictionary specified here is empty, every entry in the path will be matched. required: true type: dict path: description: - Path to query. - An example value is V(ip address). This is equivalent to running C(/ip address) in the RouterOS CLI. required: true type: str port: description: - RouterOS api port. If O(tls) is set, port will apply to TLS/SSL connection. - Defaults are V(8728) for the HTTP API, and V(8729) for the HTTPS API. type: int values: description: - On all entries matching the conditions in O(find), set the keys of this option to the values specified here. - Use YAML V(~), or prepend keys with V(!), to specify to unset a value. required: true type: dict ca_path: description: - PEM formatted file that contains a CA certificate to be used for certificate validation. - See also O(validate_cert_hostname). Only used when O(tls=true) and O(validate_certs=true). type: path version_added: 1.2.0 version_added_collection: community.routeros timeout: default: 10 description: - Timeout for the request. type: int version_added: 2.3.0 version_added_collection: community.routeros encoding: default: ASCII description: - Use the specified encoding when communicating with the RouterOS device. - Default is V(ASCII). Note that V(UTF-8) requires librouteros 3.2.1 or newer. type: str version_added: 2.1.0 version_added_collection: community.routeros hostname: description: - RouterOS hostname API. required: true type: str password: description: - RouterOS user password. required: true type: str username: description: - RouterOS login user. required: true type: str force_no_cert: default: false description: - Set to V(true) to connect without a certificate when O(tls=true). - See also O(validate_certs). - B(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 O(validate_certs) and O(ca_path). type: bool version_added: 2.4.0 version_added_collection: community.routeros validate_certs: default: true description: - Set to V(false) to skip validation of TLS certificates. - See also O(validate_cert_hostname). Only used when O(tls=true). - B(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 O(ca_path) option. type: bool version_added: 1.2.0 version_added_collection: community.routeros allow_no_matches: description: - Whether to allow that no match is found. - If not specified, this value is induced from whether O(require_matches_min) is 0 or larger. type: bool require_matches_max: description: - 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. type: int require_matches_min: default: 0 description: - Make sure that there are no less matches than this number. - If there are less matches, fail instead of modifying anything. type: int validate_cert_hostname: default: false description: - Set to V(true) to validate hostnames in certificates. - See also O(validate_certs). Only used when O(tls=true) and O(validate_certs=true). type: bool version_added: 1.2.0 version_added_collection: community.routeros
match_count: description: - The number of entries that matched the criteria in O(find). returned: success sample: 1 type: int modify__count: description: - The number of entries that were modified. returned: success sample: 1 type: int new_data: description: - A list of all elements for the current path after a change was made. elements: dict returned: success sample: - .id: '*1' actual-interface: bridge address: 192.168.1.1/24 comment: awesome disabled: false dynamic: false interface: bridge invalid: false network: 192.168.1.0 type: list old_data: description: - A list of all elements for the current path before a change was made. elements: dict returned: success sample: - .id: '*1' actual-interface: bridge address: 192.168.88.1/24 comment: defconf disabled: false dynamic: false interface: bridge invalid: false network: 192.168.88.0 type: list