Skip to content

Instantly share code, notes, and snippets.

Last active Dec 14, 2015
What would you like to do?
chef -- create an ssh key and store it in the attributes
# 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, 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.
sshfile = "/home/runtime/id_rsa"
sshcomment = [
make_key = execute "ssh key for runtime" do
user "runtime"
creates sshfile
command "ssh-keygen -t rsa -q -f #{sshfile} -P '' -C #{sshcomment}"
node.set[:site][:sshdeploykeys][:runtime] =
# 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 '----'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment