theforeman / foreman-ansible-modules

Ansible modules for interacting with the Foreman API and various plugin APIs such as Katello
GNU General Public License v3.0
149 stars 166 forks source link

TypeError: 'NoneType' object is not subscriptable when Katello composite content view not publised #678

Closed charlyhue closed 4 years ago

charlyhue commented 4 years ago
SUMMARY

Module katello_content_view raise TypeError: 'NoneType' object is not subscriptable error when composite content view is not publised

ISSUE TYPE
ANSIBLE VERSION
ansible 2.8.0
  config file = /home/charly/dev/hors-prod/satellite_deploy/ansible.cfg
  configured module search path = ['/home/charly/dev/hors-prod/satellite_deploy/library', '/home/charly/dev/hors-prod/satellite_deploy/foreman-ansible-modules/plugins/modules']
  ansible python module location = /usr/local/lib/python3.7/site-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 3.7.5 (default, Oct 17 2019, 12:09:47) [GCC 9.2.1 20190827 (Red Hat 9.2.1-1)]
KATELLO/FOREMAN VERSION
tfm-rubygem-katello-3.10.0.55-1.el7sat.noarch
foreman-1.20.1.35-1.el7sat.noarch
APYPIE VERSION
Version: 0.2.1
STEPS TO REPRODUCE
- name: create content view
  katello_content_view:
    username: "****"
    password: "****"
    server_url: "https://***"
    name: "test_ccv"
    organization: "default Organization"
    composite: True
    components:
      - content_view: test_cv
         latest: True

- name: Update content view (this task fail)
  katello_content_view:
    username: "****"
    password: "****"
    server_url: "https://***"
    name: "test_ccv"
    organization: "default Organization"
    composite: True
    components:
      - content_view: test_cv
        latest: True
      - content_view: test_cv2
        latest: True
EXPECTED RESULTS

Content view should be updated (or task should be OK when running many times).

ACTUAL RESULTS
Traceback (most recent call last):\n  File \"/home/charly/.ansible/tmp/ansible-tmp-1579269953.3757474-227102345803806/AnsiballZ_katello_content_view.py\", line 114, in <module>\n    _ansiballz_main()\n  File \"/home/charly/.ansible/tmp/ansible-tmp-1579269953.3757474-227102345803806/AnsiballZ_katello_content_view.py\", line 106, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/home/charly/.ansible/tmp/ansible-tmp-1579269953.3757474-227102345803806/AnsiballZ_katello_content_view.py\", line 49, in invoke_module\n    imp.load_module('__main__', mod, module, MOD_DESC)\n  File \"/usr/lib64/python3.7/imp.py\", line 234, in load_module\n    return load_source(name, filename, file)\n  File \"/usr/lib64/python3.7/imp.py\", line 169, in load_source\n    module = _exec(spec, sys.modules[name])\n  File \"<frozen importlib._bootstrap>\", line 630, in _exec\n  File \"<frozen importlib._bootstrap_external>\", line 728, in exec_module\n  File \"<frozen importlib._bootstrap>\", line 219, in _call_with_frames_removed\n  File \"/tmp/ansible_katello_content_view_payload_kt0fdt0w/__main__.py\", line 272, in <module>\n  File \"/tmp/ansible_katello_content_view_payload_kt0fdt0w/__main__.py\", line 211, in main\n  File \"/tmp/ansible_katello_content_view_payload_kt0fdt0w/__main__.py\", line 211, in <listcomp>\nTypeError: 'NoneType' object is not subscriptable
evgeni commented 4 years ago

Which version/source of foreman ansible modules are you using?

evgeni commented 4 years ago

and just making sure, your example playbook has latest weirdly indented

charlyhue commented 4 years ago

I use the latest version of the master branch. I fixed the example (copy / paste mistake)

The error come from cvc['content_view_version']['id'] in current_cvcs_record = [{"id": cvc['id'], "content_view_id": cvc['content_view']['id'], "content_view_version_id": cvc['content_view_version']['id'], "latest": cvc['latest']} for cvc in current_cvcs]. When composite content view is not published 'content_view_version' is empty.

evgeni commented 4 years ago

Oooh, I see.

Thanks a ton for hunting that down! I'll see that I fix that quickly.

evgeni commented 4 years ago

@charlyhue please have a look at https://github.com/theforeman/foreman-ansible-modules/pull/679, it should fix your issue