Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disagreement in Module Spec #38

Open
netgirard opened this issue Oct 25, 2024 · 0 comments
Open

Disagreement in Module Spec #38

netgirard opened this issue Oct 25, 2024 · 0 comments

Comments

@netgirard
Copy link

netgirard commented Oct 25, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant