VaranAwesomenow
Mega Sage

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

 find_real_file.png

Select Virtual Server

Change the state of Resource block to Draft

find_real_file.png

Navigate to Operations -> Steps

Select Operation  = Virtual Server Interface

Add operation

find_real_file.png

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

 

Add Step

find_real_file.png

 

Operation Type = Invoke Flow

find_real_file.png

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

Stack table fields are available via context.order.stack.<field_name>

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

 find_real_file.png

 

Create custom operation to pass updates to CPG

Inputs

 find_real_file.png

Step1  = script action, Name = Send response to CPG

Required runtime = instance, below is the mapping

find_real_file.png

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

 find_real_file.png

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

 find_real_file.png

Rest of setup is part of Ansible Spoke.

 

Demo

Navigate to cloud user portal -> Stacks

find_real_file.png

Open correct stack

Ex : AWSUbuntuApr142021

Select correct stack on which operation has to performed

Ex: Apr15Test1

 find_real_file.png

Click on Virtual server resource of the stack

find_real_file.png

Select resource operation that is created

Ex : AnsibleTestStop

Select Ok in the popup window.

find_real_file.png

Wait for execution to complete

Navigate to flow executions

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

 find_real_file.png

Open the execution

Check the input parameters

find_real_file.png

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.

 

find_real_file.png

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)

 

Version history
Last update:
‎04-15-2021 04:25 AM
Updated by: