Skip to content

Instantly share code, notes, and snippets.

@gregsymons
Created October 16, 2012 17:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gregsymons/3900805 to your computer and use it in GitHub Desktop.
Save gregsymons/3900805 to your computer and use it in GitHub Desktop.
Creating a postgis template database in chef
[Mon, 15 Oct 2012 22:45:22 +0000] DEBUG: Processing execute[create-postgis-template-db] on vagrant.vm
[Mon, 15 Oct 2012 22:45:22 +0000] INFO: Processing execute[create-postgis-template-db] action run (postgis::server line 25)
[Mon, 15 Oct 2012 22:45:22 +0000] DEBUG: Skipping execute[create-postgis-template-db] due to not_if command ` PGPASSWORD=R3n41rAfFMQzoOghaAYV psql -d postgis -U postgres >/dev/null 2&>1
`
POSTGRES_CREDS = {
'PGPASSWORD' => Chef::Config[:solo] ?
File.read('/etc/postgresql/9.1/main/.org_grok').strip
: node[:postgresql][:password],
'PGUSER' => 'postgres',
}
#ideally, this would be done using the database cookbook. Unfortunately, that's
#broken on an omnibus install. Which of course, is what we use.
execute 'create-postgis-template-db' do
environment POSTGRES_CREDS
command <<-EOC
createdb postgis
createlang plpgsql postgis
psql -d postgis -f /usr/share/postgresql-9.1/contrib/postgis-1.5/postgis.sql
psql -d postgis -f /usr/share/postgresql-9.1/contrib/postgis-1.5/spatial_ref_sys.sql
EOC
not_if <<-EOC
PGPASSWORD=#{node[:postgresql][:password]} psql -d postgis -U postgres >/dev/null 2&>1
EOC
end
vagrant@vagrant:~$ PGPASSWORD=R3n41rAfFMQzoOghaAYV psql -d postgis -U postgres >/dev/null 2&>1 && echo yes || echo no
no
vagrant@vagrant:~$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment