redhat-cop / controller_configuration

A collection of roles to manage Ansible Controller and previously Ansible Tower
https://galaxy.ansible.com/infra/controller_configuration
GNU General Public License v3.0
263 stars 136 forks source link

filetree_create/templates/current_inventory_sources.j2 complains about an undefined variable and fails. #811

Closed iamgini closed 4 months ago

iamgini commented 4 months ago

Summary

While running a simple playbook (see below) to export the configuration using filetreee_create role the filetree_create/templates/current_inventory_sources.j2 complains about an undefined variable and fails.

When I remove the line 25-27 in the filetree_create/templates/current_inventory_sources.j2, then the export will be completed successfully. But it will skip the inventory credential information for sure.

{% if inventory_source.credential is defined %}
    credential: "{{ inventory_source.summary_fields.credential.name }}"
{% endif %}

Issue Type

Ansible, Collection, Controller details

ansible --version
ansible [core 2.16.5]
  config file = /home/gmadappa/.ansible.cfg
  configured module search path = ['/home/gmadappa/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.12/site-packages/ansible
  ansible collection location = /home/gmadappa/collections:/home/gmadappa/.ansible/collections/ansible_collections:/usr/share/ansible/collections/ansible_collections:/home/gmadappa/ansible/ansible-real-life/ansible-molecule-demo/collections/ansible_collections
  executable location = /usr/bin/ansible
  python version = 3.12.2 (main, Feb 21 2024, 00:00:00) [GCC 13.2.1 20231205 (Red Hat 13.2.1-6)] (/usr/bin/python3)
  jinja version = 3.1.3
  libyaml = True

# --------------------------------------------------
$ ansible-galaxy collection list
[WARNING]: Collection at '/home/gmadappa/collections/ansible_collections/infra/.vscode' does not have a
MANIFEST.json file, nor has it galaxy.yml: cannot detect version.

# /home/gmadappa/.ansible/collections/ansible_collections
Collection                                    Version
--------------------------------------------- -------
amazon.aws                                    6.5.0  
ansible.controller                            4.4.2  
ansible.netcommon                             3.0.0  
ansible.posix                                 1.5.4  
ansible.utils                                 2.6.1  
awx.awx                                       23.1.0 
azure.azcollection                            1.16.0 
cisco.aci                                     2.2.0  
cisco.asa                                     3.0.0  
cisco.ios                                     5.2.0  
cloud.common                                  2.1.2  
community.crypto                              2.15.1 
community.general                             8.4.0  
dellemc.powerscale                            2.1.0  
fortinet.fortios                              2.2.2  
ginigangadharan.collection_demo_roles_modules 0.0.7  
iamgini.demo_colelction_roles_modules         1.0.1  
iamgini.signing_demo                          1.0.1  
kubernetes.core                               3.0.0  
redhat.rhel_system_roles                      1.21.1 

# /home/gmadappa/ansible/ansible-real-life/ansible-molecule-demo/collections/ansible_collections
Collection                                    Version
--------------------------------------------- -------
iamgini.meetupdemo                            1.0.0  
iamgini.moleculedemo                          1.0.0  
example.collection                            1.0.0  

# /home/gmadappa/collections/ansible_collections
Collection                                    Version
--------------------------------------------- -------
infra..vscode                                 *      
infra.controller_configuration                2.7.1  

# /usr/lib/python3.12/site-packages/ansible_collections
Collection                                    Version
--------------------------------------------- -------
amazon.aws                                    7.4.0  
ansible.netcommon                             5.3.0  
ansible.posix                                 1.5.4  
ansible.utils                                 2.12.0 
ansible.windows                               2.3.0  
arista.eos                                    6.2.2  
awx.awx                                       23.9.0 
azure.azcollection                            1.19.0 
check_point.mgmt                              5.2.3  
chocolatey.chocolatey                         1.5.1  
cisco.aci                                     2.8.0  
cisco.asa                                     4.0.3  
cisco.dnac                                    6.13.1 
cisco.intersight                              2.0.7  
cisco.ios                                     5.3.0  
cisco.iosxr                                   6.1.1  
cisco.ise                                     2.8.0  
cisco.meraki                                  2.17.2 
cisco.mso                                     2.5.0  
cisco.nxos                                    5.3.0  
cisco.ucs                                     1.10.0 
cloud.common                                  2.1.4  
cloudscale_ch.cloud                           2.3.1  
community.aws                                 7.1.0  
community.azure                               2.0.0  
community.ciscosmb                            1.0.7  
community.crypto                              2.18.0 
community.digitalocean                        1.26.0 
community.dns                                 2.8.3  
community.docker                              3.8.1  
community.general                             8.5.0  
community.grafana                             1.8.0  
community.hashi_vault                         6.2.0  
community.hrobot                              1.9.1  
community.library_inventory_filtering_v1      1.0.0  
community.libvirt                             1.3.0  
community.mongodb                             1.7.2  
community.mysql                               3.9.0  
community.network                             5.0.2  
community.okd                                 2.3.0  
community.postgresql                          3.4.0  
community.proxysql                            1.5.1  
community.rabbitmq                            1.2.3  
community.routeros                            2.14.0 
community.sap                                 2.0.0  
community.sap_libs                            1.4.2  
community.sops                                1.6.7  
community.vmware                              4.2.0  
community.windows                             2.2.0  
community.zabbix                              2.3.1  
containers.podman                             1.12.0 
cyberark.conjur                               1.2.2  
cyberark.pas                                  1.0.25 
dellemc.enterprise_sonic                      2.4.0  
dellemc.openmanage                            8.7.0  
dellemc.powerflex                             2.2.0  
dellemc.unity                                 1.7.1  
f5networks.f5_modules                         1.28.0 
fortinet.fortimanager                         2.4.0  
fortinet.fortios                              2.3.5  
frr.frr                                       2.0.2  
gluster.gluster                               1.0.2  
google.cloud                                  1.3.0  
grafana.grafana                               2.2.5  
hetzner.hcloud                                2.5.0  
hpe.nimble                                    1.1.4  
ibm.qradar                                    2.1.0  
ibm.spectrum_virtualize                       2.0.0  
ibm.storage_virtualize                        2.3.1  
infinidat.infinibox                           1.4.3  
infoblox.nios_modules                         1.6.1  
inspur.ispim                                  2.2.0  
inspur.sm                                     2.3.0  
junipernetworks.junos                         5.3.1  
kubernetes.core                               2.4.2  
lowlydba.sqlserver                            2.3.2  
microsoft.ad                                  1.5.0  
netapp.aws                                    21.7.1 
netapp.azure                                  21.10.1
netapp.cloudmanager                           21.22.1
netapp.elementsw                              21.7.0 
netapp.ontap                                  22.10.0
netapp.storagegrid                            21.12.0
netapp.um_info                                21.8.1 
netapp_eseries.santricity                     1.4.0  
netbox.netbox                                 3.17.0 
ngine_io.cloudstack                           2.3.0  
ngine_io.exoscale                             1.1.0  
openstack.cloud                               2.2.0  
openvswitch.openvswitch                       2.1.1  
ovirt.ovirt                                   3.2.0  
purestorage.flasharray                        1.27.0 
purestorage.flashblade                        1.16.0 
purestorage.fusion                            1.6.1  
sensu.sensu_go                                1.14.0 
splunk.es                                     2.1.2  
t_systems_mms.icinga_director                 2.0.1  
telekom_mms.icinga_director                   1.35.0 
theforeman.foreman                            3.15.0 
vmware.vmware_rest                            2.3.1  
vultr.cloud                                   1.12.1 
vyos.vyos                                     4.1.0  
wti.remote                                    1.0.5  

# --------------------------------------------------
Controller version
Ansible Automation Platform Controller 4.4.4

OS / ENVIRONMENT

Desired Behavior

Export/save the configuration without any error.

Actual Behavior

Please give some details of what is actually happening. Include a [minimum complete verifiable example] with:

TASK [infra.controller_configuration.filetree_create : Add current inventory source to the inventory sources flat file] ***
fatal: [localhost]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'dict object' has no attribute 'credential'. 'dict object' has no attribute 'credential'. 'dict object' has no attribute 'credential'. 'dict object' has no attribute 'credential'\n\nThe error appears to be in '/home/gmadappa/collections/ansible_collections/infra/controller_configuration/roles/filetree_create/tasks/inventory_sources.yml': line 21, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n    - name: \"Add current inventory source to the inventory sources flat file\"\n      ^ here\n"}

PLAY RECAP *************************************************************************************************
localhost                  : ok=20   changed=3    unreachable=0    failed=1    skipped=5    rescued=0    ignored=0   

STEPS TO REPRODUCE

$ ansible-playbook -i localhost, filetree_create.yml -e '{controller_validate_certs: false, controller_hostname: aap-rhel-92-1.lab.local, controller_username: admin, controller_password: password, flatten_output: true, output_path: /tmp/cac_output_flatten}'
---
- hosts: all
  connection: local
  gather_facts: false
  vars:
    controller_username: "{{ vault_controller_username | default(lookup('env', 'CONTROLLER_USERNAME')) }}"
    controller_password: "{{ vault_controller_password | default(lookup('env', 'CONTROLLER_PASSWORD')) }}"
    controller_hostname: "{{ vault_controller_hostname | default(lookup('env', 'CONTROLLER_HOST')) }}"
    controller_validate_certs: "{{ vault_controller_validate_certs | default(lookup('env', 'CONTROLLER_VERIFY_SSL')) }}"

  pre_tasks:
    - name: "Setup authentication (block)"
      block:
        - name: "Get the Authentication Token for the future requests"
          ansible.builtin.uri:
            url: "https://{{ controller_hostname }}/api/v2/tokens/"
            user: "{{ controller_username }}"
            password: "{{ controller_password }}"
            method: POST
            force_basic_auth: true
            validate_certs: "{{ controller_validate_certs }}"
            status_code: 201
          register: authtoken_res

        - name: "Set the oauth token to be used since now"
          ansible.builtin.set_fact:
            controller_oauthtoken: "{{ authtoken_res.json.token }}"
            controller_oauthtoken_url: "{{ authtoken_res.json.url }}"
      no_log: "{{ controller_configuration_filetree_create_secure_logging | default('false') }}"
      when: controller_oauthtoken is not defined
      tags:
        - always

  roles:
    - infra.controller_configuration.filetree_create

  post_tasks:
    - name: "Delete the Authentication Token used"
      ansible.builtin.uri:
        url: "https://{{ controller_hostname }}{{ controller_oauthtoken_url }}"
        user: "{{ controller_username }}"
        password: "{{ controller_password }}"
        method: DELETE
        force_basic_auth: true
        validate_certs: "{{ controller_validate_certs }}"
        status_code: 204
      when: controller_oauthtoken_url is defined
...
iamgini commented 4 months ago

Raised PR #812