OCI tech-specific script execution

Run ad hoc scripts on OCI instances using OCI’s native command execution mechanism

In Cloud Management Platform (CMP), this is an alternative to SSH, controlled by a server parameter. When enabled, ad hoc scripts are executed by the Oracle Cloud Agent running on the instance rather than over an SSH connection.

How it works

The Oracle Cloud Agent polls for queued commands approximately every 90 seconds. When CMP submits a script to run on an OCI server with tech-specific script execution enabled, the command is added to the Oracle Cloud Agent’s queue. The agent picks up the command on its next poll, executes the script, and returns the output.

Prerequisites

Before using tech-specific script execution, ensure the following are in place:

SSH key

An SSH key must be associated with the image used to provision the server. Servers provisioned from that image inherit the key.

Create an SSH key

  1. Open a terminal and run:

    ssh-keygen -t rsa -b 4096 -m PEM -f ~/.ssh/cloudbolt_oci -C "cloudbolt-oci"
    
  2. Display and copy the private key value:

    cat ~/.ssh/cloudbolt_oci
    

Add the private key to CMP

  1. Go to Admin > SSH Keys.
  2. Select New SSH Key.
  3. Provide a name and paste the key material.
  4. Select Add.

Associate the key with the image

  1. Go to the OCI resource handler.

  2. Open the Images tab.

  3. Under Credentials for an image, select to add or edit credentials.

  4. Provide the Username.

  5. Leave the Password field empty.

  6. Under Key name, select the SSH key.

  7. Select Save.

Public IP address

A public IP address is required on the instance to install the Oracle Cloud Agent.

Server compartment

To use OCI’s native command execution mechanism, instances must be in a sub-compartment. Running scripts via SSH will still work at the root level.

Oracle Cloud Agent

The instance must have the Oracle Cloud Agent installed and running. SSH into the instance using the key pair assigned to its image, then run the following:

# Install the agent
sudo yum install -y oracle-cloud-agent

# Enable and start
sudo systemctl enable oracle-cloud-agent
sudo systemctl start oracle-cloud-agent

# Verify
sudo systemctl status oracle-cloud-agent

Enable tech-specific script execution

Enable the Use Tech-Specific Script Execution parameter at the server or environment level.

Server level

Enable the parameter on existing servers.

  1. Locate the server in CMP.
  2. Open the Parameters tab.
  3. Select Add.
  4. Locate the Use Tech-Specific Script Execution parameter.
  5. Select the parameter, then select Next.
  6. Set the value to True and select Save.

Environment level

Enable the parameter at the environment level to automatically apply it to new servers provisioned in that environment.

  1. Go to Admin > Environments.
  2. Select the environment.
  3. Open the Parameters tab.
  4. Select Add.
  5. Locate and select the Use Tech-Specific Script Execution parameter.
  6. Select Add.
  7. Under Options, select to edit the parameter options.
  8. Select True from the dropdown, then select Add option.
  9. Select Save.

Run an ad hoc script

  1. Go to the server in CMP.
  2. Select Ad Hoc Script.
  3. Enter your script (for example, whoami or date).
  4. Select Run.

CMP checks the job state every 10 seconds. Expect up to 3 minutes for the job to complete. States progress from Visible → Accepted → Acknowledged → Succeeded / Failed. Script output is available once the job reaches Succeeded.