One of the workflows have changed in a way were multiple VMs need to be requested as part of the request form (template). For example the user will select the number of VMs the need.
-The name can be automated sequentially - something like MYVM01, MYVM02, MYVM03, MYVM04 etc.
-The user needs to provide the number of VMs that they need - for example I need to create 5 VMs.
I was able to get something like this to work:
https://vcloudinsights.com/2020/10/27/publish-a-blueprint-as-catalog-items/
But I can't get beyond 10 VMs per deployment. Also it's very confusing for the user to understand what numbers are being used versus which ones aren't.
The goal is to have the user to type the number of VMs that they need to be created, include some numbers sequentially after the name (0001,0002,0003, etc) and some way to control that the hostname and numbers aren't already being used.
Another way I was testing was using "count" in the cloud assembly but I don't know if it's possible to create a user input with “count”
Cloud_vSphere_Machine_1
type: Cloud.vSphere.Machine
properties:
image: Images
count: 2 ------------------- not sure how to use .input here to let the user select the number that will go here.
cpuCount: 1
totalMemoryMB: 1024
In the above we use count 2 to create 2 VMs, can we create an input for count so the user can specify the number for the count with an input?
Any help will be appreciated.
Thank you!
There are 2 correction which are needed , you are specifying the if condition but you have not specified what would have if environment size is not equal to 2 and you missed to add quotes as syntax for use in yaml.
here is the sample which would work.
formatVersion: 1
inputs:
environmentsize:
type: integer
title: 'Environment Size'
enum:
- 2
- 4
totalvm:
type: integer
title: 'Enter Total Number of VM'
enum:
- 0
- 1
- 2
- 3
- 4
resources:
Cloud_vSphere_Network_1:
type: Cloud.vSphere.Network
properties:
networkType: existing
Cloud_vSphere_Machine_1:
type: Cloud.vSphere.Machine
properties:
image: Linux
cpuCount: 1
totalMemoryMB: 1024
count: '${input.environmentsize == to_number(2) ? 2 : 1 }'
networks:
- network: ${resource.Cloud_vSphere_Network_1.id}
If resolved your issue , Mark this thread as resolved and right answer
Yes you can do with below
formatVersion: 1
inputs:
totalvm:
type: integer
title: Enter Total Number of VM
default: 1
maximum: 100
resources:
Cloud_vSphere_Network_1:
type: Cloud.vSphere.Network
properties:
networkType: existing
Cloud_vSphere_Machine_1:
type: Cloud.vSphere.Machine
properties:
image: Linux
cpuCount: 1
totalMemoryMB: 1024
count: ${input.totalvm}
networks:
- network: ${resource.Cloud_vSphere_Network_1.id}
I've been trying different options to manage the count and input. I am have been trying with the following code.
formatVersion: 1
inputs:
count:
type: integer
title: Machine Count
description: The number of machines that you want to deploy.
maximum: 12
minimum: 1
default: 1
enum:
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
resources:
Cloud_Network_1:
type: Cloud.Network
properties:
constraints: null
networkType: existing
Cloud_vSphere_Machine_1:
type: Cloud.vSphere.Machine
properties:
image: Ubuntu_20.04
count: ${input.env-size == "2" ? 1}
#count: 2
cpuCount: 1
totalMemoryMB: 1024
awaitIp: false
customizeGuestOs: false
Something like a drop down menu with the number of VMs that you want to deploy, then select the number and it will be used by the count in the template.
With the above if they select for example number 2 can we get this into count to say if 2 is selected then count the count value is 2, if 5 is selected then 5 will be the count value, etc
The issues that I am trying to solve:
1. Syntax
I get a syntax error : Error while validating count property string found, integer expected ---- I am not understanding why it's complaining about this?
2. How can I get the logic for count so when they select a number then count gets it as a value and the correct number of VMs are created.
count: ${input.env-size == "2" ? 1}
Ideally it will be better if the user could just type the number of VMs needed rather than a drop down menu but I am unable to get that one to work at all.
Thanks for your help.
There are 2 correction which are needed , you are specifying the if condition but you have not specified what would have if environment size is not equal to 2 and you missed to add quotes as syntax for use in yaml.
here is the sample which would work.
formatVersion: 1
inputs:
environmentsize:
type: integer
title: 'Environment Size'
enum:
- 2
- 4
totalvm:
type: integer
title: 'Enter Total Number of VM'
enum:
- 0
- 1
- 2
- 3
- 4
resources:
Cloud_vSphere_Network_1:
type: Cloud.vSphere.Network
properties:
networkType: existing
Cloud_vSphere_Machine_1:
type: Cloud.vSphere.Machine
properties:
image: Linux
cpuCount: 1
totalMemoryMB: 1024
count: '${input.environmentsize == to_number(2) ? 2 : 1 }'
networks:
- network: ${resource.Cloud_vSphere_Network_1.id}
If resolved your issue , Mark this thread as resolved and right answer
Thanks Ankush, will test shortly and provide an update. Would it be possible to replace the enum (drop down menu with numbers) with a way for the user to type the number of VMs instead, so for example, the user will type 100 VMs and then that value will be send to the count as the new value to create 100 VMs as part of the request. Thank you so much!
Yes you can do with below
formatVersion: 1
inputs:
totalvm:
type: integer
title: Enter Total Number of VM
default: 1
maximum: 100
resources:
Cloud_vSphere_Network_1:
type: Cloud.vSphere.Network
properties:
networkType: existing
Cloud_vSphere_Machine_1:
type: Cloud.vSphere.Machine
properties:
image: Linux
cpuCount: 1
totalMemoryMB: 1024
count: ${input.totalvm}
networks:
- network: ${resource.Cloud_vSphere_Network_1.id}
Thanks the count works great, but I just realized after testing further that the ansible part fails with the following error:
If the count is 1 then ansible executes (I guess it's a 1 VM to 1 Ansible ratio) but if the count is more than 1 then it fails with the error above. I feel it's getting confused when there is more than 1 count (VM) because it might be expecting another Ansible action? Something like cloud_ansible_1 (object) per Cloud_vSphere_Machine_1 works (1:1) but because there are multiple Cloud_vSphere_Machine_XXX because of the count = XXX and just one cloud_ansible_1 (object) fails.
Here's the yaml code for the template:
formatVersion: 1
inputs:
totalvm:
type: integer
title: Enter Total Number of VM
default: 1
maximum: 100
leaseDays:
type: integer
minimum: 60
maximum: 120
description: The lease values accepted are between 60-120 days.
resources:
Cloud_vSphere_Machine_1:
type: Cloud.vSphere.Machine
cloudConfig: |
#cloud-config
preserve_hostname: false
runcmd:
- hostnamectl set-hostname ${env.deploymentName}
properties:
image: Ub
count: ${input.totalvm}
cpuCount: 2
totalMemoryMB: 4096
awaitIp: false
customizeGuestOs: false
Cloud_vSphere_Network_1:
type: Cloud.vSphere.Network
properties:
networkType: existing
Cloud_Ansible_1:
type: Cloud.Ansible
properties:
authentication: usernamePassword
inventoryFile: /home/ansible/inventory
username: ansible
password: xxx
groups:
- lin
playbooks:
provision:
- /home/ansible/ub.yml
hostVariables: |
message: Hello ${env.requestedBy}
project: ${env.projectName}
hostName: ${env.deploymentName}
reqUser: ${env.requestedBy}
osType: linux
maxConnectionRetries: 4
account: Ansible
host: ${resource.Cloud_vSphere_Machine_1.*}
I don't know how to handle this scenario with count and ansible?
Thanks
Please open different thread as it is separate query than reported on this thread
Sure. The new one is here. Thanks.