- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 04-15-2021 04:25 AM
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
Select Virtual Server
Change the state of Resource block to Draft
Navigate to Operations -> Steps
Select Operation = Virtual Server Interface
Add operation
Give Name (Ex: AnsibleTestStop), Operation (ex : Stop, Start), Access Type = Public
Add Step
Operation Type = Invoke Flow
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
Create custom operation to pass updates to CPG
Inputs
Step1 = script action, Name = Send response to CPG
Required runtime = instance, below is the mapping
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
Adding this operation to subflow, add action and map correlationid to flowcorrelationid (which is subflow input)
Rest of setup is part of Ansible Spoke.
Demo
Navigate to cloud user portal -> Stacks
Open correct stack
Ex : AWSUbuntuApr142021
Select correct stack on which operation has to performed
Ex: Apr15Test1
Click on Virtual server resource of the stack
Select resource operation that is created
Ex : AnsibleTestStop
Select Ok in the popup window.
Wait for execution to complete
Navigate to flow executions
Open the execution
Check the input parameters
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.
References
Ansible to ServiceNow CPG integration - IT Operations Management - Article - ServiceNow Community
Add a resource operation step to invoke a subflow (servicenow.com)
- 1,065 Views