Skip to content

Disagreement in Module Spec #38

@netgirard

Description

@netgirard

There seems to be a disagreement between the module spec and the cmlModule init function in plugins/module_utils/cml_utils.py.

Using python 3.11.10 and Ansible-core 2.17.4.

When I go to create a lab using this task:

  - name: Create lab
    cisco.cml.cml_lab:
      lab: "{{ full_slug }}"
      topology: "{{ lookup('file', '../templates/lab_topology.yml') }}"
      state: present

The environment variables for host, username, and password are set. I get the following error:

TASK [Create lab] ************************************************************** An exception occurred during task execution. To see the full traceback, use -vvv. The error was: KeyError: 'user' fatal: [localhost]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n File \"/home/<redacted>/.ansible/tmp/ansible-tmp-1729872399.4116898-239694-106795014035904/AnsiballZ_cml_lab.py\", line 107, in <module>\n _ansiballz_main()\n File \"/home/<redacted>/.ansible/tmp/ansible-tmp-1729872399.4116898-239694-106795014035904/AnsiballZ_cml_lab.py\", line 99, in _ansiballz_main\n invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n File \"/home/<redacted>/.ansible/tmp/ansible-tmp-1729872399.4116898-239694-106795014035904/AnsiballZ_cml_lab.py\", line 47, in invoke_module\n runpy.run_module(mod_name='ansible_collections.cisco.cml.plugins.modules.cml_lab', init_globals=dict(_module_fqn='ansible_collections.cisco.cml.plugins.modules.cml_lab', _modlib_path=modlib_path),\n File \"<frozen runpy>\", line 226, in run_module\n File \"<frozen runpy>\", line 98, in _run_module_code\n File \"<frozen runpy>\", line 88, in _run_code\n File \"/tmp/ansible_cisco.cml.cml_lab_payload_xkju8_gw/ansible_cisco.cml.cml_lab_payload.zip/ansible_collections/cisco/cml/plugins/modules/cml_lab.py\", line 196, in <module>\n File \"/tmp/ansible_cisco.cml.cml_lab_payload_xkju8_gw/ansible_cisco.cml.cml_lab_payload.zip/ansible_collections/cisco/cml/plugins/modules/cml_lab.py\", line 192, in main\n File \"/tmp/ansible_cisco.cml.cml_lab_payload_xkju8_gw/ansible_cisco.cml.cml_lab_payload.zip/ansible_collections/cisco/cml/plugins/modules/cml_lab.py\", line 130, in run_module\n File \"/tmp/ansible_cisco.cml.cml_lab_payload_xkju8_gw/ansible_cisco.cml.cml_lab_payload.zip/ansible_collections/cisco/cml/plugins/module_utils/cml_utils.py\", line 42, in __init__\nKeyError: 'user'\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}

This looks to be a disagreement between

self.user = self.params['user']
and
username=dict(type='str', required=True, aliases=['user'], fallback=(env_fallback, ['CML_USERNAME'])),

If I use the 'user' argument to the module along with the environment variable, there is no longer an error, but there is a warning that both 'username' and 'user' are set, so it appears to be an underlying flaw in the Ansible module spec/params handling that is allowing it to work when the alias is used, but is not typing the alias in the params call back to the underlying 'username' value and fallback settings.

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