controller_configuration icon indicating copy to clipboard operation
controller_configuration copied to clipboard

inventory_sources built using the api plugin in object_diff do not include the source key

Open w4hf opened this issue 1 year ago • 1 comments

Summary

When trying to remove inventory_sources not declared in Conf as code using the object_diff role, the role fails in the task [ infra.configuration.inventory_sources : Managing Inventory Sources ] with the following error :

fatal: [localhost]: FAILED! => {"msg": "The conditional check '__controller_source_item.source != \"constructed\"' failed. 
The error was: error while evaluating conditional (__controller_source_item.source != \"constructed\"): 'dict object' has no attribute 'source'.
'dict object' has no attribute 'source'\n\nThe error appears to be in 
'/home/gitlab-runner/.ansible/collections/ansible_collections/infra/configuration/roles/inventory_sources/tasks/main.yml': 
line 2, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\n
The offending line appears to be:\n\n---\n- name: \"Managing Inventory Sources\"\n ^ here\n"}

Because the inventory_sources list read from the Controller using the API plugin do not create a source key for each element in the list. Below an example of the controller_inventory_sources list built using the object_diff role. We can see that there is no key source :

TASK [infra.configuration.object_diff : Set inventory_sources' list to be configured] ***
task path:
/home/gitlab-runner/.ansible/collections/ansible_collections/infra/configuration/roles/object_diff/tasks/inventory_sources.yml:27
ok: [localhost] => 
{"ansible_facts": {"controller_inventory_sources": [{"inventory": "TEST INVENTORY", "name": "TEST Inventory Source", "organization": "Test", "state": "absent"}]}, "changed": false}

Issue Type

  • Bug Report

Ansible, Collection, Controller details

ansible version : 2.15.0

used collections : ansible.controller 4.5.1 infra.controller_configuration 2.6.0

Controller version 4.5.1

  • ansible installation method: OS package

OS / ENVIRONMENT

RHEL 8.6

Desired Behavior

Each element of the list controller_inventory_sources built using the object_diff role automatically from the Controller should have the key source

Actual Behavior

The elements of the list controller_inventory_sources do not contains the key source which cause the role to fail in the task [ infra.configuration.inventory_sources : Managing Inventory Sources ]

STEPS TO REPRODUCE

Manually create an inventory_source in the Controller web interface that do is not declared in the configuration as code. Then call the object diff role to remove inventory_sources not in the configuration as code as follow :

    - role: infra.controller_configuration.object_diff
      vars:
        controller_configuration_object_diff_tasks:
          - {name: inventory_sources, var: controller_inventory_sources, tags: inventory_sources}

w4hf avatar Feb 23 '24 19:02 w4hf

Ran into the same issue. Had to revert to version 2.5.2 as a workaround. Looks like the bug was introduced by this change?

https://github.com/redhat-cop/controller_configuration/pull/720

mmaaz1 avatar Mar 04 '24 23:03 mmaaz1

This is a duplicate of #783 and is solved at #755. As they are both closed, I'm closing this one, too.

ivarmu avatar Mar 18 '24 11:03 ivarmu