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
95 stars 44 forks source link

Modify address lists without affecting others #283

Closed ewysong closed 3 weeks ago

ewysong commented 4 months ago
SUMMARY

Ability to modify address-lists without affecting others. I'm sure this would apply to other areas as well, such as /ip/address if an interface has more than one address.

ISSUE TYPE
COMPONENT NAME

I've tried both community.routeros.api_modify and community.routeros.api_find_and_modify to try and make this work, but I've not found a way to modify an address list from /ip/firewall/address-list to include only the addresses listed in the playbook and to not remove any other address lists in the configuration.

ADDITIONAL INFORMATION
- name: Firewall list
  delegate_to: localhost
  community.routeros.api_modify:
    path: ip firewall address-list
    data:
      - list: example_list
        address: 192.168.1.0/24
      - list: example_list
        address: 192.168.2.0/24

If I add handle_absent_entries: remove, then it removes any other address lists in the configuration but not listed in the playbook. I'd like to just remove any addresses in the address list itself that are not in the configuration.

irrwitzer42 commented 4 months ago

From my understanding, there is already a PR for this problem (I'm also having): https://github.com/ansible-collections/community.routeros/pull/160

I also have this problem mainly with address-lists, but I like @phox142 's generic approach, because I'm quite sure there will be other "paths" with the same problem.

An other problem with the current (2.15.0) implementation is, that with "handle_absent_entries: remove" one can't add/update address-lists with conditionals, as (at least AFAIK) conditionals work only for tasks, but each task has it's own "data" variable, so each new task will overwrite the changes of the previous one.

Looking forward to a solution, if it's PR160, or something else, but I think this great collection needs one asap ;-)

Thanks guys for your work by the way and looking forward to everything you add to this collection!

ewysong commented 4 months ago

@irrwitzer42 you're absolutely correct. I checked open issues for this but not PRs.

To my knowledge you're correct regarding conditionals as well. I tried (a loop to be exact) and had the same issue (only the last value was present when it completed).

Appreciate the work on this as well. I know it's a small community.

If it's best this be issue be closed since there's already a PR, feel free to close it it @felixfontein!

felixfontein commented 3 weeks ago

This can now be achieved using #305.