Skip to content

Instantly share code, notes, and snippets.

@razor-x

razor-x/knife.rb

Last active Feb 25, 2016
Embed
What would you like to do?
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