CloudConfig is a great way to expand the abilities of your deployments in vRealize Automation. CloudConfig is a standardized structure of coding that is functional across all clouds. It utilizes CloudInit within Linux based OS’s and Cloudbase-Init within Windows OS’s. Both utilities are free to use and rather easy to setup, so I won’t cover anything about that here. Given that both CloudInit and Cloudbase-Init follow the same code structure, here is a great resource for code example reference.
Cloud Configuration in Image Mappings
If you read my post about Image Mappings, you remember that we briefly discussed that we could add Cloud Configurations at this level. I like to do this when every deployment of the given OS requires something to be done with it. This keeps it all in one place to maintain rather than having it specified per Cloud Template.
The first line of code is to tell the CloudInit or Cloudbase-Init service what the code type is. In this case we are using ‘#cloud-config’. This should be the first line in your code when you are using CloudConfig coding. As you will see in the Cloud Templates example below, I show setting it up to be PowerShell code, which may clear this up a bit.
This example shows us running a single line of runcmd that changes to the ssh directory and generates a new host key and restarts the sshd service. This is because CloudInit by default flushes all the hosts keys when it runs the first time to prevent duplication of keys due to cloning machines.
Cloud Configuration in Cloud Templates
Here within the Cloud Template itself, we will do most of our Cloud Configuration work. The below use case was to format and label additional disks attached to the Machine resource and then install SQL Server. I chose to do this with PowerShell since that is an easy way to code within Windows. To do this we need to specify the code type as ‘#ps1_sysnative’. This will ensure that the system knows that we are executing powershell and it will take all the code listed below and create a ps1 file on the destination machine. Once the file is copied up, it will execute the PowerShell script.
Cloud Configuration Multipart configuration
There will be instances where you will end up generating a multipart cloud configuration. What is a multipart configuration? Well, a multipart configuration is built for you when you have cloud configurations in Image Mappings as well as Cloud Templates. They are pieced together when you deploy and are applied as one multipart cloud configuration.
If you find yourself needing to run both native CloudConfig as well as PowerShell or other shell script within the same area as the Cloud Template, we need to build this multipart configuration ourselves. Let’s look at a simplified example that we can talk through.
First, we define this being a multipart/mixed configuration and specify how we signify the beginning of a part. Here I chose to use ===BEGIN to signify the beginning of the part.
cloudConfig: |
Content-Type: multipart/mixed; boundary=”===BEGIN”
MIME-Version: 1.0
Next, we create the header for the part. We begin with our defined boundary with 2 dashes in front. We need to specify the appropriate Content-Type, text/cloud-config for all CloudConfig code and text/x-shellscript will be for PowerShell or other shell scripting. The last thing to pay attention to will be the filename. For CloudConfig, leave this as cloud-config. For your shell scripts name them what you want them to be in the file system of the deployed machine.
Leave A Reply