---
sourceDocument: Australia IT Operations Management
sourceDocumentLink: https://www.servicenow.com/docs/r/australia/it-operations-management

 Release :

    - australia

ft:locale :

    - en-US

ft:publication_title :

    - Australia IT Operations Management

ft:clusterId :

    - itom

bundleId :

    - itom

workflow :

    - Technology


---

# Cloud scripts and cloud script templates

# Cloud scripts and cloud script templates {#ariaid-title1}

Release version: Australia  
Updated November 5, 2026  
![](https://www.servicenow.com/docs/portal-asset/ico-clock) 3 minutes to read
Summarize  
![AI sparkle icon](https://servicenow.com/docs/portal-asset/ai-sparkle-icon) Summarized using AI  
This content was generated using new OpenAI-powered functionality. Results are provided on an as is basis and are not guaranteed to be accurate or complete.  

## Summary of Cloud scripts and cloud script templates

In the Cloud Provisioning and Governance application, script execution is managed throughcloud scriptsandcloud script templates.
These scripts are used within blueprints, resource blocks, OS profiles, and policy scripts to automate and customize cloud resource provisioning and management.
Cloud scripts are JavaScript-based, leveraging platform features, while cloud script templates are executable scripts (e.g., Shell, PowerShell, CloudInit) targeted at virtual machines.
Show full answer Show less  

## Cloud Scripts

Cloud scripts are JavaScript functions that interact with platform objects like the `templateResolver` to fetch and customize templates dynamically. They use parameters with default and override values to enable flexible execution. These parameters can be simple literals or complex expressions, and script authors can modify them as needed to adapt to specific provisioning scenarios.

For example, you can override a parameter value within a script to customize deployment behavior dynamically by querying data and updating template attributes before fetching the template.

## Cloud Script Templates

Cloud script templates are the actual executable code snippets passed to virtual machines during provisioning. They can be written in any scripting language supported by the target environment (Shell, PowerShell, CloudInit, etc.). These templates must be created first and then associated with corresponding cloud scripts that control their execution.

## Using Cloud Scripts with CloudInit

* **Image level:** Associate a cloud script with a specific image so that whenever that image is used, the script runs by default. This is useful for automating initialization tasks like installing software during VM boot.
* **OS profile level:** Map cloud scripts to OS profiles, either for specific images or generically across multiple images. OS profile mappings override image-level associations and allow parameter overrides for fine-tuned control.
* **Resource blocks:** Execute cloud scripts tied to specific resource blocks or resource aliases within blueprints, enabling targeted automation on particular infrastructure components.

## Cloud Scripts as Postinit Scripts

Cloud scripts can be executed as Postinit scripts within resource blocks by adding an **ExecuteScript** operation. This operation allows selection from a pool of cloud scripts and supports parameter overrides via JSON maps. All Cloud Management-supported expressions can be used in these overrides, providing robust scripting flexibility after resource provisioning.

## Practical Benefits for ServiceNow Customers

* Automate and customize cloud resource provisioning with scripts that dynamically adapt to environment parameters.
* Use script templates to execute platform-specific initialization tasks on VMs during boot time or after provisioning.
* Leverage OS profile and image-level script associations for consistent, repeatable cloud-init processes.
* Override script parameters easily to tailor cloud automation without modifying underlying scripts.
* Incorporate scripting directly into blueprints and resource blocks for end-to-end deployment automation within ServiceNow.  
In the Cloud Provisioning and Governance application, script execution is divided
into cloud scripts and cloud script templates. Use scripts in blueprints, resource blocks, OS
profiles, and use policy scripts to set request form attributes. Policy scripts cannot override
user data.

## Cloud scripts {#cloud-scripts-and-templates__section_j4d_lrc_v2b}

Cloud scripts are simple java scripts that use platform features. An example of a sample cloud script:

    function evaluateTemplate() {
    	// Template Resolver is a helper function which we will use to fetch a template and replace its parameters,
    	// var templateResolver=new TemplateResolver(); this comes inbuild
    	// templateAttributes below will passed from the user.
    	var listDir=templateResolver.getTemplate('Install',templateAttributes);
    	return listDir;
    }

Each cloud script contains certain parameters. Parameters are the attributes that you want
to access. A parameter contains a name, a default value, and an override value. The default
value can be a string literal, a resource block parameter or a complex script expression
used in resource blocks.

A cloud script, by default, has access to the templateResolver object.
The templateResolver object has, by default, a getTemplate method,
whose first parameter is the cloud script template name.
templateAttributes are the cloud script parameters created as part of
a cloud script. If needed, customizations can be done in templateAttributes. As an example, see the following code snippet if the value
of DevName parameter needs to be changed from John to Emily.

    function evaluateTemplate() {
    	// Template Resolver is a helper function which we will use to fetch a template and replace its parameters,
    	// var templateResolver=new TemplateResolver(); this comes inbuild
    	// templateAttributes below will passed from the user.
    	templateAttributes['DevName'] = 'Emily';
    	var customNodeName;
    	var now_GR = new GlideRecord('some_custom_table_to_query');
    	gr.addQuery('some_parameter','some_value');
    	gr.query();
    	if(gr.next())
    	 	customNodeName=gr.getValue('some_custom_node_name');
    		
    	templateAttributes['NodeName'] = customNodeName;
    	var listDir=templateResolver.getTemplate('Install',templateAttributes);
    	return listDir;
    }
    evaluateTemplate();

## Cloud script templates {#cloud-scripts-and-templates__section_rrv_qwc_v2b}

Cloud script templates are actual executables which are passed to target a virtual machine
for execution. Cloud templates can be of any type (Shell/PowerShell/CloudInit) depending on
the execution context. You need to create a cloud template first and then associate it with
a cloud script.

## Cloud scripts as CloudInit {#cloud-scripts-and-templates__section_lyn_yyc_v2b}

Cloud providers provide a way to execute scripts at boottime for virtual machines. In the Cloud Management application, you can specify a cloudinit script at various levels:

* Image level: At the time of creating a cloud script, you can specify an image against which this script should be executed. Once an OS profile which contains this specific image gets selected, the default cloud script against this image is executed. In the example below, an Apache cloud script is associated with a particular image.

* OS profile level: You can run a cloudinit against a specific cloud provider and against a specific AMI/image. You can also be generic and associate a cloudinit to an OS profile, irrespective of the underlying image. In the following example, multiple images are associated with the OS profile. You can map any cloud script to the OS profile in the Cloud Script OS Profile Mappings tab. The mapping of a cloud script with an OS profile takes precedence over the image-level cloud script association.

  In this example, the Apache cloud script is mapped to the Centos OS profile. If needed, you can override the script parameters in the OS Profile Mapping Overrides section.
* Resource blocks: While mapping a cloud script to an OS profile, you can choose whether to execute the cloud script for a specific resource block used in a blueprint. You can also target a particular resource alias. See [Create an OS profile](https://www.servicenow.com/docs/AYw7AjMumTmWHazqWM4OrA "An OS profile installs a specified image on a newly-provisioned virtual machine. You map an OS profile to a cloud account, a location (datacenter), an image template, and a cloud script. OS profiles are provider-agnostic and you can use the same profile for multiple cloud accounts.").
{#cloud-scripts-and-templates__ul_cl4_5zc_v2b}

## Cloud scripts as Postinit {#cloud-scripts-and-templates__section_gbl_b1j_v2b}

You can use cloud scripts as Postinit scripts in a resource block. Once you create a
resource block with a virtual machine to be provisioned, you can add an ExecuteScript
operation. The ExecuteScript operation takes a script parameter (a pool of cloud scripts)
and you can select any script to execute. Use the ScriptParameters
attribute in the ExecuteScript operation to override any script parameter. You can provide a
JSON map of script parameter and its override value. All expressions that are supported by
Cloud Management work in the
ScriptParamters attribute.

