Created
April 21, 2018 02:50
-
-
Save rayterrill/90f066dd0cb732cdcee646578b47e83d to your computer and use it in GitHub Desktop.
Calling hashicorp vault from Chef
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
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