Skip to content
This repository was archived by the owner on Mar 25, 2018. It is now read-only.

Quick Start

dols edited this page Aug 11, 2012 · 6 revisions

Note that Chef support is not complete

  1. Setup a Chef Server or Register for Opscode Hosted Chef
    1. Register for the Opscode Hosted Chef
    2. confirm your email entitled Please validate your Opscode user account
  2. Create an api client and save the private key
    • On Opscode Hosted Chef
      1. create client
      2. save the private key to ~/.chef/CLIENT_NAME.pem
  3. Ensure you are using a recent JDK 6
  4. clone and build jclouds chef locally
  5. Setup your project to include jclouds-chef

ant (1.7.1+)

Setup your ant build.xml to obtain a classpath ref to jclouds-chef

<project name="your_project" default="your_target" basedir="." xmlns:artifact="antlib:org.apache.maven.artifact.ant">
  <artifact:dependencies pathId="jclouds-chef.classpath">
    <dependency groupId="org.jclouds" artifactId="jclouds-chef" version="1.0-SNAPSHOT" />
  </artifact:dependencies>

maven (2.2.1+)

Setup your Maven pom to include jclouds-chef

  <dependencies>
    <dependency>
       <groupId>org.jclouds.api</groupId>
       <artifactId>chef</artifactId>
       <version>1.5.0-beta.9</version>
    </dependency>
   </dependencies>

lein (1.2.0 +)

Setup your project.clj jclouds-chef

  :dependencies [[org.clojure/clojure "1.2.0"]
                 [org.clojure/clojure-contrib "1.2.0"]
     [org.jclouds/jclouds-chef "1.0-SNAPSHOT"]]
  1. Start coding

Java

String client = "CLIENT_NAME";
String pemFile = System.getProperty("user.home") + "/.chef/" + client + ".pem";
String credential = Files.toString(new File(keyfile), Charsets.UTF_8);

// specify the chef server you want, or opscode hosted chef
Properties overrides = new Properties();
// default is localhost:4000
overrides.setProperty("chef.endpoint", "https://api.opscode.com/organizations/YOUR_ORG");

// create a context where you can access the chef client, asyncClient, and service features
ChefContext context = new ChefContextFactory().createContext(client, credential, 
                                            ImmutableSet.<Module> of(), overrides);

// The raw api has access to all chef features as exposed in the Chef REST api
Set<String> databags = context.getApi().listDatabags();

// ChefService has helpers for common commands
context.getChefService().createNodeAndPopulateAutomaticAttributes(nodeName, ImmutableSet.of("role[prod]"));

// release resources
context.close();

Clojure

(ns chef.example
  (:use org.jclouds.chef))

(def client "CLIENT_NAME")
;; load the rsa key from ~/.chef/CLIENT_NAME.pem
(def credential (load-pem client))

;; define a chef service you can use directly or within the with-chef-service closure
;; note that the default :chef.endpoint is localhost:8000
(def chef (chef-service "chef" client credential :chef.endpoint "https://api.opscode.com/organizations/YOUR_ORG"))

(with-chef-service [chef]
  (create-databag "cluster-config")  
  (update-databag-item "cluster-config" {:id "master" :name "myhost.com"})) 

;; note that you can create your chef connection like this to do in-memory testing
(def chef (chef-service "transientchef" "" ""))
;; note you can also pass in chef.endpoint as a system property if you are using only one chef org/server
  1. Validate on the Console
Clone this wiki locally