Cloud initialization scripts Cloud initialization scripts give you the ability to run scripts when a virtual machine is provisioned. Cloud initialization script components Cloud initialization scripts have the following components: Template The actual script that is run. Script A script is a container of templates. You can use multiple templates in a script. The script name can be called from a blueprint operation or from an Image template. Parameters Parameters are the attributes that you want to access. An attribute contains a name, a default value, and an override value. Where cloud init scripts are used Cloud initialization scripts are used in: Blueprints The Execute Script operations on a virtual machine in a blueprint provides a field called Script. You map the script name to this field. The script runs after the VM is provisioned. See Example: A post-provisioning cloud script in a blueprint for an example. OS profiles You can map a script to an OS profile. Scripts on blueprints override scripts on image templates. Therefore, if you have a script on both components, only the script specified on the blueprint is run when the VM is provisioned. The script on the Image is ignored. Create cloud initialization script templates and a script Create cloud initialization templates and a script to use during VM provisioning. Before you beginRole required: cloud_admin Procedure Navigate to Cloud Management > Cloud Admin Portal > Design > Cloud Scripts > Cloud Script Templates. Click New. Enter the name and content of the script. Click Submit. Create as many script templates as needed. Navigate to Cloud Management > Cloud Admin Portal > Design > Cloud Scripts. Click New. Enter a descriptive name and create script that uses the template name in the following line of code: templateResolver.getTemplate(scriptName); Where scriptName is the name of the template. Click Submit. What to do nextTo run a script at the time a virtual resource is provisioned, map the script to an OS profile. See Map scripts to an OS profile. To run a post-provisioning script, create a blueprint and specify the script in the Execute Script operation. See Example: A post-provisioning cloud script in a blueprint for an example. Map scripts to an OS profile You can map a script to an OS profile if you want to execute scripted actions during VM provisioning. The script runs on VMs that are created based on the image template in the OS profile. Before you begin Role required: cloud_admin A cloud script that you want to run. Procedure Navigate to Cloud Management > Cloud Admin Portal > Resource Profiles > OS Profiles. On the Cloud Script OS Mappings related list, click New. Fill out the form fields (see table). Field Description Blueprint[Optional] Select a blueprint to limit the script to a specific resource block used in the blueprint. Cloud script Select that cloud script. Active Keep this check box selected to use the script. OS profile Keep the OS profile record that this script mapping is associated with. Resource Alias[Optional] Select the resource block that is part of the blueprint. The script runs when a cloud resource is provisioned based on this resource block. Note: Profile mappings that specify more details are run first. For example, a mapping that specifies a blueprint, OS profile, and resource alias take precedence over a one that just specifies an OS profile. Right-click the form header and select Save. The attribute scriptName appears in the OS Profile Mapping Overrides section. In the OS Profile Mapping Overrides section, enter an optional attribute name and value that you want to use when the resource is provisioned. Example: A post-provisioning cloud script in a blueprint This example shows you how to create a cloud script that is run after a user provisions a virtual machine. Before you begin Role required: cloud_admin An OS resource profile that is mapped to an Image template from which user will provision a resource. You must add the necessary Basic authentication credentials to the Image. A Compute resource profile that is mapped to a Hardware type. About this taskIn this example, you will create a cloud init script, create a new blueprint, and provision a VM from the User Portal. Procedure Create a cloud script template and a cloud script that refers to the template. Create a blueprint with a virtual machine that can be provisioned Add these operations on the Virtual Server resource: Block Until Ready Execute Script: This operation tells the blueprint to run a script. For the Execute Script operation, clear the Script check box and change the expression in the Mapping column to the following text: $(CloudScript.scripts.scriptname), where scriptname is the name of the script, not the script template, that you created above. Figure 1. Example blueprint operations Publish the catalog item from the blueprint. Launch a new stack to provision a VM, and specify the OS profile and Compute profile you had created as a prerequisite to this example task. ResultThe Stack Status screen runs through the CreateNode, BlockUntilReady, and ExecuteShellScript operations. The last operation is what kicked off the script you created above.