I’m always trying to automate as many processes at work. Earlier this year we started working on trying to automate as much of Infrastructure deployment as possible. Turning manual processes which require a lot of documentation into code that can be stored in source control. This is commonly known as Infrastructure as Code.

One idea I had a few months back was to try and automate the deployment of VMware Appliances with configuration injected. Last weekend I had some time to work on a script that can deploy OVF’s to VMware vCenter and VMware ESXi directly.

The script is written in Microsoft PowerShell and requires version 3+ of PowerShell along with VMware vSphere PowerCli. Configuration values that the script uses are held in a JSON data file. This allows one copy of the script to be stored and a number of JSON configuration files used against it. All this could be stored in a source control system like GIT.

Another requirement is VMware OVF Tool. This is used to deploy the appliance to the vCenter or ESXi host and inject the configuration properties. OVF Tool can’t currently deploy appliances to directly ESXi with customised properties. Version 4 of the tool will have the added the parameter: –X:injectOvfEnv to do this but this has at this point not yet been released.

Thanks must go to William Lam who recently wrote an article and put together some scripts that can inject properties into a OVF once OVF tool has deployed it to a ESXi host. I have used this example to inject the properties until version 4 of OVF tool has been released.

I have added the script along with sample configuration files to GitHub. I have made the script flexible so you should be able to use it to deploy other VMware Appliances that require configuration properties for deployment.

Eamples:

How to execute the script from PowerShell:

 .\\Deploy\_VMware\_Appliance.ps1 -configpath
D:\\configuration\\vco\_5\_5\_config\_host.json\

Here is an example of the configuration file to deploy the VMware vCenter appliance directly to a ESXi host. Note you shouldn’t change the property: vm.vmname.

{
    "config": {
        "deployType": "host",
        "deployConfig": {
            "host": "192.168.10.51",
            "host_username": "root",
            "host_password": "password",
            "vmName": "vcsa",
            "datastore": "DS1",
            "diskMode": "thin",
            "network": "VM Network",
            "powerOn": true,
            "ovfpath": "D:\\Mware-vCenter-Server-Appliance-5.5.0.5100-1312297_OVF10.ova"
        },
        "properties":
            {
            "vami.DNS.VMware_vCenter_Server_Appliance":"192.168.10.55",
            "vami.gateway.VMware_vCenter_Server_Appliance":"192.168.10.1",
            "vami.hostname":"vcsa.domain.local",
            "vami.ip0.VMware_vCenter_Server_Appliance":"192.168.10.56",
            "vami.netmask0.VMware_vCenter_Server_Appliance":"255.255.255.0",
            "vm.vmname":"VMware_vCenter_Server_Appliance"
            }
    }
}

More details and examples are available in the GitHub Repository.

You can view and download the project from GitHub



Comments

comments powered by Disqus