Skip to content

Instantly share code, notes, and snippets.

@rayterrill
Created April 21, 2018 02:50
Show Gist options
  • Save rayterrill/90f066dd0cb732cdcee646578b47e83d to your computer and use it in GitHub Desktop.
Save rayterrill/90f066dd0cb732cdcee646578b47e83d to your computer and use it in GitHub Desktop.
Calling hashicorp vault from Chef
remote_file '/tmp/database.json' do
backup false
source 'https://vault.hashicorp.rocks/v1/postgresql/creds/readonly'
headers({
'X-Vault-Token' => ENV['VAULT_TOKEN'],
})
mode '0644'
action :create
notifies :create, 'ruby_block[write_config]', :immediately
not_if { File.exist?('/tmp/database.json') }
end
ruby_block 'write_config' do
block do
data = JSON.parse(File.read('/tmp/database.json'))["data"]
f = "---\npostgresql:\n username: #{data["username"]}\n password: #{data["password"]}"
File.write("/tmp/database.yml", f)
end
action :nothing
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment