ansible-collections / community.general

Ansible Community General Collection
https://galaxy.ansible.com/ui/repo/published/community/general/
GNU General Public License v3.0
787 stars 1.45k forks source link

udm_dns_record: IPv4 not recognized #5880

Open Cinux90 opened 1 year ago

Cinux90 commented 1 year ago

Summary

I want to add a reverse zone entry in univention. But it failed because the IP is not an unicode object and I have no idea how to change that or if this is correct.

Also with ipv4 filter it is not working for me.

Any ideas whats wrong here?

Issue Type

Bug Report

Component Name

udm_dns_record

Ansible Version

$ ansible --version
ansible [core 2.14.1]
  config file = /home/cinux/workspace/ansible/ansible-inventory-on-prem/ansible.cfg
  configured module search path = ['/home/cinux/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/cinux/workspace/ansible/ansible-role-zfs/.env/lib/python3.10/site-packages/ansible
  ansible collection location = /home/cinux/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/cinux/workspace/ansible/ansible-role-zfs/.env/bin/ansible
  python version = 3.10.6 (main, Nov 14 2022, 16:10:14) [GCC 11.3.0] (/home/cinux/workspace/ansible/ansible-role-zfs/.env/bin/python)
  jinja version = 3.1.2
  libyaml = False

Community.general Version

$ ansible-galaxy collection list community.general
Collection        Version
----------------- -------
community.general 6.1.0  

Configuration

$ ansible-config dump --only-changed

OS / Environment

Ubuntu 22

Steps to Reproduce

- hosts: localhost
  tasks:
    - name: "Set reverse host record 192.168.123.7"
      delegate_to: dns-server
      community.general.udm_dns_record:
        name: 192.168.123.7
        zone: "123.168.192.in-addr.arpa"
        state: present
        type: ptr_record
        data:
          ptr_record: "testhost"

Expected Results

reverse entry created

Actual Results

...
TASK [Set reverse host record 192.168.123.7] *******************************************************************************************************************************************************************************************************************************
fatal: [localhost -> dns-server(192.168.122.193)]: FAILED! => {"changed": false, "msg": "handling PTR record for 192.168.123.7 in zone 123.168.192.in-addr.arpa failed: '192.168.123.7' does not appear to be an IPv4 or IPv6 address. Did you pass in a bytes (str in Python 2) instead of a unicode object?"}

Code of Conduct

ansibullbot commented 1 year ago

Files identified in the description:

If these files are incorrect, please update the component name section of the description or use the !component bot command.

click here for bot help

ansibullbot commented 1 year ago

cc @keachi click here for bot help

felixfontein commented 1 year ago

According to https://github.com/phihag/ipaddress/blob/master/ipaddress.py#L161 this should only happen on Python 2, since name should be of type str in https://github.com/ansible-collections/community.general/blob/main/plugins/modules/udm_dns_record.py#L161 (which only equals bytes on Python 2).

Could it be that dns-server is using Python 2? The correct PTR handling was only implemented recently (#3256) and might never have been tested with Python 2 so far.

In any case, it might help to change line 161 (https://github.com/ansible-collections/community.general/blob/main/plugins/modules/udm_dns_record.py#L161) to

            ipaddr_rev = ipaddress.ip_address(to_text(name)).reverse_pointer

where you need to add from ansible.module_utils.common.text.converters import to_text to the imports.

Cinux90 commented 1 year ago

Yes, you are completly right. dns-server runs python2:

root@ucs-6304:~# python --version
Python 2.7.13

As in the documentation of the udm_dns_record is stated that is need univention and python 2.6 or higher I expect that it works well.

Anyway, your workaround works fine for me. Thanks for that :+1:

(FYI: I used Univention in version 4 which supports python2. Version 5 will support python3)

felixfontein commented 1 year ago

Since this is not fixed, reopening.