Skip to content

Instantly share code, notes, and snippets.

@razor-x
Last active February 25, 2016 18:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save razor-x/c02038e1bc78b89ee646 to your computer and use it in GitHub Desktop.
Save razor-x/c02038e1bc78b89ee646 to your computer and use it in GitHub Desktop.
Portable .chef/knife.rb for Chef projects.
#
# Local Environment
#
home_dir = Dir.home
chef_dir = File.join(home_dir, '.chef')
secret_dir = File.join(chef_dir, 'private')
organization = ENV['chef_org'] || 'the_organization_name'
knife_override = File.join(chef_dir, 'knife_override.rb')
username = (ENV['USER'] || ENV['USERNAME']).downcase
# DigitalOcean credentials file.
digitalocean_config =
File.join(secret_dir, "#{organization}.digitalocean.yml")
#
# Knife Configuration
#
chef_repo_path File.join File.dirname(__FILE__), '../'
chef_server_url "https://api.opscode.com/organizations/#{organization}"
chef_server_api chef_server_url
chef_organization organization
node_name username
client_key File.join(secret_dir, "#{organization}.#{username}.pem")
validation_key File.join(secret_dir, "#{organization}-validator.pem")
validation_client_name "#{organization}-validator"
syntax_check_cache_path File.join(chef_dir, 'syntax_check_cache')
private_key_paths [File.join(chef_dir, 'keys')]
data_bag_secret 'encrypted_data_bag_secret'
data_bag_secret_key File.join(secret_dir, "#{organization}.#{data_bag_secret}_key")
# Import DigitalOcean API credentials.
if File.exist? digitalocean_config
driver_options compute_options: YAML.load_file(digitalocean_config)
end
# Allow overriding values in this knife.rb from knife_override.rb.
Chef::Config.from_file knife_override if File.exist? knife_override
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment