logo

NJP

Invoke a Subflow from Cloud Provisioning operation for virtual server or any stack item

Import · Apr 15, 2021 · article

How to add Day 2 operation to virtual server

Theory

https://youtu.be/thv80zHsXl0

Ansible Installation

https://youtu.be/AyLeLvO7oSI

Ansible playbook creation

https://youtu.be/Ktt7y2JgUF4

ServiceNow setup

How to add Day 2 operation to virtual server

Step1 : Navigate to Cloud Admin portal -> Resource Blocks

image

Select Virtual Server

Change the state of Resource block to Draft

image

Navigate to Operations -> Steps

Select Operation = Virtual Server Interface

Add operation

image

Give Name (Ex: AnsibleTestStop), Operation (ex : Stop, Start), Access Type = Public

Add Step

image

Operation Type = Invoke Flow

image

Subflow = name of subflow that needs to be invoked (Subflow should be in published state)

Input tab -> This auto populates with input values from Subflow inputs.

Following changes are needed to input parameter mapping

Parameter Value Comments
Flowcorrelationid $(Script:CMPFlowStepHandler.generateCorrelationId) This is used to store correlation id which will be used by flow to post back the results
Stackdetails $(context.order.stack.short_description) This contains details of stack such as name , ip address.. Table = sn_cmp_stack Column = short_description Sample value : {"InstanceId":"i-08d90bbb7a9dd5836","PublicIP":"3.142.152.50","AZ":"us-east-2b","PublicDNS":"ec2-3-142-152-50.us-east-2.compute.amazonaws.com"}
stackid $(context.order.stack) This is reference to the stack record that contains the resource from which this operation is invoked
Stackstatus $(context.order.stack.stack_status) This is status of stack

If any other parameters are needed and if they are available either in order table or stack table they can be retrieved

Order table fields are available via context.order.

Stack table fields are available via context.order.stack.

Order table = sn_cmp_order

Stack table = sn_cmp_order

Subflow setup

This subflow invokes Ansible REST API to run a job.

API end point = Ansible endpoint to trigger a job template

Base url = https://ANSIBLETOWERIPADDRESS/api/v2/ To be set to correct IP address or DNS name

resource path = job_templates/11/launch

image

Create custom operation to pass updates to CPG

Inputs

image

Step1 = script action, Name = Send response to CPG

Required runtime = instance, below is the mapping

image

Script

(function execute(inputs, outputs) {

// ... code ...

gs.info("******[CMP] Flow Inputs--- " + JSON.stringify(inputs));

new sn_cmp.CMPFlowDesignStepHandler().populateFlowResult(inputs.correlationid, inputs);

outputs.result = JSON.stringify(inputs);

gs.info("****[CMP] Flow outputs ----" + JSON.stringify(outputs.result));

})(inputs, outputs);

Output variables

image

Adding this operation to subflow, add action and map correlationid to flowcorrelationid (which is subflow input)

image

Rest of setup is part of Ansible Spoke.

Demo

Navigate to cloud user portal -> Stacks

image

Open correct stack

Ex : AWSUbuntuApr142021

Select correct stack on which operation has to performed

Ex: Apr15Test1

image

Click on Virtual server resource of the stack

image

Select resource operation that is created

Ex : AnsibleTestStop

Select Ok in the popup window.

image

Wait for execution to complete

Navigate to flow executions

https://.service-now.com/$flow-designer.do?sysparm_nostack=true#/welcome/recent-execut...

image

Open the execution

Check the input parameters

image

RUNTIME VALUE

StackID

5e9d2b452f632c10f101ad2ef699b6da

flowcorrelationid

d436925d2fe76c10f101ad2ef699b6a3

stackstatus

2

Stackdetails :

{"InstanceId":"i-08d90bbb7a9dd5836","PublicIP":"3.142.152.50","AZ":"us-east-2b","PublicDNS":"ec2-3-142-152-50.us-east-2.compute.amazonaws.com"}

Verify that the input parameters have correct values, these can now be used in flow action to process ansible API.

Resource operation output on cloud user portal once subflow execution is complete.

image

References

Ansible to ServiceNow CPG integration - IT Operations Management - Article - ServiceNow Community

ServiceNow Cloud Provisioning and Governance: How to integrate a third party IPAM tool? - IT Operati...

Add a resource operation step to invoke a subflow (servicenow.com)

View original source

https://www.servicenow.com/community/itom-articles/invoke-a-subflow-from-cloud-provisioning-operation-for-virtual/ta-p/2295386