Skip to content

nameserver_record_info returns type builtin_function_or_method for the result.values #289

@serpro69

Description

@serpro69
SUMMARY

I was trying to add an until to the nameserver_record_info that would check for result values being equal to IP address that I expect the dns name to resolve to, but it was failing with no element found at index errors. Doing some debugging, I saw that results[0].result[0].values returns non-json-serializable object "builtin_function_or_method".

ISSUE TYPE
  • Bug Report
COMPONENT NAME

nameserver_record_info

ANSIBLE VERSION
ansible [core 2.18.7]
  config file = /home/sergio/Projects/***/ansible/ansible.cfg
  configured module search path = ['/home/sergio/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /nix/store/lv76m7hx46mww5lw6mw8h9f1mbwgvahp-python3.12-ansible-core-2.18.7/lib/python3.12/site-packages/ansible
  ansible collection location = /home/sergio/Projects/***/ansible/galaxy/collections
  executable location = /nix/store/lv76m7hx46mww5lw6mw8h9f1mbwgvahp-python3.12-ansible-core-2.18.7/bin/ansible
  python version = 3.12.11 (main, Jun  3 2025, 15:41:47) [GCC 14.3.0] (/nix/store/vxl8pzgkkw8vdb4agzwm58imrfclmfrx-python3-3.12.11/bin/python3.12)
  jinja version = 3.1.6
  libyaml = True

COLLECTION VERSION
# /home/sergio/Projects/***/ansible/galaxy/collections/ansible_collections
Collection    Version
------------- -------
community.dns 3.3.4

# /nix/store/qfvzbjazdahp00hvqvwqdzfcxc85davs-python3.12-ansible-11.8.0/lib/python3.12/site-packages/ansible_collections
Collection    Version
------------- -------
community.dns 3.2.6
CONFIGURATION

OS / ENVIRONMENT
STEPS TO REPRODUCE
    - name: Retrieve A values
      community.dns.nameserver_record_info:
        name:
          - google.com
        type: A
      register: ns_info

    - name: Show values
      ansible.builtin.debug:
        msg: '{{ ns_info.results[0].result[0].values }}'

    - name: Try to convert to json
      ansible.builtin.debug:
        msg: '{{ ns_info.results[0].result[0].values | to_json }}'
EXPECTED RESULTS

Should return a list of elements of values that can be serialized and hence accessed.

ACTUAL RESULTS
TASK [Retrieve A values] *****************************************************************************************************************************************************
ok: [localhost] => changed=false
  results:
  - name: google.com
    result:
    - nameserver: ns1.google.com.
      values:
      - address: 142.250.74.14
    - nameserver: ns2.google.com.
      values:
      - address: 142.250.74.14
    - nameserver: ns3.google.com.
      values:
      - address: 142.250.74.14
    - nameserver: ns4.google.com.
      values:
      - address: 142.250.74.14

TASK [Show values] ***********************************************************************************************************************************************************
ok: [localhost] =>
  msg: <built-in method values of dict object at 0x7ffff4200540>

TASK [Try to convert to json] ************************************************************************************************************************************************
fatal: [localhost]: FAILED! =>
  msg: 'Unexpected templating type error occurred on ({{ ns_info.results[0].result[0].values | to_json }}): Object of type builtin_function_or_method is not JSON serializable. Object of type builtin_function_or_method is not JSON serializable'

PLAY RECAP *******************************************************************************************************************************************************************
localhost                  : ok=3    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions