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

facts subset config is allways "changed" #20

Closed qaxi closed 3 years ago

qaxi commented 3 years ago
SUMMARY

Every time 'community.routeros.facts' subset 'config' returns data it's status is 'not changed' but it is false. Returned data are different on every run of 'community.routeros.facts' even configuration on device is not changed:

  1. there is date at the beggining of the file
  2. with "/export verbose" there are exported unconfigured services too and for example unconfigured '/interface ovpn-server server' contains random generated MAC address (tested on RouterBOARD 750G r3)
ISSUE TYPE
COMPONENT NAME

'community.routeros.facts' subset 'config'

ANSIBLE VERSION
CONFIGURATION
# ansible --version
ansible 2.10.6
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.8/dist-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 3.8.5 (default, Jul 28 2020, 12:59:40) [GCC 9.3.0]
OS / ENVIRONMENT

Ubuntu 20.04 RouterBOARD 750G r3 RouterOS 6.40.3

STEPS TO REPRODUCE

setup your inventory to an Mikrotik device (tested on RouterBOARD 750G r3)

---
- name: Mikrotik config1
  community.routeros.facts:
    gather_subset: config

- set_fact: cfg1="{{ ansible_net_config }}" 
- set_fact: cfg3="{{ ansible_net_config }}" 

- name: Mikrotik config2
  community.routeros.facts:
    gather_subset: config

- set_fact: cfg2="{{ ansible_net_config }}" 

- ansible.builtin.debug: 
    msg: "cfg1 is different from cfg2"
  when: cfg1 != cfg2

- ansible.builtin.debug: 
    msg: "cfg1 is not different from cfg1"
  when: cfg1 == cfg1

- ansible.builtin.debug: 
    msg: "cfg1 is not different from cfg3"
  when: cfg1 == cfg3
EXPECTED RESULTS

cfg1 should be the same cfg2 because device configuration did not changed

ACTUAL RESULTS

cfg1 and cfg2 are different. it makes very difficult to version those cfg files

felixfontein commented 3 years ago

"not changed" means that the task did not actively made any change, which is correct - facts modules must never change the state of a device.

qaxi commented 3 years ago

I understand it, but output data are always changed, and when you want to use them (save, version ...) Ansible learn it status as changed! I understand it is "feature" of RouterOS, but we should have an option to make it 'idempotent' ...

For date we should filter it, and for "MAC" problem limit output cfg just to changed configs '/export'

It is pitty to change behavior so this new behavior could be changed by for example another 'gather_subset' or parameter for 'gather_subset: config' for example 'config_verbose:' with default 'true'.