Skip to content

Instantly share code, notes, and snippets.

@zzondlo
Forked from fnichol/knife.rb
Created February 23, 2012 03:07
Show Gist options
  • Select an option

  • Save zzondlo/1889718 to your computer and use it in GitHub Desktop.

Select an option

Save zzondlo/1889718 to your computer and use it in GitHub Desktop.

Revisions

  1. @fnichol fnichol revised this gist Sep 18, 2011. 1 changed file with 43 additions and 15 deletions.
    58 changes: 43 additions & 15 deletions knife.rb
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,32 @@
    ### Chef Solo
    #
    #
    ### Opscode Hosted Chef Server
    #
    # export KNIFE_USER="jdoe"
    # export KNIFE_ORGNAME="acmeco"
    #
    # * Your Opscode client key should be at `~/.chef.d/opscode-jdoe.pem`.
    # * Your Opscode validation key should be at `~/.chef.d/opscode-acmeco-validator.pem`.
    #
    ### Chef Server
    #
    # export KNIFE_USER="hsolo"
    # export KNIFE_SERVER_NAME="widgetinc"
    # export KNIFE_SERVER_URL="https://chef.widgetinc.com"
    #
    # * Your Chef Server client key should be at `~/.chef.d/widgetinc-hsolo.pem`.
    # * Your Chef Server validation key should be at `~/.chef.d/widgetinc-validator.pem`.
    #

    current_dir = File.dirname(__FILE__)
    home_dir = ENV['HOME']
    chef_dir = "#{home_dir}/.chef.d"

    user = ENV['KNIFE_USER'] || ENV['USER']
    orgname = ENV['KNIFE_ORGNAME']
    server_url = ENV['KNIFE_CHEF_SERVER']
    chef_dir = "#{home_dir}/.chef.d"
    key = "#{chef_dir}/#{user}.pem"
    val_key = "#{chef_dir}/#{orgname}-validator.pem"
    server_name = ENV['KNIFE_SERVER_NAME']
    server_url = ENV['KNIFE_SERVER_URL']

    # path to cookbooks
    cookbook_path ["#{current_dir}/../cookbooks"]
    @@ -14,24 +35,31 @@
    log_level :info
    log_location STDOUT

    # user/client and private key to authenticate to a chef server, if needed
    # user/client and private key to authenticate to a Chef Server, if needed
    node_name user
    client_key key if File.exists?(key)

    # if an orgname is given, then we want to talk to Opscode Hosted Chef Server
    if orgname
    validation_client_name "opscode-#{orgname}-validator"
    validation_key val_key if File.exists?(val_key)
    # if KNIFE_ORGNAME is given, then we're talking to the Opscode Hosted Chef
    # Server
    validation_client_name "#{orgname}-validator"
    client_key "#{chef_dir}/opscode-#{user}.pem"
    validation_key "#{chef_dir}/opscode-#{orgname}-validator.pem"
    chef_server_url "https://api.opscode.com/organizations/#{orgname}"
    elsif server_name
    # if KNIFE_SERVER_NAME is defined, then we're talking to a Chef Server
    validation_client_name "#{server_name}-validator"
    client_key "#{chef_dir}/#{server_name}-#{user}.pem"
    validation_key "#{chef_dir}/#{server_name}-validator.pem"
    chef_server_url server_url
    end

    # caching options
    cache_type 'BasicFile'
    cache_options( :path => "#{home_dir}/.chef/checksums" )
    cache_options( :path => "#{home_dir}/.chef/checksums" )

    # new cookbook defaults
    cookbook_copyright ENV['KNIFE_COOKBOOK_COPYRIGHT'] ||
    %x{git config --get user.name}.chomp
    cookbook_email ENV['KNIFE_COOKBOOK_EMAIL'] ||
    %x{git config --get user.email}.chomp
    cookbook_license "apachev2"
    cookbook_copyright ENV['KNIFE_COOKBOOK_COPYRIGHT'] ||
    %x{git config --get user.name}.chomp
    cookbook_email ENV['KNIFE_COOKBOOK_EMAIL'] ||
    %x{git config --get user.email}.chomp
    cookbook_license "apachev2"
  2. @fnichol fnichol revised this gist Sep 17, 2011. 1 changed file with 13 additions and 10 deletions.
    23 changes: 13 additions & 10 deletions knife.rb
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,11 @@
    current_dir = File.dirname(__FILE__)
    home_dir = ENV['HOME']
    user = ENV['OPSCODE_USER'] || ENV['USER']
    orgname = ENV['ORGNAME']
    server_url = ENV['CHEF_SERVER'] || "https://api.opscode.com/organizations/#{orgname}"
    key = "#{home_dir}/.chef.d/#{user}.pem"
    val_key = "#{home_dir}/.chef.d/#{orgname}-validator.pem"
    user = ENV['KNIFE_USER'] || ENV['USER']
    orgname = ENV['KNIFE_ORGNAME']
    server_url = ENV['KNIFE_CHEF_SERVER']
    chef_dir = "#{home_dir}/.chef.d"
    key = "#{chef_dir}/#{user}.pem"
    val_key = "#{chef_dir}/#{orgname}-validator.pem"

    # path to cookbooks
    cookbook_path ["#{current_dir}/../cookbooks"]
    @@ -17,18 +18,20 @@
    node_name user
    client_key key if File.exists?(key)

    # if an orgname is given, then we want to talk to a chef server
    # if an orgname is given, then we want to talk to Opscode Hosted Chef Server
    if orgname
    validation_client_name "#{orgname}-validator"
    validation_client_name "opscode-#{orgname}-validator"
    validation_key val_key if File.exists?(val_key)
    chef_server_url chef_server
    chef_server_url "https://api.opscode.com/organizations/#{orgname}"
    end

    # caching options
    cache_type 'BasicFile'
    cache_options( :path => "#{home_dir}/.chef/checksums" )

    # new cookbook defaults
    cookbook_copyright ENV['COOKBOOK_COPYRIGHT'] || %x{git config --get user.name}.chomp
    cookbook_email ENV['COOKBOOK_EMAIL'] || %x{git config --get user.email}.chomp
    cookbook_copyright ENV['KNIFE_COOKBOOK_COPYRIGHT'] ||
    %x{git config --get user.name}.chomp
    cookbook_email ENV['KNIFE_COOKBOOK_EMAIL'] ||
    %x{git config --get user.email}.chomp
    cookbook_license "apachev2"
  3. @fnichol fnichol created this gist Sep 17, 2011.
    34 changes: 34 additions & 0 deletions knife.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    current_dir = File.dirname(__FILE__)
    home_dir = ENV['HOME']
    user = ENV['OPSCODE_USER'] || ENV['USER']
    orgname = ENV['ORGNAME']
    server_url = ENV['CHEF_SERVER'] || "https://api.opscode.com/organizations/#{orgname}"
    key = "#{home_dir}/.chef.d/#{user}.pem"
    val_key = "#{home_dir}/.chef.d/#{orgname}-validator.pem"

    # path to cookbooks
    cookbook_path ["#{current_dir}/../cookbooks"]

    # logging details
    log_level :info
    log_location STDOUT

    # user/client and private key to authenticate to a chef server, if needed
    node_name user
    client_key key if File.exists?(key)

    # if an orgname is given, then we want to talk to a chef server
    if orgname
    validation_client_name "#{orgname}-validator"
    validation_key val_key if File.exists?(val_key)
    chef_server_url chef_server
    end

    # caching options
    cache_type 'BasicFile'
    cache_options( :path => "#{home_dir}/.chef/checksums" )

    # new cookbook defaults
    cookbook_copyright ENV['COOKBOOK_COPYRIGHT'] || %x{git config --get user.name}.chomp
    cookbook_email ENV['COOKBOOK_EMAIL'] || %x{git config --get user.email}.chomp
    cookbook_license "apachev2"