Setting the inventory within an Ansible Tower job template to "prompt on launch" means that when the template is run from within Tower, all current inventories are presented in a drop down box as shown below.
If we want to run this job template as a service catalog item in cloudforms then we create a service dialog and call this from a service catalog item.
The problem here is that the service dialog created within cloudforms does not present a list of inventories to choose from , only "limit". Since the limit variable only applies when a valid inventory is selected , we are missing a key input value from cloudforms to tower to make the catalog item for this particular job template work. So, our catalog item will fail.
We need to get a valid list of inventories from tower and present them within our service dialog.
Create a service dialog from the job template as before:
Edit this dialog to add some dynamic drop-down fields that will present all the current available inventories within Tower, and all the hosts within.
Firstly, add a new dynamic drop-down list. This will have a label "inventory group" and name "inventory_ root_ group". This will be populated by a method called "inventory_group _hosts.rb" , located here
Secondly, edit the "limit" text box to be a dynamic drop down list. This will have a label of "inventory hosts" , with a name of "limit". This will be populated by a method called "inventory_hosts.rb", located here
The dialogs described above can be found here
These dialog elements, look like this
one last thing
In order to process the dialog options successfully and pass them to Tower, we need to edit the preprovision method so that the option for inventory _ root_ group from the dialog is passed to Tower. Here is how.
Copy the method:
to your custom domain of choice
Then, edit it to enable the "modify job options" method to be called by removing that # from the job options call ( line 20 )
Finally , submit the values from your dialogs box by editing the job options to set inventory as the value returned from the "inventory _root _ group dialog box " (from line 46)
Create the service
We are now ready to create our service catalog item that call the dialogs we have created above.
ready to order
Ordering the service presents us with all the inventories set up with Tower; and all the hosts for each inventory selected.
Choose your target and click submit. The job should run on Tower against the selected inventory.