Last active
December 14, 2015 19:09
-
-
Save directionless/5134452 to your computer and use it in GitHub Desktop.
chef -- create an ssh key and store it in the attributes
This file contains 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
# Create the ssh access key | |
# | |
# Something in the node.set lines happens at the *start* of the chef | |
# run. It might be the node.set, or it might be the File.read, but | |
# either way, it happens before the resource execution. To compensate | |
# for this, we need to shift the ssh key creation to the start of the | |
# run. http://docs.opscode.com/resource_common_compile.html | |
sshfile = "/home/runtime/id_rsa" | |
sshcomment = [ | |
node[:fqdn], | |
"chef-generated", | |
Time.now.strftime("%Y%m%d"), | |
].join("-") | |
make_key = execute "ssh key for runtime" do | |
user "runtime" | |
creates sshfile | |
command "ssh-keygen -t rsa -q -f #{sshfile} -P '' -C #{sshcomment}" | |
end | |
make_key.run_action(:run) | |
node.set[:site][:sshdeploykeys][:runtime] = ::File.read(sshfile) | |
node.save |
This file contains 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
# You can retrieve those files for various templates and future use via: | |
search(:node, 'site_sshdeploykeys:*').each do |n| | |
n[:site][:sshdeploykeys].each do |user, sshkey| | |
puts user | |
puts sshkey | |
puts '----' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment