-
-
Save nohupped/caa45c252e5cceab37e32502e2a3d3ff to your computer and use it in GitHub Desktop.
Create a template within a ruby block
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
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment