logo

NJP

Cloud Management : Making Script Execution work for both Greenfield and Brownfield VMs

Import · Aug 23, 2019 · article

As we focus more on our brownfield resources, one common requirement is to be able to execute scripts on brownfield VMs(Servers not provisioned through ServicveNow). As far as Greenfield Servers are concerned(VMs provisioned by ServiceNow), we already know about the credentials associated with VM, However, in case of brownfield VM's as Cloud discovery don't give back enough info to run scripts, so there is a manual process involved. Here are the steps which you can follow.

Prerequisite: Any vm on which you need execute script operation, you should know in advance what is the user name/password set , if the VM is accessible through private key, you will need to have that private key available physically.

Step1: Create a new SSH Key Pair type of credential with username/password/private key.

image

Step2: Associate these credentials with the VM, Go to sn_cmp_vm_node_user_creds,Set Orchestration Credentials as newly created SSH key pair credential. Set node against which these credentials were created.

image

Step3: Import the update set from share. click here

Step4: Make sure your Virtual Server is assigned to a group so that it shows up on portal. Set the Assign to field if not set already.

imageStep5: Now, Either Create an Extension Interface and override ExecuteScript Operation in Virtual Server (Right way to do it) or you can make changes in the existing Virtual Server interface >> Execute Script operation (only for testing).

Go to Operation > Input Parameters,

1.Add a new parameter as resourceId with mapping as ${parameter.resourceId}

2. Change the expression for NodeAddress as $(Script:CMPVMUtils.getReachableIp[arg=${parameter.resourceId}])

3. Change the expression for NodeCredential as $(Script:CMPBrownfieldHelper.getNodeCredential[arg=${parameter.resourceId},arg=${parameter.CredentialId}])

4. you can alternatively ask the user credentials at runtime too, if that is the use case, you can create another Input parameter as CredentialId with mapping as ${parameter.CredentialId} (Not mandatory right now)

5.Make sure your operation type is public so that it shows up on portal as day2.

image

6. Cloud Scripts :You should have a valid Cloud Script and template setup in CMP which you can select from portal.image

And you are done. Go to Cloud Portal >> Resources, Find your virtual server,

image

If you need to pass script parameters, you can make use of Resource Policies to pass additional script parameters.

View original source

https://www.servicenow.com/community/itom-articles/cloud-management-making-script-execution-work-for-both/ta-p/2322004