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.89k stars 3.4k forks source link

Support parameter --playbook-dir for Inventory Sources #14909

Open gendergap opened 6 months ago

gendergap commented 6 months ago

Please confirm the following

Feature type

Enhancement to Existing Feature

Feature Summary

The ansible-inventory command allows to set a --playbook-dir base directory to locate all kinds of things inside a project. I personally use this to load a project-specific inventory plugin from the inventory_plugins directory of my project. But according to the documentation, it could also be relevant in a ton of other use cases.

AWX currently does not allow to set this variable for an inventory source, as far as I can see. This makes it impossible to load the dynamic inventory through the plugin for my project.

Select the relevant components

Steps to reproduce

  1. Set up an Ansible project with
    • a dummy playbook
    • a custom inventory plugin written in Python (in my case, sharepoint.py)
    • an inventory configuration for the plugin (to trigger the loading of the plugin) - here: hosts/sharepoint.yaml
  2. Add the project to AWX (e.g., from a Git repository)
  3. Configure a new Inventory in AWX
  4. Set up an Inventory Source "Sourced from a Project" and select the inventory configuration
  5. Try to synchronize the inventory

Current results

[WARNING]: * Failed to parse /runner/project/hosts/sharepoint.yaml with auto plugin: inventory config '/runner/project/hosts/sharepoint.yaml' specifies unknown plugin 'sharepoint'

Sugested feature result

I would wish that either

Additional information

No response

gendergap commented 6 months ago

I read through awx/main/tasks/jobs.py a bit and found out that the parameter --playbook-dir is actually set. It is set to the directory the inventory source is in. This by chance works well if the inventory configuration is located on the top layer (next to roles, and inventory_plugins). In my case, I have a bunch of inventory files which together reside in a subdirectory. AWX now uses this subdirectory as the --playbook-dir value and cannot find the plugin.

I believe this issue just went from "feature request" to "bug".

gendergap commented 6 months ago

As a workaround, I recommend to create a ansible.cfg file in your project and to write the following inside:

[defaults]

inventory_plugins = inventory_plugins

The value of that parameter is the name of the directory you keep your plugin in (relative to the project root).