ansible-collections / dellemc.os6

GNU General Public License v3.0
8 stars 13 forks source link

ansible-playbook --check fails with error #32

Closed GuyFoetz closed 8 months ago

GuyFoetz commented 3 years ago
SUMMARY

When executing a playbook with --check a Task with a command will fail due to a variable not being assigned.

ISSUE TYPE
COMPONENT NAME

os6_config

ANSIBLE VERSION
ansible 2.10.5
  python version = 3.8.6 (default, Jan 27 2021, 15:42:20) [GCC 10.2.0]
CONFIGURATION
ANSIBLE_SSH_ARGS(ansible.cfg) = -o ForwardAgent=yes
DEFAULT_HOST_LIST(ansible.cfg) = ['inventory.yaml']
HOST_KEY_CHECKING(ansible.cfg) = False
INTERPRETER_PYTHON(ansible.cfg) = auto
OS / ENVIRONMENT

Ubuntu 20.10

STEPS TO REPRODUCE

While running a vlan configuration on os6 with --check to see if the command is executed correctly you get the error

ansible-playbook playbook.yaml  --tags vlan --check -vvv

hostvar:

os6_interface:
    Gi1/0/1:
      portmode: access
      admin: up
EXPECTED RESULTS
ACTUAL RESULTS
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: UnboundLocalError: local variable 'result_banners' referenced before assignment
fatal: [cnc-e114-r01-sw2]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):
  File \".ansible/tmp/ansible-local-18941ek58ufs3/ansible-tmp-1620024310.6947634-18949-276975040182545/AnsiballZ_os6_config.py\", line 102, in <module>
    _ansiballz_main()
  File \".ansible/tmp/ansible-local-18941ek58ufs3/ansible-tmp-1620024310.6947634-18949-276975040182545/AnsiballZ_os6_config.py\", line 94, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File \".ansible/tmp/ansible-local-18941ek58ufs3/ansible-tmp-1620024310.6947634-18949-276975040182545/AnsiballZ_os6_config.py\", line 40, in invoke_module
    runpy.run_module(mod_name='ansible_collections.dellemc.os6.plugins.modules.os6_config', init_globals=None, run_name='__main__', alter_sys=True)
  File \"/usr/lib/python3.8/runpy.py\", line 207, in run_module
    return _run_module_code(code, init_globals, run_name, mod_spec)
  File \"/usr/lib/python3.8/runpy.py\", line 97, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File \"/usr/lib/python3.8/runpy.py\", line 87, in _run_code
    exec(code, run_globals)
  File \"/tmp/ansible_dellemc.os6.os6_config_payload_70h1wnsr/ansible_dellemc.os6.os6_config_payload.zip/ansible_collections/dellemc/os6/plugins/modules/os6_config.py\", line 410, in <module>
  File \"/tmp/ansible_dellemc.os6.os6_config_payload_70h1wnsr/ansible_dellemc.os6.os6_config_payload.zip/ansible_collections/dellemc/os6/plugins/modules/os6_config.py\", line 390, in main
UnboundLocalError: local variable 'result_banners' referenced before assignment
", "module_stdout": "", "msg": "MODULE FAILURE
See stdout/stderr for the exact error", "rc": 1}
GuyFoetz commented 3 years ago

pull request with the fix will fallow soon :)

ewenmcneill commented 2 years ago

I ran into this same issue with dellemc.os6.os6_config on Ansible 2.10 on CentOS 7, and can confirm that the fix in PR #33 does allow running to completion in check mode for me too. (The problem appears to be that result_banners is only generated in non-check mode, but it is included in the returned result unconditionally; setting result_banners to an empty array works around this non-initialisation in check mode.)

Please merge #33 or an equivalent fix; it looks like a reasonable fix to me, and without it neither update: check nor ansible-playbook .... -C work AFAICT.

Ewen

timway commented 2 years ago

Just encountered this issue in os6_config (check mode) as well after installing the most recent collection via ansible-galaxy. The environment is the Ansible Automation Platform 2.2 ee-supported-rhel8 image with the collection installed.

@elpuma1969

mryan commented 2 years ago

I have also ran into this issue. Being the core config module, most of the roles depend on this one and not having a check mode is a significant deterrent to using the whole collection.