Skip to content
Dan Ryan edited this page Jun 13, 2012 · 21 revisions

Spice has the following configuration attributes:

  • Spice.server_url - The URL of the Chef server. Remember to include the port if you are hosting your own Chef server. Default: http://localhost:4000
  • Spice.chef_version - The version of the Chef server. Setting this changes functionality, so make sure the numbers match (especially major versions). Default: 0.10.10
  • Spice.client_name - The client name to connect as. This client must be an admin. Default: ""
  • Spice.client_key - The client key (an OpenSSL::PKey::RSA object). Default: ""
  • Spice.user_agent - The user agent that Spice will use. Default: Spice #{Spice::VERSION}"
  • Spice.connection_options - A hash of options to provide to the Faraday HTTP connection. Default: {}

A convenience method, Spice.read_key_file, is provided for backwards compatibility with older versions of Spice that required a filesystem path for the client key, which reads the key file, validates it, and turns it into the RSA key format we need:

Spice.read_key_file("/path/to/key_file.pem") # => OpenSSL::PKey::RSA.new(key_file)

To connect to a Chef server at https://chef.example.com:5000 with the "admin" API client, throw this somewhere your app can initialize:

Spice.server_url  = "http://chef.example.com:5000"
Spice.client_name = "admin"
Spice.client_key  = Spice.read_key_file("/Users/me/.chef/admin.pem")

Say you had a Chef server v0.10.10 running locally on port 4000 over HTTP, you only need to set your client_name and client_key path:

Spice.client_name = "admin"
Spice.client_key  = Spice.read_key_file("/Users/me/.chef/admin.pem")

You can also use the Spice.setup block if you prefer this style:

Spice.setup do |s|
  s.server_url   = "http://chef.example.com:4000"
  s.client_name  = "admin"
  s.client_key   = Spice.read_key_file("/Users/me/.chef/admin.pem")
  s.chef_version = "0.9.18"
end

If you want to reset your config to their default values:

Spice.reset

Lastly, if you need to manage multiple connections you can configure a Spice::Connection object with its own attributes. Any attributes not specified will inherit from the default global attributes.

@production = Spice::Connection.new(
  :server_url => "http://chef.production.example.com:4000",
  :client_name => "admin",
  :client_key => "-----BEGIN RSA PRIVATE KEY-----\n-----END RSA PRIVATE KEY-----",
  :chef_version => "0.10.10",
  :user_agent => "THE SPICE MUST FLOW"
)

@staging = Spice::Connection.new(
  :server_url => "http://chef.staging.example.com:4000",
  :client_name => "admin",
  :client_key => "-----BEGIN RSA PRIVATE KEY-----\n-----END RSA PRIVATE KEY-----",
  :chef_version => "0.10.10",
  :user_agent => "THE SPICE MUST FLOW"
)
Clone this wiki locally