ansible-collections / community.routeros

Ansible modules for managing MikroTik RouterOS instances.
https://galaxy.ansible.com/ui/repo/published/community/routeros/
GNU General Public License v3.0
103 stars 46 forks source link

Status "changed" on BGP connection and template #316

Closed tim427 closed 1 month ago

tim427 commented 1 month ago
SUMMARY

When using:

community.routeros.api_modify:
    path: 'routing bgp connection'

I receive the status "changed" and the ID is indeed changed:

image

See following (nothing has changed):

`-vvvv` output ``` changed: [routerhostname -> localhost] => { "changed": true, "diff": { "after": { "data": [ { ".id": "*F", "address-families": "ip", "as": 4321, "disabled": false, "name": "ixname-ipv4", "output.network": "bgp-networks", "router-id": "1.2.3.18", "routing-table": "main" }, { ".id": "*10", "address-families": "ipv6", "as": 4321, "disabled": false, "name": "ixname-ipv6", "output.network": "bgp-networks", "router-id": "1.2.3.18", "routing-table": "main" } ] }, "before": { "data": [ { ".id": "*F", "address-families": "ip", "as": 4321, "disabled": false, "name": "ixname-ipv4", "output.network": "bgp-networks", "router-id": "1.2.3.18", "routing-table": "main" }, { ".id": "*10", "address-families": "ipv6", "as": 4321, "disabled": false, "name": "ixname-ipv6", "output.network": "bgp-networks", "router-id": "1.2.3.18", "routing-table": "main" } ] } }, "invocation": { "module_args": { "ca_path": null, "data": [ { "address-families": "ip", "as": "4321", "disabled": false, "name": "ixname-ipv4", "output.network": "bgp-networks", "router-id": "1.2.3.18", "routing-table": "main" }, { "address-families": "ipv6", "as": "4321", "disabled": false, "name": "ixname-ipv6", "output.network": "bgp-networks", "router-id": "1.2.3.18", "routing-table": "main" } ], "encoding": "ASCII", "ensure_order": true, "force_no_cert": false, "handle_absent_entries": "remove", "handle_entries_content": "remove", "handle_read_only": "error", "handle_write_only": "create_only", "hostname": "routerhostname", "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "path": "routing bgp template", "port": null, "restrict": [ { "field": "name", "invert": false, "match_disabled": false, "regex": "ixname-ipv[4,6]", "values": null } ], "timeout": 10, "tls": true, "username": "tim", "validate_cert_hostname": false, "validate_certs": true } }, "new_data": [ { ".id": "*F", "address-families": "ip", "as": 4321, "disabled": false, "name": "ixname-ipv4", "output.network": "bgp-networks", "router-id": "1.2.3.18", "routing-table": "main" }, { ".id": "*10", "address-families": "ipv6", "as": 4321, "disabled": false, "name": "ixname-ipv6", "output.network": "bgp-networks", "router-id": "1.2.3.18", "routing-table": "main" } ], "old_data": [ { ".id": "*F", "address-families": "ip", "as": 4321, "disabled": false, "name": "ixname-ipv4", "output.network": "bgp-networks", "router-id": "1.2.3.18", "routing-table": "main" }, { ".id": "*10", "address-families": "ipv6", "as": 4321, "disabled": false, "name": "ixname-ipv6", "output.network": "bgp-networks", "router-id": "1.2.3.18", "routing-table": "main" } ] } ```

Whe using: When using:

community.routeros.api_modify:
    path: 'routing bgp template'

I receive status "changed", without any actual changes. See following (only the .id has changed):

`-vvvv` output ``` changed: [routerhostname -> localhost] => { "changed": true, "diff": { "after": { "data": [ { ".id": "*A0", "address-families": "ip", "as": 4321, "disabled": true, "local.address": "1.2.3.18", "local.role": "ebgp", "name": "ixname-as1234-1-ipv4", "output.network": "bgp-networks", "remote.address": "1.2.3.253", "remote.as": 1234, "router-id": "1.2.3.18", "routing-table": "main", "templates": "ixname-ipv4" }, { ".id": "*A1", "address-families": "ipv6", "as": 4321, "disabled": true, "local.address": "2001:1:2:3:4::304:1", "local.role": "ebgp", "name": "ixname-as1234-1-ipv6", "output.network": "bgp-networks", "remote.address": "2001:1:2:3:4::e2", "remote.as": 1234, "router-id": "1.2.3.18", "routing-table": "main", "templates": "ixname-ipv6" } ] }, "before": { "data": [ { ".id": "*94", "address-families": "ip", "as": 4321, "disabled": true, "local.address": "1.2.3.18", "local.role": "ebgp", "name": "ixname-as1234-1-ipv4", "output.network": "bgp-networks", "remote.address": "1.2.3.253", "remote.as": 1234, "router-id": "1.2.3.18", "routing-table": "main", "templates": "ixname-ipv4" }, { ".id": "*95", "address-families": "ipv6", "as": 4321, "disabled": true, "local.address": "2001:1:2:3:4::304:1", "local.role": "ebgp", "name": "ixname-as1234-1-ipv6", "output.network": "bgp-networks", "remote.address": "2001:1:2:3:4::e2", "remote.as": 1234, "router-id": "1.2.3.18", "routing-table": "main", "templates": "ixname-ipv6" } ] } }, "invocation": { "module_args": { "ca_path": null, "data": [ { ".id": "*A0", "disabled": true, "local.address": "1.2.3.18", "local.role": "ebgp", "name": "ixname-as1234-1-ipv4", "remote.address": "1.2.3.253", "remote.as": "1234", "templates": "ixname-ipv4" }, { ".id": "*A1", "disabled": true, "local.address": "2001:1:2:3:4::304:1", "local.role": "ebgp", "name": "ixname-as1234-1-ipv6", "remote.address": "2001:1:2:3:4::e2", "remote.as": "1234", "templates": "ixname-ipv6" } ], "encoding": "ASCII", "ensure_order": true, "force_no_cert": false, "handle_absent_entries": "remove", "handle_entries_content": "remove", "handle_read_only": "error", "handle_write_only": "create_only", "hostname": "routerhostname", "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "path": "routing bgp connection", "port": null, "restrict": [ { "field": "name", "invert": false, "match_disabled": false, "regex": "ixname-as1234-1-ipv[4,6]", "values": null } ], "timeout": 10, "tls": true, "username": "tim", "validate_cert_hostname": false, "validate_certs": true } }, "new_data": [ { ".id": "*A0", "address-families": "ip", "as": 4321, "disabled": true, "local.address": "1.2.3.18", "local.role": "ebgp", "name": "ixname-as1234-1-ipv4", "output.network": "bgp-networks", "remote.address": "1.2.3.253", "remote.as": 1234, "router-id": "1.2.3.18", "routing-table": "main", "templates": "ixname-ipv4" }, { ".id": "*A1", "address-families": "ipv6", "as": 4321, "disabled": true, "local.address": "2001:1:2:3:4::304:1", "local.role": "ebgp", "name": "ixname-as1234-1-ipv6", "output.network": "bgp-networks", "remote.address": "2001:1:2:3:4::e2", "remote.as": 1234, "router-id": "1.2.3.18", "routing-table": "main", "templates": "ixname-ipv6" } ], "old_data": [ { ".id": "*94", "address-families": "ip", "as": 4321, "disabled": true, "local.address": "1.2.3.18", "local.role": "ebgp", "name": "ixname-as1234-1-ipv4", "output.network": "bgp-networks", "remote.address": "1.2.3.253", "remote.as": 1234, "router-id": "1.2.3.18", "routing-table": "main", "templates": "ixname-ipv4" }, { ".id": "*95", "address-families": "ipv6", "as": 4321, "disabled": true, "local.address": "2001:1:2:3:4::304:1", "local.role": "ebgp", "name": "ixname-as1234-1-ipv6", "output.network": "bgp-networks", "remote.address": "2001:1:2:3:4::e2", "remote.as": 1234, "router-id": "1.2.3.18", "routing-table": "main", "templates": "ixname-ipv6" } ] } ```
ISSUE TYPE
COMPONENT NAME

api-modify

ANSIBLE VERSION
ansible [core 2.16.11]
  config file = /home/tim/ansible/ansible.cfg
  configured module search path = ['/home/tim/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3/dist-packages/ansible
  ansible collection location = /home/tim/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.11.2 (main, Aug 26 2024, 07:20:54) [GCC 12.2.0] (/usr/bin/python3)
  jinja version = 3.1.2
  libyaml = True
COLLECTION VERSION
# /usr/lib/python3/dist-packages/ansible_collections
Collection         Version
------------------ -------
community.routeros 2.19.0
CONFIGURATION
CONFIG_FILE() = /home/tim/ansible/ansible.cfg
DEFAULT_FORKS(/home/tim/ansible/ansible.cfg) = 140
DEFAULT_HOST_LIST(/home/tim/ansible/ansible.cfg) = ['/home/tim/ansible/inventories']
DEFAULT_LOAD_CALLBACK_PLUGINS(/home/tim/ansible/ansible.cfg) = True
DEFAULT_TIMEOUT(/home/tim/ansible/ansible.cfg) = 20
DEFAULT_VAULT_PASSWORD_FILE(/home/tim/ansible/ansible.cfg) = /home/tim/ansible/vault
DIFF_ALWAYS(/home/tim/ansible/ansible.cfg) = True
DIFF_CONTEXT(/home/tim/ansible/ansible.cfg) = 1
DISPLAY_SKIPPED_HOSTS(/home/tim/ansible/ansible.cfg) = False
INTERPRETER_PYTHON(/home/tim/ansible/ansible.cfg) = auto
RETRY_FILES_ENABLED(/home/tim/ansible/ansible.cfg) = True
OS / ENVIRONMENT

Debian 12.7

STEPS TO REPRODUCE
EXPECTED RESULTS

When no changes are applied, the status should ben "Ok" and the .id should not change.

ACTUAL RESULTS

See summary

felixfontein commented 1 month ago

You can run the module with diff and check mode (--diff -C) enabled to see what it thinks it is changing.

The reason seems to be that you provide "as" as a string, while the router returns it as an int. The module sees these as different values and thus tries to change the value.

tim427 commented 1 month ago

@felixfontein Perfect, that was indeed the cause. Thanks!