Skip to content

agileseason/chef-postgresql

 
 

Repository files navigation

chef-postgresql

Circle CI

Description

Install and configure PostgreSQL using the PostgreSQL Apt Repository.

Currently supported versions:

  • 9.6

Requirements

Supported Platforms

The following platforms are supported by this cookbook, meaning that the recipes run on these platforms without error:

  • Ubuntu 16.04

Chef

This cookbook requires Chef >= 12.9 due to the use of the built in apt_repository resource.

Dependencies

Recipes

  • postgresql - Set up the apt repository and install dependent packages
  • postgresql::client - Client programs for PostgreSQL 9.x
  • postgresql::configuration - Internal recipe to manage configuration files
  • postgresql::data_directory - Internal recipe to setup the data directory
  • postgresql::postgis - Geographic objects support for PostgreSQL 9.x
  • postgresql::server - Object-relational SQL database, version 9.x server
  • postgresql::service - Internal recipe to declare the system service
  • postgresql::setup_databases - Internal recipe to manage specified databases
  • postgresql::setup_extensions - Internal recipe to manage specified database extensions
  • postgresql::setup_users - Internal recipe to manage specified users

LWRP

Users

# create a user
postgresql_user "myuser" do
  superuser false
  createdb false
  login true
  replication false
  password "mypassword"
end

# create a user with an MD5-encrypted password
postgresql_user "myuser" do
  superuser false
  createdb false
  login true
  replication false
  encrypted_password "667ff118ef6d196c96313aeaee7da519"
end

# drop a user
postgresql_user "myuser" do
  action :drop
end

Or add users via attributes:

"postgresql": {
  "users": [
    {
      "username": "dickeyxxx",
      "password": "password",
      "superuser": true,
      "replication": false,
      "createdb": true,
      "createrole": false,
      "inherit": true,
      "replication": false,
      "login": true
    }
  ]
}

Databases and Extensions

# create a database
postgresql_database "mydb" do
  owner "myuser"
  encoding "UTF-8"
  template "template0"
  locale "en_US.UTF-8"
end

# install extensions to database
postgresql_extension "hstore" do
  database "mydb"
end

# drop dblink extension
postgresql_extension "dblink" do
  database "mydb"
  action :drop
end

# drop a database
postgresql_database "mydb" do
  action :drop
end

Or add the database via attributes:

"postgresql": {
  "databases": [
    {
      "name": "my_db",
      "owner": "dickeyxxx",
      "template": "template0",
      "encoding": "UTF-8",
      "locale": "en_US.UTF-8",
      "extensions": ["hstore", "dblink"],
      "postgis": true
    }
  ]
}

Configuration

"postgresql": {
  "conf": {
    "data_directory": "/dev/null",
    // ... all options explicitly set here
  }
}

You may also set the contents of pg_hba.conf via attributes:

"postgresql": {
  "pg_hba": [
    { "type": "local", "db": "all", "user": "postgres",   "addr": "",             "method": "ident" },
    { "type": "local", "db": "all", "user": "all",        "addr": "",             "method": "trust" },
    { "type": "host",  "db": "all", "user": "all",        "addr": "127.0.0.1/32", "method": "trust" },
    { "type": "host",  "db": "all", "user": "all",        "addr": "::1/128",      "method": "trust" },
    { "type": "host",  "db": "all", "user": "postgres",   "addr": "127.0.0.1/32", "method": "trust" },
    { "type": "host",  "db": "all", "user": "username",   "addr": "127.0.0.1/32", "method": "trust" }
  ]
}

Attributes

Too many to list so refer to attributes.rb

License

Refer to LICENSE

About

Chef cookbook for PostgreSQL components

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby 76.7%
  • HTML 23.3%