Created
August 20, 2012 23:27
-
-
Save ctgswallow/3409231 to your computer and use it in GitHub Desktop.
Create a template within a ruby block
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
ruby_block "create ssh key" do | |
block do | |
k = SSHKey.generate(:type => 'RSA', :bits => 1024, :comment => "Postgres Master") | |
node.set[:postgresql][:pubkey] = k.ssh_public_key | |
node.save | |
# Much of the DSL disappears in ruby blocks. Here's how to create a template. | |
rc = Chef::RunContext.new(node, node.cookbook_collection) | |
t = Chef::Resource::Template.new "/var/lib/postgresql/.ssh/id_rsa" | |
t.source("id_rsa.erb") | |
t.owner("postgres") | |
t.group("postgres") | |
t.cookbook("postgresql") | |
t.mode("0600") | |
t.variables( | |
:k => k.private_key | |
) | |
t.action(:create_if_missing) | |
t.run_context=(rc) | |
t.run_action("create") | |
end | |
not_if { File.exists?("/var/lib/postgresql/.ssh/id_rsa") } | |
end |
This should not be used, it is not safe and breaks the Chef API.
@coderanger what should not be used exactly? Chef::Resource::RemoteFile
? Or Chef::Resource::Template.new
inside block
? Pls be specific.
At the same time. If you are hinting not to use this approach. Please suggest an alternative
Simply stating This should not be used, it is not safe and breaks the Chef API.
is good information. But it doesn't really help the OP and future observers
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@mansona in my example, I instantiate the
Resource
instead of theProvider
:Chef::Resource::RemoteFile