Orchestration Chef Activities

From ServiceNow Wiki
Jump to: navigation, search
Orchestration
Related Topics
Knowledge.gif Get the Book

1 Overview

Chef is a server management application that can use ServiceNow configuration item (CI) data to bring computers into a desired state. ServiceNow can interact with a Chef automation server through various Orchestration activities.

2 Shared Input Variables

All Chef activities share these input variables.

Field Description
Use hosted Chef Value that indicates if the Chef server is hosted by Opscode. This value can be true, false, or a JavaScript function that returns either true or false.
Chef server The IP address of a Chef server hosted in your own environment. This variable is mandatory if Hosted Chef is False. Leave this variable blank if Hosted Chef is True.
Organization The Chef organization. Organizations contain groups and users. This variable is mandatory if Hosted Chef is True or when using self-hosted Enterprise Chef. For more information, see the Chef Organizations documentation.
User account A Chef user account record. This record holds the information necessary to make Chef API calls including the username, keystore, and alias of a Chef user.
Sensor script JavaScript that processes the results of requests made to the Chef server.

3 Chef Request

The Chef Request activity sends a Chef API request to a Chef server. This activity stores returned data in the responses sensor script variable as an array of JavaScript objects. Each object in the array contains the following fields.

  • response_code: the HTTP response code for the request.
  • success: a boolean value that indicates whether the request was successful or not.
  • request_url: the endpoint for the request.
  • response_body: the raw data returned from the Chef server.
Note
Note: All other Chef activities implement a specific Chef request and contain these fields in their sensor script variable. Some activities also contain additional fields in their sensor script variable.


3.1 Results

  • Success: the Chef server returned a response. The activity returns a successful result even if one or more Chef requests failed. To determine the success of a specific request, use the success value from an object stored in the responses variable.
  • Failure: the Chef server was not available or rejected the supplied credentials.

3.2 Input Variables

Field Description
Method The type of REST function to execute. Possible values are GET, POST, PUT, and DELETE.
Target data An array of JavaScript objects. Each object specifies these values:
  • targetPath: the target endpoint for this request. See the Chef API endpoint documentation for information on specifying an endpoint.
  • content: the body of the message, written in JSON, when using a PUT or POST REST message.

4 Get Cookbooks

The Get Cookbooks activity retrieves name and version information about cookbooks installed on a Chef server. The activity stores the retrieved cookbook information in the cookbooks sensor script variable as an array of JavaScript objects. Each object in the array contains the following fields:

  • name: the name of the cookbook.
  • version: the version of the cookbook.

For more information, see the Chef cookbook documentation.

4.1 Results

  • Success: the Chef request was successful.
  • Failure: the Chef request failed, the Chef server was unavailable, or the Chef server rejected the supplied credentials.

4.2 Input Variables

The Get Cookbooks activity uses only shared input variables.

5 Get Cookbook Data

The Get Cookbook Data activity retrieves the recipes and attributes from a given cookbook. The activity stores the retrieved cookbook data in the cookbookData sensor script variable as an array of JavaScript objects. Each object contains the following fields, as well as all fields returned by the Chef Request activity:

  • name: the name of the cookbook.
  • recipes: a list of recipes stored in the cookbook.
  • attributes: a parameter that controls the behavior of a node, such as the port used by a web server.

5.1 Results

  • Success: the Chef server returned a response. The activity returns a successful result even if one or more Chef requests failed. To determine the success of a specific request, use the success value from an object stored in the cookbookData variable.
  • Failure: the Chef server was not available or rejected the supplied credentials.

5.2 Input Variables

Field Description
Cookbook data An array of JavaScript objects that defines which cookbooks to get data from. Each object contains the following fields:
  • cookbook_name: the name of the cookbook to get data for.
  • cookbook_version: the version of the cookbook to get data for.

6 Get Environments

The Get Environments activity retrieves the names of all environments on a given Chef server. The activity stores retrieved environment names as an array of strings in the environments sensor script variable.

6.1 Results

  • Success: the Chef request was successful.
  • Failure: the Chef request failed, the Chef server was unavailable, or the Chef server rejected the supplied credentials.

6.2 Input Variables

The Get Environments activity uses only shared input variables.

7 Get Recipes

The Get Recipes activity retrieves all recipes stored in a version of a cookbook. Unlike the Get Cookbook Data activity, the Get Recipes activity does not get attribute information. The activity stores retrieved recipes in the recipes sensor script variable as an array of JavaScript objects. Each object in this array contains the following fields, as well as all fields returned by the Chef Request activity:

  • cookbook_name: the name of the cookbook, passed in the Cookbook data activity input variable.
  • cookbook_version: the version of the cookbook, passed in the Cookbook data activity input variable.
  • recipes: an array of JavaScript objects that lists the recipes contained in the cookbook. Each object in this array contains the name of a single recipe and the description of that recipe.

7.1 Results

  • Success: the Chef request was successful.
  • Failure: the Chef request failed, the Chef server was unavailable, or the Chef server rejected the supplied credentials.

7.2 Input Variables

Field Description
Cookbook data An array of JavaScript objects that lists the cookbooks to get recipes from. Each object in the array contains the following fields:
  • cookbook_name: the name of the cookbook to get recipes from.
  • cookbook_version: the version of the cookbook to get recipes from.

8 Get Roles

The Get Roles activity retrieves roles installed on a given Chef server. The activity stores a list of retrieved role names in the roles sensor script variable.

8.1 Results

  • Success: the Chef request was successful.
  • Failure: the Chef request failed, the Chef server was unavailable, or the Chef server rejected the supplied credentials.

8.2 Input Variables

The Get Roles activity uses only shared input variables.

9 Get Role Data

The Get Role Data activity retrieves additional information about a given Chef role. The activity stores retrieved role data in the roleData sensor script variable as a JavaScript object. The object contains the following fields, as well as all fields returned by the Chef Request activity:

  • role_name: the name of the role, passed in the Role data activity input variable.
  • description: a description of the role, if available.
  • run_list: the list of recipes and other roles that the role contains.
  • default_attributes: attributes that apply to nodes with this role.
  • override_attributes: attributes that apply to nodes with this role. These attributes can override a default attribute inherited from a parent role.

9.1 Results

  • Success: the Chef server returned a response. The activity returns a successful result even if one or more Chef requests failed. To determine the success of a specific request, use the success value from an object stored in the roleData variable.
  • Failure: the Chef server was not available or rejected the supplied credentials.

9.2 Input Variables

Field Description
Role data An array of JavaScript objects that defines which roles to get more information about. Each object contains the following field:
  • role_name: the name of the role to get more information about.

10 Update Node

The Update Node activity updates a given Chef node with a run list. A run list defines which recipes, roles, and attributes to apply to a Chef node, and the order to apply them. For more information, see the Chef run list documentation. The activity stores returned data in the nodeData sensor script variable as an array of JavaScript objects. The object contains the following fields, as well as all fields returned by the Chef Request activity:

  • fqdn: the given fully-qualified domain name for the node.
  • Any other name-value pairs based on the value entered in the Node data activity input variable.

10.1 Results

  • Success: the Chef server returned a response. The activity returns a successful result even if one or more Chef requests failed. To determine the success of a specific request, use the success value from an object stored in the nodeData variable.
  • Failure: the Chef server was not available or rejected the supplied credentials.

10.2 Input Variables

Field Description
Run list An array of JavaScript objects that defines the configuration settings to push to Chef. Objects in this array contain the following fields:
  • type: the type of Chef resource. Valid types are recipe or role.
  • name: the name of the recipe or role.
Environment The Chef environment the specified node should belong to.
Node data An array of JavaScript objects that defines additional configuration settings, including attributes, for the Chef node. Objects in this array contain the following fields:
  • fqdn: the fully-qualified domain name of the node to update.
  • attribute: an array of JavaScript objects that defines the attributes to apply. Objects in this array contain the following fields:
    • name: the name of an attribute.
    • value: the value to assign the specified attribute.
    • type: [Optional] the type of attribute. Supported values are normal, default, and override. The attribute type is normal by default.
    • namespace: [Optional] an array of strings that defines the attribute path. For example, to access an attribute called db_name with a path of mysql/db/db_name, enter a namespace value of ['mysql', 'db'].
Was this article helpful?
Yes, I found what I needed
No, I need more assistance