Unknown error with arguments of roles

Hi all,

I have a role lr_nsupdate so:
- - -
- name: Show calling args
  debug:
    var: ca

- name: Update DNS master server
  community.general.nsupdate:
    key_name: '{{ key_name }}'
    key_algorithm: '{{ algorithm }}'
    key_secret: '{{ secret }}'
    server: '{{ server }}'
    zone: '{{ ca.zone | default(None) }}'
    record: '{{ ca.owner_name }}'
    ttl: '{{ the_ttl | default(3600) }}'
    type: '{{ ca.type }}'
    value: '{{ ca.RDATA }}'
    state: '{{ ca.state | default(present) }}‘
- - -
When I call it so in another role:
- - -
- name: 'Delete CNAME db.lrau.net'
  include_role:
    name: lr_nsupdate
  vars:
    ca:
      ca.owner_name: 'db.lrau.net.'
      ca.state: 'absent'
      ca.type: ‚CNAME‘
- - -
I get:
- - -
ok: [dbo5] => {
    "ca": {
        "ca.owner_name": "db.lrau.net.",
        "ca.state": "absent",
        "ca.type": "CNAME"
    }
}

TASK [lr_nsupdate : Update DNS master server] **************************************************************************************************************************************************************************************************************
fatal: [dbo5]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'dict object' has no attribute 'owner_name'\n\nThe error appears to be in '/usr/local/etc/ansible/roles/lr_nsupdate/tasks/main.yaml': line 31, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: Update DNS master server\n ^ here\n“}
- - -

Any help welcome,
Axel

You either change it to ca.ca.owner_name or remove the second ‘ca’ for each dict member.

Naturally of course, (-;

Thanks, Axel

After fixing the argument issue, I’m stuck with this:

I have a role lr_nsupdate so:
- - -

- name: Show calling args
  debug:
    var: ca

- name: Update DNS master server
  community.general.nsupdate:
    key_name: '{{ key_name }}'
    key_algorithm: '{{ algorithm }}'
    key_secret: '{{ secret }}'
    server: '{{ server }}'
    zone: '{{ ca.zone | default(None) }}'
    record: '{{ ca.owner_name }}'
    ttl: '{{ the_ttl | default(3600) }}'
    type: '{{ ca.type }}'
    value: '{{ ca.RDATA | default(None) }}'
    state: "{{ ca.state | default('present') }}"
  delegate_to: localhost
- - -
When I call it so in another role:
- - -
- name: 'Delete CNAME db.lrau.net'
  include_role:
    name: lr_nsupdate
  vars:
    ca:
      owner_name: 'db.lrau.net.'
      state: 'absent'
      type: ‚CNAME‘
- - -
I get:
- - -
TASK [lr_nsupdate : Show calling args] *********************************************************************************************************************************************************************************************************************
ok: [dbo5] => {
    "ca": {
        "owner_name": "db.lrau.net.",
        "state": "absent",
        "type": "CNAME"
    }
}

TASK [lr_nsupdate : Update DNS master server] **************************************************************************************************************************************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: IndexError: string index out of range
fatal: [dbo5 -> localhost]: FAILED! => {"changed": false, "module_stderr": "Shared connection to localhost closed.\r\n", "module_stdout": "Traceback (most recent call last):\r\n File \"/root/.ansible/tmp/ansible-tmp-1639333586.086785-18489-58263131450333/AnsiballZ_nsupdate.py\", line 100, in <module>\r\n _ansiballz_main()\r\n File \"/root/.ansible/tmp/ansible-tmp-1639333586.086785-18489-58263131450333/AnsiballZ_nsupdate.py\", line 92, in _ansiballz_main\r\n invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\r\n File \"/root/.ansible/tmp/ansible-tmp-1639333586.086785-18489-58263131450333/AnsiballZ_nsupdate.py\", line 41, in invoke_module\r\n run_name='__main__', alter_sys=True)\r\n File \"/usr/local/lib/python3.7/runpy.py\", line 205, in run_module\r\n return _run_module_code(code, init_globals, run_name, mod_spec)\r\n File \"/usr/local/lib/python3.7/runpy.py\", line 96, in _run_module_code\r\n mod_name, mod_spec, pkg_name, script_name)\r\n File \"/usr/local/lib/python3.7/runpy.py\", line 85, in _run_code\r\n exec(code, run_globals)\r\n File \"/tmp/ansible_community.general.nsupdate_payload_3364ymle/ansible_community.general.nsupdate_payload.zip/ansible_collections/community/general/plugins/modules/nsupdate.py\", line 483, in <module>\r\n File \"/tmp/ansible_community.general.nsupdate_payload_3364ymle/ansible_community.general.nsupdate_payload.zip/ansible_collections/community/general/plugins/modules/nsupdate.py\", line 461, in main\r\n File \"/tmp/ansible_community.general.nsupdate_payload_3364ymle/ansible_community.general.nsupdate_payload.zip/ansible_collections/community/general/plugins/modules/nsupdate.py\", line 233, in __init__\r\nIndexError: string index out of range\r\n", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}

Is this a bug in the nsupdate module?

Thanks, Axel

- name: Update DNS master server
  community.general.nsupdate:
    key_name: '{{ key_name }}'
    key_algorithm: '{{ algorithm }}'
    key_secret: '{{ secret }}'
    server: '{{ server }}'
    zone: '{{ ca.zone | default(None) }}'
    record: '{{ ca.owner_name }}'
    ttl:  '{{ the_ttl | default(3600) }}'
    type: '{{ ca.type }}'
    value: '{{ ca.RDATA | default(None) }}'
    state: "{{ ca.state | default('present') }}"
  delegate_to: localhost

Those default(None) should probably be default(omit).

Is this a bug in the nsupdate module?

I expect it is, or at least it could be handled better. But my guess is it’s being triggered by your use of None instead of omit.

YES!Thanks a lot, Axel