ansible / awx

AWX provides a web-based user interface, REST API, and task engine built on top of Ansible. It is one of the upstream projects for Red Hat Ansible Automation Platform.
Other
13.97k stars 3.41k forks source link

Inventory Drop Down Empty for Project Sourced Inventory #13710

Open shawnweeks opened 1 year ago

shawnweeks commented 1 year ago

Please confirm the following

Bug Summary

When sourcing inventory from a Git based Project the inventory file drop down menu is empty. Typing in a known inventory yaml file path works. Other places that use project files like the Job Template page correctly show all the available files in the drop down including inventory files.

AWX version

21.13.0

Select the relevant components

Installation method

kubernetes

Modifications

no

Ansible version

No response

Operating system

Rocky 8

Web browser

Firefox

Steps to reproduce

  1. Create project from a Git repository containing an inventory/ folder and multiple inventory files with .yml extension.
  2. Verify that project created in step 1 syncs successfully.
  3. Create Inventory from Source and reference the Project created in Step 1 and notice that the drop down menu for inventory files just shows the root directory and no files.

Expected results

Inventory file list should show the files from the project.

Actual results

Inventory list just shows / (project root)

Additional information

This is a basic install using the AWX Operator on a single node K3s installation with all defaults and no configuration changes inside of AWX.

shawnweeks commented 1 year ago
Screenshot 2023-03-16 at 2 06 10 PM Screenshot 2023-03-16 at 2 05 54 PM
arielb2 commented 1 year ago

It seems to me that Currently it only works with files that have names hosts, inventory, *.ini, for the inventory files and with a limit of 50 files

shawnweeks commented 1 year ago

I use the structure described at the bottom of https://docs.ansible.com/ansible/latest/inventory_guide/intro_inventory.html for all of my Ansible projects. Would it make sense to expand it to inventory/ as well?

fosterseth commented 1 year ago

here is the code to try to quickly determine if a file is inventory or not

https://github.com/ansible/awx/blob/7fda4b0675aba9df5a68b2b03b038ed3cc446ee8/awx/main/utils/ansible.py#L67

it only looks at the first 10 lines of code -- do your inventory files have comments or anything at the beginning of the file?

shawnweeks commented 1 year ago

No, they do not contain any comments at the top. Here is a snippet from one of the inventory files.

all:
  children:
    pve:
      hosts:
        cloud1:
          ip_suffix: 11
          mgmt_net_adapter_1: eno3
          mgmt_net_adapter_2: eno4
          vm_net_adapter: eno1
          ceph_net_adapter: enp65s0
        cloud2:
          ip_suffix: 12
          mgmt_net_adapter_1: eno3
          mgmt_net_adapter_2: eno4
          vm_net_adapter: eno1
          ceph_net_adapter: enp65s0
        cloud3:
          ip_suffix: 13
          mgmt_net_adapter_1: eno3
          mgmt_net_adapter_2: eno4
          vm_net_adapter: eno1
          ceph_net_adapter: enp65s0
arielb2 commented 1 year ago

No, they do not contain any comments at the top. Here is a snippet from one of the inventory files.

all:
  children:
    pve:
      hosts:
        cloud1:
          ip_suffix: 11
          mgmt_net_adapter_1: eno3
          mgmt_net_adapter_2: eno4
          vm_net_adapter: eno1
          ceph_net_adapter: enp65s0
        cloud2:
          ip_suffix: 12
          mgmt_net_adapter_1: eno3
          mgmt_net_adapter_2: eno4
          vm_net_adapter: eno1
          ceph_net_adapter: enp65s0
        cloud3:
          ip_suffix: 13
          mgmt_net_adapter_1: eno3
          mgmt_net_adapter_2: eno4
          vm_net_adapter: eno1
          ceph_net_adapter: enp65s0

try to name the file as inventory or hosts, without extension, even if it is a yaml

shawnweeks commented 1 year ago

Changing the name of the files really isn't practical, is there a particular reason why *.ini was allowed and *.yml isn't even though the documentation for Ansible suggests that file extension for your inventory? Looking at the code this just seems to be something that was missed, I can submit a PR adding it but there is no point if it was intentionally left out.

arielb2 commented 1 year ago

Changing the name of the files really isn't practical, is there a particular reason why *.ini was allowed and *.yml isn't even though the documentation for Ansible suggests that file extension for your inventory? Looking at the code this just seems to be something that was missed, I can submit a PR adding it but there is no point if it was intentionally left out.

Well I don't really have the answer, it's just a recommendation to validate the issue, based on what I see in the code. If that works for you, it could be better analyzed if a pull request is necessary :-)

arielb2 commented 1 year ago

for the record, I did a test by creating an inventory with yaml format and name the file hosts and it loads it to the drop down list and also to the inventory the hosts, groups

all:
  children:
    prod:
      children:
        database:
          children:
            central:
              hosts:
                host1:
                host2:

image

arielb2 commented 1 year ago

The test was also made to manually place the path of the yml file with the name, since the filter is only for the dropdown list to show them, but if we write it if it loads the inventory in the yml

image