The Now Platform® Washington DC release is live. Watch now!
on ‎09-30-2019 10:23 AM
In this article we will see how to do pre and post provision operations with the templates.
The flow would be like this:
Get to Cloud Admin Portal first. Then get to Cloud Catalog Items. Then create a new catalog item. I am naming it 'Pre and Post Provision Sample'.
I am choosing an ARM template. You can go for CFT, GDM or any template. Save it.
Then go to the 'Cloud Templates' tab and upload/Provide URL for the ARM template and save it. It will read the template and parse the variables.
Then click 'Activate' button to create the variables, variable sets etc on the catalog item.
Let us take a short detour to look at the Pre and Post operations flows we are going to call.
For this exercise we have created two workflows, one for Pre and one for Post provision operation. Both these are basic workflows. In your case you would be using an appropriate workflow. Instead of workflow, you can use a Cloud API or a script include call as applicable.
Let us look at the Pre-Process WF first. It is a simple workflow that looks like this:
It basically logs the inputs that are sent to the workflow. And very importantly returns 'success' as the return. This is critical and this tells us that the workflow execution was successful.
This workflow takes in a single input 'u_payload'. The inputs can be seen here. Click on the properties and you can view it.
The 'Log Workflow Inputs' step looks like this:
In a real life scenario, there could be multiple steps and each one doing something pertinent to your use case.
The 'Return Value' step looks like this. This is important and needed.
The Post-Process WF is very similar to Pre-Process WF. Am not showing the WF here.
Now let us get back to our catalog item.
After you have hit the 'Activate' button, you will see that there are two tabs in the related lists. "Pre Provision Operation" and "Post Provision Operation". This is the place where you add the Pre and Post provision operations.
Let us click on 'Pre Provision Operation' tab. You would see a 'new' button there.
Click on the 'New' button to add a Pre Provision step. A create form would show up like this:
In this example, we will choose Workflow. You can choose as per your use case.
Choose 'Workflow' and then click on the 'search button' for choosing which workflow.
Choose Pre-Process WF and hit OK. In your instance, you would be choosing an appropriate workflow.
Then click Submit as shown below.
This Pre-Process WF takes in a parameter called 'u_payload'. We need to map this 'u_payload' attribute to an appropriate input from the catalog item. For this, click the 'Manage Attributes' link as shown below:
The 'Manage Attributes' screen will show up. You need to choose the 'Pre Provision' operation call as shown below.
CMP reads the inputs for the workflow and auto-adds them to the operation attributes. This way user does not need to add them manually. Then click on the 'u_payload' operation attribute.
In this exercise, We will map the u_payload to StackName. You can change it right here to 'S{parameter.StackName}' or click on the 'u_payload'.
Click on Update.
Then click on the 'Apply Changes'.
The same set of changes need to be done for the Post-Provisioning operation as well. I will leave that as an exercise to the user.
When you are done with it, it would look like this:
Mark the catalog item as active so that end users can order it.
Now get into the Cloud User Portal (or via url https://your_server_here/cloud_portal). Get to the 'Catalog' section.
Choose the 'Pre and Post Prov Sample' catalog item.
Put in proper values for all fields. For the StackName i am using 'TestPreAndPost'.
Then click the submit button as indicated below.
You will then see that the Pre-Provision step is getting executed.
After this call is completed, you will see the template getting executed.
When the template is provisioned and the targeted discovery of the resources is completed, the Post-Provisioning step gets executed.
We just saw how to enable Pre and Post provisioning operations on a template driven catalog item.
Hi Ashok,
Thanks for the article. Will we be able to create catalog tasks using the Pre/Post Provisioning operations?
Thanks & Regards,
Arjun
Thanks! This was helpful. Two issues that I hit along the way:
I am new to using Workflows, and I wasted the better part of a day trying to troubleshoot an issue that turned out to be that I did not Publish the Workflow. ServiceNow just reported a generic error "did not start all flows". Publishing the Workflow fixed this.
When I created my Workflow, I selected the Table "Requested Item [sc_req_item]" based on some other info I found. Then instead of the "Inputs" tab, this shows a "Catalog Variables" tab. I then wasted more time trying to figure out how to populate these variables and access them from the script. After recreating my Workflow and selecting "Global [global]", I was able to follow this example.
I am curious if I can call a Script Include directly instead of using a Workflow. When I tried the "Instance Script" option, it seemed like it was trying to call a method on the "vm" object. In my case I have a Catalog Item based on a Terraform template and I want to invoke a Ansible Tower Template after the environment is provisioned.
hi Arjun,
Were you able to successfully create tasks. I am struggling with passing RITM Sys_id.
Thanks,
Rohini