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

TDNF Ansible Module not working #1508

Closed
felixtech-msp opened this issue Oct 3, 2023 · 3 comments
Closed

TDNF Ansible Module not working #1508

felixtech-msp opened this issue Oct 3, 2023 · 3 comments
Labels

Comments

@felixtech-msp
Copy link

Describe the bug

The Ansible module for TDNF found under https://github.com/vmware/photon/blob/master/SPECS/ansible/tdnf.py isn't working.

The error message is as following:

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: TypeError: 'NoneType' object is not iterable

Traceback (most recent call last):
 File \"/home/awx/.ansible/tmp/ansible-tmp-1696251955.61725-318-195202107349459/AnsiballZ_tdnf.py\", line 107, in  _ansiballz_main()
 File \"/home/awx/.ansible/tmp/ansible-tmp-1696251955.61725-318-195202107349459/AnsiballZ_tdnf.py\", line 99, in _ansiballz_main
 invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
 File \"/home/awx/.ansible/tmp/ansible-tmp-1696251955.61725-318-195202107349459/AnsiballZ_tdnf.py\", line 47, in invoke_module
 runpy.run_module(mod_name='ansible.modules.tdnf', init_globals=dict(_module_fqn='ansible.modules.tdnf', _modlib_path=modlib_path),
 File \"\", line 226, in run_module
 File \"\", line 98, in _run_module_code
 File \"\", line 88, in _run_code
 File \"/tmp/ansible_tdnf_payload_fsw168bt/ansible_tdnf_payload.zip/ansible/modules/tdnf.py\", line 368, in 
 File \"/tmp/ansible_tdnf_payload_fsw168bt/ansible_tdnf_payload.zip/ansible/modules/tdnf.py\", line 332, in main
 File \"/tmp/ansible_tdnf_payload_fsw168bt/ansible_tdnf_payload.zip/ansible/modules/tdnf.py\", line 292, in convert_to_list
TypeError: 'NoneType' object is not iterable

The task to run was:

- name: update installed packages
  tdnf:
    update_cache: yes
    upgrade: yes

Reproduction steps

  1. Create Ansible role and put module file under library folder.
  2. Run above described Ansible task on a Photon OS 5.0 machine.
  3. Observe the error.

Expected behavior

Run TDNF tasks as intended ans described by documentation.

Additional context

Ansible Version 2.13.6
Python Version 3.10.11

@snapshotleisure
Copy link

Hi, this is the same issue for me with the same configuration

@snapshotleisure
Copy link

snapshotleisure commented Nov 11, 2023

Hi,
I actually have a fix for this, the bug is actually in the function called convert_to_list at line 288. It is not doing a check for NoneType.

You can find the files in the following locations:

  • /usr/lib/python3.11/site-packages/ansible/modules/tdnf.py
  • /usr/lib64/python3.11/site-packages/ansible/modules/tdnf.py

You will need to update the function like below with the None check:

def convert_to_list(input_list):
    """Convert nested list into flat list"""
    flat_list = []

    if input_list is not None:
      for sublist in input_list:
          if not isinstance(sublist, list):
              flat_list.append(sublist)
              continue
          if sublist is not None:
            for item in sublist:
                flat_list.append(item)

    return flat_list

Then you need to run the command below to recompile it:
python -c "import py_compile;py_compile.compile('/usr/lib/python3.11/site-packages/ansible/modules/tdnf.py');py_compile.compile('/usr/lib64/python3.11/site-packages/ansible/modules/tdnf.py');"

After that it should work.

Unfortunately I'm not really good with git, so don't know how to request pull request to fix up the code, but hope this helps people and the devs will fix up the function

@snapshotleisure
Copy link

Ok tried to do a pull request, will see if it works

gerrit-photon pushed a commit that referenced this issue Nov 14, 2023
Fixes: #1508

Original author of this fix is:
snapshotleisure <sfzhao99@hotmail.com>
#1517

Change-Id: I4a04f852169fa5821f6aa25cb7ed072e5bc621c3
Signed-off-by: Shreenidhi Shedi <sshedi@vmware.com>
Reviewed-on: http://photon-jenkins.eng.vmware.com:8082/c/photon/+/22343
Tested-by: gerrit-photon <photon-checkins@vmware.com>
gerrit-photon pushed a commit that referenced this issue Nov 14, 2023
Fixes: #1508

Original author of this fix is:
snapshotleisure <sfzhao99@hotmail.com>
#1517

Change-Id: I32f1f352dea9d33de88f57a7180cfb1ea30f4f4a
Signed-off-by: Shreenidhi Shedi <sshedi@vmware.com>
Reviewed-on: http://photon-jenkins.eng.vmware.com:8082/c/photon/+/22342
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant