Skip to main content

Chef Infra Client Interpreter

Chef Courier provides first-class integration with Chef Infra Client, so if you have the Chef Infra Client skill installed on a node or an existing Chef Infra Client installation is available as an executable, you can define and execute Chef Infra Client runs in a Courier job.

Use the run command in a job definition to execute an Infra Client run:

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

run accepts the following arguments:

  • rotate credentials
  • download
  • run
  • execute

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"
    }
  }

download content

The download content command downloads Cookbooks from public or private Supermarkets using the Chef Supermarket API. You can use the following Supermarket API endpoints with the download content 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 content 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"
  }
}

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 client.rb

{
  "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/"
  }
}

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 in client.rb:

{
  "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"
  }
}

Thank you for your feedback!

×