Actions

Actions are executable scripts in the form of CloudBolt plug-ins, remote scripts, webhooks, emails, and external orchestration engine flows (HPSA, vCO).

This section is meant to provide the initial information needed to get started authoring actions. For sample content, go to any of the links in “Contexts in which actions may be executed” on Admin > All Actions. On those views, you can browse actions published on the CloudBolt Content Library by clicking the cloud button in the top right.

../../_images/content_lib_buttons.png

You may also visit the CloudBolt Forge which contains content that is not yet browsable from the CB user interface. If you have questions, do not hesitate to contact CloudBolt support or post to our community help forum.

Action Types

Every action is of a particular type, which indicates its mode of execution:

  • CloudBolt Plug-in - Python module that runs on the CloudBolt server and has access to internal CloudBolt APIs
  • Remote script - arbitrary code that runs on servers under management by CloudBolt
  • Webhook - call external APIs to integrate CloudBolt with other systems
  • Email - send emails to one or more recipients
  • External flow - run workflows in external orchestrators such as HP Operations Orchestration or vCenter Orchestrator

Actions with Code

Plug-ins and remote scripts execute code. This code can either be installed on the CloudBolt server by uploading a file or loaded dynamically from a URL. The latter option allows you to maintain action code in a source code repository and deploy changes in a controlled fashion.

../../_images/upload-or-url.png

Uploaded File

CloudBolt stores uploaded source code files in an upgrade-safe location: /var/www/html/cloudbolt/static/uploads/hooks/.

Some actions come with a source code file provided out-of-the-box. It is perfectly safe to edit these actions, and your version of the code will be stored in the upgrade-safe location above. You can also easily view both the current code and the out-of-the-box code, in order to compare them.

External Source Code

To use code hosted on another system, determine the URL to the raw file content on that system.

GitHub Example

Navigate to the script in your github.com repository. Click on the Raw link and copy the contents of the address bar without the stuff after the question mark to get a URL like this: https://github.com/CloudBoltSoftware/cloudbolt-forge/blob/master/actions/remote_scripts/restart_apache/restart_apache.sh

../../_images/github-raw-content.png

GitHub also supports branch names in URLs (above example is in the ‘master’ branch), so you might create a production branch and only push updates to it when they are ready to be used by CloudBolt.

Source Code Repository Authentication

If your repository is private, CloudBolt will need to have credentials to access file contents. Go to Admin > Connection Info.

Create a new Connection Info entry named exactly “Source Code Repository”. Provide any value for IP/hostname, like “github.com” (this field isn’t used but is required) and enter Username and Password of an account that has at least read-access to the repository.

Action Input Parameters

CloudBolt will automatically scan user defined actions to determine if additional input is required for the action to be executed. This process is covered in more detail where each of the Action Types are documented. CloudBolt will handle prompting users for those inputs or substituting in pre-designated default values where appropriate. Note that CloudBolt will not create action inputs for template variables that start with the keyword server, like “”{{ server.ip }}”. To see a full list of these context keys provided by CloudBolt, see Action Context.

CloudBolt adminstrators can customize the input parameters that are auto-discovered, giving them label, description, type, dependencies, and validation constraints. In addition, for CB plug-ins options for the input parameters can be defined in methods within the plug-in, as described in CloudBolt Plug-in Parameterization.

Action inputs can also reference other CloudBolt resources. For instance: If you have a post-provision action to add a server to a load balancer or a back-up schedule by hostname, you can define the default for the “hostname” input parameter to be “{{server.hostname}}”.

Blueprint Action Context

When executing an action as part of a blueprint deployment the entire deployment is available to the action context. If, for instance you have a database server being built, using a BP build item named ‘DB’, you can reference the context of that item in any action by setting an input parameter value to something like “{{blueprint_context.db.server.ip}}”. Besides being converted to lower case, build item names are modified by converting spaces or hyphens to underscores and removing other non-alphanumeric characters. The conversion also strips leading and trailing whitespace.

Action Blueprint Item Context

Key/value pair representing a mapping between the action inputs and the values that should be used on a given execution.

Provision Server Blueprint Item Context

  • quantity: Reference to the number of Server(s) that will be created by this item.
  • os_build: Reference to the CloudBolt object for the OSBuild being used to provision the Server(s).
  • applications: List of references to CloudBolt objects for all applications included in the provisioning.
  • servers: List of references to the CloudBolt Server objects being provisioned in this item.
  • server: Convenient short-cut available if only one server is being provisioned.
  • <parameter_name> for each parameter on the item: To access the value that will be used for the parameter.
  • <preconfig_name> for each preconfiguration on the item: To access the value that will be used for the preconfiguration.

Pod Blueprint Item Context

  • images: Comma delimited string of images to be installed in the container.
  • container_orchestrator: Reference to the CloudBolt object for the Container Orchestrator being used.

Load Balancer Blueprint Item Context

  • source_port: Access the source port that will be used
  • destination_port: Access the destination port that will be used

Retrying Actions

All base actions can have a value set for max retries. This means that, whenever the action runs, if it returns a nonsuccessful status or raises an exception, it will be retried up to the max retries number of times. This can be helpful if you have an action that needs to interact with a flaky external system that sometimes fails, for example. Note that for CloudBolt plug-ins the retry logic only applies to methods named “run”.

Exporting and Importing Actions

CloudBolt allows actions to be exported as files so they can be easily reused across CloudBolt instances, or shared in the CloudBolt Forge, a repository of sample CloudBolt resources. Exported actions are typically stored as zip files containing JSON-formatted metadata about the action along with any scripts associated with the action.

When exporting, you can choose between a sanitized or instance-specific version of your action. The formats are the same, but the sanitized version will omit potentially sensitive information such as script credentials, environments, and groups. This makes sanitized versions great for sharing actions on the CloudBolt Forge, or for moving them between CloudBolt instances that don’t have the same groups and environments.

You can import actions in the UI wherever you can create new actions. Note that actions can only be imported in the same context from which they were exported. For example, to import an action as a server action, the action must have been exported from the Server Actions page.

The CloudBolt Forge contains a variety of shared resources you can use to make CloudBolt more powerful. Actions in the CloudBolt Forge are stored unzipped so you can easily browse their contents. To import one of these actions, zip the folder containing the action’s files before uploading.

Actions can also be imported using the CloudBolt API. The sample API scripts included with CloudBolt have an example of how this can be done.