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
99 stars 45 forks source link

api_modify: Some routes shows "changed" when they shouldn't #148

Closed Igorgro closed 1 year ago

Igorgro commented 1 year ago
SUMMARY

Some routes (I currently experiencing this only in ip dhcp-client, but there can be more) show changed, when there actually no changes. For example when I executing the following task muliple times:

- name: Set DHCP client
  community.routeros.api_modify:
    path: ip dhcp-client
    data:
      - interface: ether1
        add-default-route: True
        default-route-distance: 1
        disabled: false
        use-peer-dns: True
        use-peer-ntp: True
        dhcp-options: ""

it always shows changed status, when no actually changes are performed (it is visible when enabling verbose output and comparing old_data and new_data)

ISSUE TYPE
COMPONENT NAME

community.routeros.api_modify

ANSIBLE VERSION
ansible [core 2.14.1]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.10/site-packages/ansible
  ansible collection location = /usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.10.9 (main, Dec 19 2022, 17:35:49) [GCC 12.2.0] (/usr/bin/python)
  jinja version = 3.1.2
  libyaml = True
COLLECTION VERSION
Collection         Version
------------------ -------
community.routeros 2.5.0  
CONFIGURATION
OS / ENVIRONMENT
STEPS TO REPRODUCE

Run a playbook with the task that modifies ip dhcp-client path of Mikrotik router

- name: Set DHCP client
  community.routeros.api_modify:
    path: ip dhcp-client
    data:
      - interface: ether1
        add-default-route: True
        default-route-distance: 1
        disabled: false
        use-peer-dns: True
        use-peer-ntp: True
        dhcp-options: ""
EXPECTED RESULTS

The status of task should be ok, not changed when applying the same configuration

ACTUAL RESULTS
PLAY RECAP *************
localhost                  : ok=0    changed=1
felixfontein commented 1 year ago

Please use --diff to figure out what the module thinks it is changing.

Igorgro commented 1 year ago

When using --diff --check it shows the following:

--- before
+++ after
@@ -15,6 +15,7 @@
             ".id": "*5",
             "add-default-route": true,
             "default-route-distance": 1,
+            "dhcp-options": "",
             "disabled": false,
             "interface": "ether1",
             "use-peer-dns": true,

I need this option to be unset, but it doesn't accept null or empty object/array

felixfontein commented 1 year ago

Ok, that means we are handling the dhcp-options value wrong. I have to try that out, and I'm also wondering whether the behavior changed between ROS6 and ROS7 for it.

felixfontein commented 1 year ago

Verified: on both ROS6 and ROS7, dhcp-options's empty value should be '' (similar to comments).

felixfontein commented 1 year ago

154 should fix this.