How to link inventories/hosts and machine credentials?

Hi,

We are using AWX to manage a large number of systems, with several hundred dynamic inventories and credentials to go with each one (it’s a 1:1 relationship). Our job templates do not have an inventory or ssh credential set – we set the appropriate inventory and credential each time we launch a job through the API.

In some cases it would be convenient if the credential could be automatically linked to the inventory – for example, if we want to create a smart inventory for hosts of a certain type across many inventories. How can we tell AWX/Ansible which credential to use to connect to each host?

I know that ansible has the “ansible_ssh_private_key_file” variable that would seem to aim to address this, but this seems to require having the key on disk, which would mean it would have to live inside the AWX Kubernetes cluster. Is there a way in AWX’s host object that we could store the appropriate key directly?

If we are doing it wrong and there’s a better solution, I’m all for it, so please don’t hesitate to say so!