logo

NJP

Pre and Post Provision operation with Templates

Import · Sep 30, 2019 · article

In this article we will see how to do pre and post provision operations with the templates.

The flow would be like this:

  • Create a catalog item and ingest a template.
  • Add a Pre-Provision operation. In this sample we will call a simple workflow.You can call workflows, Cloud API, Script includes as well.
  • Add a Post-Provision operation. In this sample we will call a simple workflow. You can call workflows, Cloud API, Script includes as well.

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'.

image

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.

image

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.

image

Let us look at the Pre-Process WF first. It is a simple workflow that looks like this:

image

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.

image

The 'Log Workflow Inputs' step looks like this:

image

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.

image

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.

image

Let us click on 'Pre Provision Operation' tab. You would see a 'new' button there.

image

Click on the 'New' button to add a Pre Provision step. A create form would show up like this:

image

In this example, we will choose Workflow. You can choose as per your use case.

image

Choose 'Workflow' and then click on the 'search button' for choosing which workflow.

image

Choose Pre-Process WF and hit OK. In your instance, you would be choosing an appropriate workflow.

Then click Submit as shown below.

image

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:

image

The 'Manage Attributes' screen will show up. You need to choose the 'Pre Provision' operation call as shown below.

image

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'.

image

Click on Update.

Then click on the 'Apply Changes'.

image

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:

image

Mark the catalog item as active so that end users can order it.

image

Now get into the Cloud User Portal (or via url https://your_server_here/cloud_portal). Get to the 'Catalog' section.

image

Choose the 'Pre and Post Prov Sample' catalog item.

Put in proper values for all fields. For the StackName i am using 'TestPreAndPost'.

image

Then click the submit button as indicated below.

image

You will then see that the Pre-Provision step is getting executed.

image

After this call is completed, you will see the template getting executed.

image

When the template is provisioned and the targeted discovery of the resources is completed, the Post-Provisioning step gets executed.

image

We just saw how to enable Pre and Post provisioning operations on a template driven catalog item.

View original source

https://www.servicenow.com/community/itom-articles/pre-and-post-provision-operation-with-templates/ta-p/2319499