VMware Cloud Community
vmsiul
Enthusiast
Enthusiast

vRA 8.6 | How to manage the input of a custom form for "Multi Select"

Hello, 

We are looking for a way to use a Multi Select (constant value) if the value is "yes" or "checked" we would like to run an ansible playbook. Ideally we would like to keep it simple within the cloud template/blueprint as part of the YAML code (like shown below with the "oneOf".

We have a form with "oneOf" type where users are selecting the Language they need to get configured, that takes them to execute a specific Ansible playbook that's matching their selection. 
 
Language:
    type: string
    oneOf:
      - title: French
        const: FrenchAnsible
      - title: German
        const: GermanAnsible
    title: Select Language
 
Later their selection is used in Ansible blueprint section:
 
 Cloud_Ansible_1:
    type: Cloud.Ansible
    properties:
      authentication: usernamePassword
      inventoryFile: /home/ansible/inventory
      username: Administrator
      password: xxxxx
      hostName: '${resource.Cloud_vSphere_Machine_1.networks[0].address}'
      groups:
        - win
      playbooks:
        provision:
          - '/home/ansible/${input.Language}.yml'
 
If they go with French their selection will generate a value of FrenchAnsible which is the name of ansible playbook called frenchansible.yml which will execute the playbook.  
 
Here's the question...
 
I need to create a section in the form to allow users to select the apps that they need to get installed during the creation of the VM. The installation will happen via Ansible the same way as I've explained above.  
 
For example the form will have:
 
App1 (Multi Select with a value)
App2 (Multi Select with a value)
App3 (Multi Select with a value)
 
So based on the (Multi Select with a value) selection and the value we will be executing different playbooks to install the app,  something like this:

---
playbooks:
provision:
-
'/etc/ansible/playbooks/${input.app1}.yml'
'/etc/ansible/playbooks/${input.app2}.yml'

So the app1 (Multi Select with a value) will call app1.yml, the app2 (Multi Select with a value) will call app2.yml, etc. so ansible will be executed just for the selections that have been made via check box. Since app3 hasn't been selected it won't be executed.
 
When I use a custom form and I use ((Multi Select with a value)) I can't find a way to use the code like I did with the oneOf option to call INPUT the "value" /${input.app1}.yml like I did before.
 
Something like this 
 
checkbox:
      - title: French
        const: FrenchAnsible
 
So I can later use it with the ansible blueprint code to call the ansible playbook the same way. 
 
playbooks:
        provision:
          - '/home/ansible/${input.Language}.yml'
 
How can we can use "INPUT" value for custom forms, in the example above for Multi Select to call ansible specific playbook.  
 
Note the values I am using are constant not dynamic. 
Labels (5)
0 Kudos
5 Replies
johnbowdre
Enthusiast
Enthusiast

I did some fumbling about with this today and I think I have a solution, at least for the input side of things.

I start out by adding a 'playbooks' input to my Cloud Template, of type 'array' so that it can hold multiple strings:

inputs:
  playbooks:
    type: array
    title: Playbooks
    description: Ansible playbooks to run
    items:
      type: object
      properties:
        playbook:
          type: string
          title: Playbook

On the Custom Form side, I can set the field to be a Multi Value Picker and set the values to a few playbook names I want to be available:

johnbowdre_0-1648760442439.png

(The first line of the values CSV is the header and needs to match the property specified in the template, 'playbook' in this instance.)

And then it shows up correctly when requesting the catalog item:

johnbowdre_1-1648760611327.png

Of course, this is going to return an array of playbook names back to vRA. I'm not sure how best to handle breaking it out to discrete strings for the ansible provisioner to handle. I might experiment with that some in the future, but this is about as far as I could get it in my free time today. Maybe it'll at least help to nudge you in the right direction?

0 Kudos
vmsiul
Enthusiast
Enthusiast

Thanks John, the main issue I am facing is that I don't know a way to pass the value that's chosen as an input to call the playbook. I can name the playbook to match the value but how do I get that value as part of a input. I don't need to use a multi select but I need to use something like a checkbox type solution so they can check the option for the app they need and then execute the playbook. 

0 Kudos
johnbowdre
Enthusiast
Enthusiast

Yeah I've been poking a bit more at it and haven't come up with a way to handle that within the Ansible resource section of the template. BTW a Data Grid display type might make more sense so that users could select the checkboxes for what they want rather than having to search for it. Same issue on the backend, though - still need to figure out how to convert an array of strings into something that could be processed by the Ansible provisioner.

0 Kudos
vmsiul
Enthusiast
Enthusiast

Thanks John.

 

 

0 Kudos
Ankush11s
VMware Employee
VMware Employee

you can try with boolean and conditional logic.

Ansible:
    type: Cloud.Ansible
    metadata:
      layoutPosition:
        - 0
        - 1
    properties:
      account: eso-ansible
      username: administrator
      password: Dynam1c0ps
      maxConnectionRetries: 20
      playbooks:
        provision:
          - '${input.App1 == true ?  "/root/ansible-playbooks/windows_enableiis.yml" :  ""}'
      osType: windows
      inventoryFile: /root/ansible-playbooks/windowshosts
0 Kudos