Unable to call/use ansible.utils.ipmath

Hi all,

Having some issues calling a specific plugin - ansible.utils.ipmath - with ansible core 2.18.6.

When I call “ipmath”, I get my expected output. However, this is using ansible.netcommon.ipmath which is deprecated

[DEPRECATION WARNING]: Filter "ansible.netcommon.ipmath" has been deprecated. Use 'ansible.utils.ipmath' module instead. This feature will be removed from ansible.netcommon in a release after 2024-01-01.
Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.

If I explicitly call either of those (ansible.netcommon.ipmath, or ansible.utils.ipmath) directly I get errors.

FAILED! => {"msg": "lookup plugin (ansible.netcommon.ipmath) not found"}
FAILED! => {"msg": "lookup plugin (ansible.utils.ipmath) not found"}

despite the collection being installed

(.venv) user@Ansible:~/AnsibleProject$ ansible-galaxy collection install ansible.utils
Starting galaxy collection install process
Nothing to do. All requested collections are already installed. If you want to reinstall them, consider using `--force`.

Is there a way of explicitly telling ansible I don’t want to use netcommon, and use utils instead? I’m presuming it would work as the collection is already installed, and despite me not being able to call the full name, ansible would find the appropriate plugin from utils, as it is doing with netcommon currently.

Thanks

Task code:

- name: Generate SVI and HSRP IPs per VLAN
  set_fact:
    svis: >-
      {% set result = [] %}
      {% for vlan in vlans | default([]) %}
        {% if 'subnet' in vlan %}
          {% set subnet = vlan.subnet %}
          {% set prefix = vlan.subnet.split('/')[-1] %}
          {% set hsrp_ip = subnet | ipmath(1) %}
          {% set svi_ip = subnet | ipmath(1 + switch_id) %}
          {% set _ = result.append({
            'vlan_id': vlan.vlan_id,
            'ip': svi_ip ~ '/' ~ prefix,
            'hsrp_ip': hsrp_ip
          }) %}
        {% endif %}
      {% endfor %}
      {{ result }}

What version of ansible.utils is installed? It looks like the filter is new in ansible.utils 5.1.2. https://docs.ansible.com/ansible/latest/collections/ansible/utils/ipmath_filter.html

5.1.2. is installed.

I’ve been playing around with it this morning and turned out to be user error. Misread some old posts and now have it working calling ansible.utils.ipmath explicitly.

Couldn’t delete my pending post, but I’ve marked this as solved. Thanks for your time :slight_smile:

1 Like