Skip to main content

Chef Infra Client interpreter

Chef Courier provides first-class integration with Chef Infra Client. This means that Chef Courier can execute Chef Infra Client runs that are defined in a Courier job if the Chef Infra Client skill or an existing Chef Infra Client installation is available as an executable on the node.

The Chef Infra Client interpreter accepts commands in a job definition using the following format:

"command": {
  "exec": "<COMMAND>",
  "args":{
    "<ARG>": "<ARGUMENT_VALUE>"
  }
},

The possible commands are:

download

The download command downloads Cookbooks from public or private Supermarkets using the Chef Supermarket API. You can use the following Supermarket API endpoints with the download command:

  • GET /api/v1/cookbooks/<COOKBOOK_NAME>
  • GET /api/v1/cookbooks/<COOKBOOK_NAME>/versions/<VERSION>

The Infra Client interpreter follows these steps when downloading content:

  • Create a directory to download cookbooks.
  • Download from Supermarket or from Chef Infra Server and extract the cookbook inside the directory.
  • Resolve all direct and transitive dependencies.
  • Remove all tar/zip files.

The download command accepts the following arguments:

url
The URL to the public or a private Supermarket.

Default value: https://supermarket.chef.io/

Example:

"url": "https://supermarket.chef.io/"
cookbooks
A comma-separated list of cookbook names.

Default value: NA

Example:

"cookbooks": "git@12.0.0,nginx"
path
The path to the directory that content is downloaded to.

Default value: /tmp/courier/chef-interpreter/cookbooks

Example:

"path": "/Users/home/ubuntu/cookbooks"

Examples

Download a cookbook with a download path:

"command": {
  "exec":"download",
  "args": {
    "cookbooks": "git@12.0.0,nginx",
    "path": "/Users/home/ubuntu/cookbooks"
  }
}

Download a cookbook from the default download path:

"command": {
  "exec":"download",
  "args": {
    "cookbooks": "git@12.0.0,nginx"
  }
}

execute

The execute command combines the features of download and run to execute a cookbook that may or may not be present on the node. This is a higher level command that allows user to run any cookbook from a Supermarket site.

execute uses the default cookbook path to temporarily cache cookbooks.

execute accepts the following arguments:

url
Supermarket site URL

Default value: https://supermarket.chef.io/

Example:

"url": "https://supermarket.chef.io/"
runlist
A comma-separated list of cookbook names in the format: <cookbook name>@<version>::<recipe name>.

If a cookbook appears twice in the runlist, both items are run in the order they appear in the runlist.

Default value: NA

Example:

"runlist": "cookbook::recipe"
"runlist": "cookbook@1.0"
"runlist": "cookbook@1.1::recipe"
mode
Can be set to local or remote.

Default value: remote

Example:

"mode": "local"

Examples

The Infra Client interpreter executes a run with the node’s available configuration defined in the client.rb file:

{
  "exec":"execute",
  "args": {}
}

The Infra Client interpreter downloads the latest versions of the Git and nginx, then downloads cookbooks and their dependencies from Chef Supermarket, and saves them it in the default cookbook directory. Once all cookbooks are resolved without any errors, it attempts to execute the run-list in local mode.

{
  "exec":"execute",
  "args": {
    "mode": "local",
    "runlist": "git::default,nginx@14.0"
  }
}

The Infra Client interpreter executes the provided run-list:

{
  "exec":"execute",
  "args": {
    "runlist": "git::default,nginx"
  }
}

rotate credentials

The rotate credentials command checks the current PEM key for validity. If the key is valid, the Infra Client interpreter replaces the existing PEM key with a new one.

It accepts the following arguments:

config
Path to infra credentials file.

Example:

"config": "/Users/home/ubuntu/.chef/credentials"

Default value: It checks the current working directory and home directory for a credentials file.

Examples

This rotates credentials found in /Users/home/ubuntu/.chef/credentials:

"command": {
    "exec":"rotate credentials",
    "args":{
      "config": "/Users/home/ubuntu/.chef/credentials"
    }
  }

run

The run command executes Chef Infra Client runs on a node as a part of the Courier job.

run accepts the following arguments:

runlist
Comma separated list of cookbook names.

Default value: NA

Example:

"runlist": "<cookbook>::<recipe>"
path
The path to the cookbook directory.

Default value: /tmp/courier/chef-interpreter/cookbooks

Example:

"path": "/Users/home/ubuntu/"
mode
The mode to run the Infra Client interpreter in.

Allowed values: local or remote.

Default value: remote

Example:

"mode": "local"

Examples

Execute a Chef Infra Client run with the node’s available configuration in the client.rb file.

{
  "exec":"run",
  "args": {
    "runlist": "git::default,nginx"
  }
}

Execute a run-list in local mode if the cookbooks are available under the default path. This exits with a failure if a cookbook isn’t available.

{
  "exec":"run",
  "args": {
    "mode": "local",
    "runlist": "git::default,nginx"
  }
}

Execute a run-list in local mode using cookbooks in /Users/home/ubuntu/:

{
  "exec":"run",
  "args": {
    "mode": "local",
    "runlist": "git::default,nginx",
    "path": "/Users/home/ubuntu/"
  }
}

Thank you for your feedback!

×