I am using an encrypted data bag to encrypt an ssh key and decrypted it via Chef. The data bag had an id of pwind_ssh_rsa_pub_cred, but what I really want is the unencrypted data for the ssh key. I want to then take the key and append it to a file, but the code that I have currently is running into some issues. With static values, the below code works. Additionally, I am a big confused as to what the type is of "decrypted_ssh".
ruby_block "obtainCredentials" do
block do
hadoop_key = Chef::EncryptedDataBagItem.load_secret("/home/ec2-user/project_data_bag_key")
decrypted_ssh = Chef::EncryptedDataBagItem.load("pwind_keys", "pwind_ssh_rsa_pub_credentials", hadoop_key)
Chef::Resource::RubyBlock.send(:include, Chef::Mixin::ShellOut)
command = "su - 'root' -c 'cd /home/ec2-user; cd .ssh; echo #{decrypted_ssh} >> .authorized_keys'"
shell(command)
end
end
What modifications should be done to get this ssh key decrypted and out of the encrypted data bag? Any suggestions would be much appreciated!
You need to select an element from the decrypted databag item.
Complete example:
Create key and databag item:
Content:
Verify:
cookbooks/test/recipes/test.rb
Execute recipe