Hello,
Opening a new thread, to resolve an issue I am running into from a different thread.
Seeking for some help for the following:
As suggested previously I am using "count" to generate multiple instances of a VM 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 between count and ansible. Any help would be appreciated.
Thanks
Try with this and replace image mapping name
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
properties:
image: Linux
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
count: ${input.totalvm}
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"].*}'
Thanks Ankush.
I've tried the code but for some reason I get the following error.
Do you have IP addresses available in your network profile ?
error message says IP is not available
Yes, the network profile works with other cloud templates. The network profile connects to a vDS which is served by DHCP. I've tried several things but nothing seems to work. The strange thing is that the VMs get a valid IP address but the deployments are just copy from the template without any changes it's like ansible doesn't run, so the hostname isn't changed, etc (part of the play). I've checked the ansible inventory file and the names of the deployments are not in there, I am wondering if it's getting confused and doesn't know how to enter the addresses in the inventory which will prevent ansible from running and configure the VM with the play. I also tried deploying a single VM (count 1) and same issue. Does this code work for you? Can you think of anything in the code the might be preventing to register the IPs in the inventory file?
Thanks