ansible-collections / ansible.utils

A collection of ansible utilities for the content creator.
GNU General Public License v3.0
74 stars 75 forks source link

ansible.utils.ipaddr('host/prefix') should not parse non CIDR IP. #372

Open ijajmulani opened 1 week ago

ijajmulani commented 1 week ago
SUMMARY
ISSUE TYPE
COMPONENT NAME
ANSIBLE VERSION
ansible [core 2.16.3]
  config file = /opt/IMAppliance/ansible/ansible.cfg
  configured module search path = ['/opt/IMAppliance/ansible/library', '/opt/ansible/library']
  ansible python module location = /usr/lib/python3.12/site-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /bin/ansible
  python version = 3.12.3 (main, Jun 19 2024, 10:06:03) [GCC 8.5.0 20210514 (Red Hat 8.5.0-22)] (/usr/bin/python3.12)
  jinja version = 3.1.2
  libyaml = True
COLLECTION VERSION
# /usr/share/ansible/collections/ansible_collections
Collection    Version
------------- -------
ansible.utils 5.0.0
OS / ENVIRONMENT

RHEL 8.10

STEPS TO REPRODUCE
ansible -i localhost, all -m debug -a "msg={{ '203.0.113.23' | ansible.utils.ipaddr('host/prefix') }}" 
EXPECTED RESULTS
localhost | SUCCESS => {
    "msg": ""
}
ACTUAL RESULTS
<!--- Describe what actually happened. If possible run with extra verbosity (-vvvv) -->
localhost | SUCCESS => {
    "msg": "203.0.113.23/32"
}
ijajmulani commented 1 week ago

I did a little analysis isn't the conditioned mentioned here should be like

https://github.com/ansible-collections/ansible.utils/blame/main/plugins/plugin_utils/base/ipaddr_utils.py#L102-L105

def _address_prefix_query(v):
    if v.ip in (v.network, v.broadcast):
        return False
    return str(v.ip) + "/" + str(v.prefixlen)
ijajmulani commented 1 week ago

I have raised PR for same. Let me know for further changes.

ijajmulani commented 5 days ago

Looks my pr will regress existing functionality. Can you please let me know whether this is an issue or actual behavior?