How do I list available playbooks in a dropdown in a service catalog

automate
providers

#1

Hi everyone, I’m trying to list the available playbooks/templates in Ansible Tower to be used in provisioning. In the service catalog, I need a dropdown with the categories of my playbooks( category A, B and C) and the next dropdown will refresh accordingly and show the list of the playbooks that belong to each category. Can someone guide me, or if there’s a similar example to follow, I don’t have any experience with conding ruby methods.


#2

Are categories A/B/C based on tags applied to playbooks?


#3

I did not apply any tags in the playbook, I separated them in different git repos, each category in a different git repo in Ansible Tower, I tried to name them [A] Playbook1…n [B] Playbook 1…n and I got a simple ruby method to refresh the dropdown dynamically according to the [Lettre] but it sometimes works sometimes not, and it takes way too long to refresh the dropdown. if you feel applying tags into the playbook will make it more easier to refresh the dropdown I will gladly do it but how the ruby code would be?


#4

The following method will filter based on applied tags of Department category:

values_hash = {}
$evm.vmdb(:configuration_script).all.each do |jobtemplate| 
  values_hash[jobtemplate.id] = jobtemplate.name if jobtemplate.tagged_with? 'department', $evm.root['dialog_department'].first.try(:name)
end
list_values = {
   'sort_by'    => :value,
   'data_type'  => :string,
   'required'   => true,
   'values'     => values_hash
}
list_values.each { |key, value| $evm.object[key] = value }

The service form has two fields, the first one is Tag control type with variable name department:

The second field (Playbook) is a dynamic dropdown:
playbook


#5

Thank you for your idea, it’s better than the one I used.