Created
May 30, 2018 20:16
-
-
Save mivok/a5a0f8618aa7a7dbcf1d79fcdbffafcd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Save this as ~/.chef/newcreds.rb | |
# Add require_relative 'newcreds' to your ~/.chef/knife.rb | |
require 'tomlrb' | |
require 'pathname' | |
context_file = "#{Dir.home}/.chef/context" | |
credentials_file = "#{Dir.home}/.chef/credentials" | |
context = File.read(context_file).chomp if File.exist?(context_file) | |
profile_name = ENV["CHEF_PROFILE"] || context || "default" | |
conf = Tomlrb.load_file(credentials_file) if File.exist?(credentials_file) | |
conf ||= {} | |
profile = conf[profile_name] || {} | |
# Make relative pathnames relative to ~/.chef | |
unless Pathname.new(profile['client_key']).absolute? | |
profile['client_key'] = File.expand_path("~/.chef/" + profile['client_key']) | |
end | |
%w(client_name client_key validator_key chef_server_url node_name).each do |k| | |
ChefConfig::Config.send(k, profile[k]) if profile[k] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment