Git Product home page Git Product logo

chef-postgresql's Introduction

chef-postgresql

Flair

Cookbook Version License Build Status Gitter It Works On My Machine™ Tip Endorse

Description

Installs PostgreSQL, The world's most advanced open source database.

This installs postgres 9.x from the PostgreSQL Apt Repository.

Currently supported versions:

  • 9.0
  • 9.1
  • 9.2
  • 9.3
  • 9.4

The default version is 9.4.

Requirements

Supported Platforms

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

  • Debian 7.8
  • Ubuntu 12.04
  • Ubuntu 14.04

Chef

This cookbook requires Chef >= 11.13 due to the use of the sensitive attribute for some resources.

Cookbooks

Recipes

  • postgresql - Set up the apt repository and install dependent packages
  • postgresql::apt_repository - Internal recipe to setup the apt repository
  • postgresql::client - Front-end programs for PostgreSQL 9.x
  • postgresql::configuration - Internal recipe to manage configuration files
  • postgresql::contrib - Additional facilities for PostgreSQL
  • postgresql::data_directory - Internal recipe to setup the data directory
  • postgresql::dbg - Debug symbols for the server daemon
  • postgresql::debian_backports - Internal recipe to manage debian backports
  • postgresql::doc - Documentation for the PostgreSQL database management system
  • postgresql::libpq - PostgreSQL C client library and header files for libpq5 (PostgreSQL library)
  • postgresql::postgis - Geographic objects support for PostgreSQL 9.x (currently Ubuntu only)
  • postgresql::server - Object-relational SQL database, version 9.x server
  • postgresql::server_dev - Development files for PostgreSQL server-side programming
  • 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_languages - Internal recipe to manage specified database languages
  • postgresql::setup_users - Internal recipe to manage specified users

Usage

This cookbook installs the postgresql components if not present, and pulls updates if they are installed on the system.

This cookbook provides three definitions to create, alter, and delete users as well as create and drop databases, or setup extensions. Usage is as follows:

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

postgresql_language "plpgsql" 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

The postgresql.conf configuration may be set one of two ways:

  • set individual node attributes to be interpolated into the default template
  • create a custom configuration hash to write a custom file

To create a custom configuration, set the node["postgresql"]["conf"] hash with your custom settings:

"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" }
  ]
}

Change APT distribution

Currently the APT distributions are sourced from http://apt.postgresql.org/pub/repos/apt/. In some cases this source might not immediately contain a package for the distribution of your target system.

The node["postgresql"]["apt_distribution"] attribute can be used to install PostgreSQL from a different compatible distribution:

"postgresql": {
  "apt_distribution": "precise"
}

Attributes

# WARNING: If this version number is changed in your own recipes, the
# FILE LOCATIONS (see below) attributes *must* also be overridden in
# order to re-compute the paths with the correct version number.
default["postgresql"]["version"]                         = "9.4"

#----------------------------------------------------------------------------
# DAEMON CONTROL
#----------------------------------------------------------------------------
default["postgresql"]["service_actions"]                 = %w[enable start]

# control how the postgres service is signaled when configuration files are
# updated. by default the service is told to `:restart` (stop, start). if you
# run high availability installation and do not want the service to restart via
# chef you can change this to `:reload`. the caveat is that you will need to
# manually restart the postgres server if you change a setting that requires
# a full restart.
default["postgresql"]["cfg_update_action"]               = :restart

#----------------------------------------------------------------------------
# APT REPOSITORY
#----------------------------------------------------------------------------
default["postgresql"]["apt_distribution"]                = node["lsb"]["codename"]
default["postgresql"]["apt_repository"]                  = "apt.postgresql.org"
default["postgresql"]["apt_uri"]                         = "http://apt.postgresql.org/pub/repos/apt"
default["postgresql"]["apt_components"]                  = ["main"]
default["postgresql"]["apt_key"]                         = "https://www.postgresql.org/media/keys/ACCC4CF8.asc"
# You can set default["postgresql"]["apt_keyserver"] if you want to use a keyserver

default["postgresql"]["environment_variables"]           = {}
default["postgresql"]["pg_ctl_options"]                  = ""
default["postgresql"]["pg_hba"]                          = []
default["postgresql"]["pg_hba_defaults"]                 = true  # Whether to populate the pg_hba.conf with defaults
default["postgresql"]["pg_ident"]                        = []
default["postgresql"]["start"]                           = "auto"  # auto, manual, disabled

default["postgresql"]["conf"]                            = {}
default["postgresql"]["conf_custom"]                     = false  # if true, only use node["postgresql"]["conf"]
default["postgresql"]["initdb_options"]                  = "--locale=en_US.UTF-8"

#------------------------------------------------------------------------------
# FILE LOCATIONS
#------------------------------------------------------------------------------
default["postgresql"]["data_directory"]                  = "/var/lib/postgresql/#{node["postgresql"]["version"]}/main"
default["postgresql"]["hba_file"]                        = "/etc/postgresql/#{node["postgresql"]["version"]}/main/pg_hba.conf"
default["postgresql"]["ident_file"]                      = "/etc/postgresql/#{node["postgresql"]["version"]}/main/pg_ident.conf"
default["postgresql"]["external_pid_file"]               = "/var/run/postgresql/#{node["postgresql"]["version"]}-main.pid"


#------------------------------------------------------------------------------
# CONNECTIONS AND AUTHENTICATION
#------------------------------------------------------------------------------

# connection settings
default["postgresql"]["listen_addresses"]                = "localhost"
default["postgresql"]["port"]                            = 5432
default["postgresql"]["max_connections"]                 = 100
default["postgresql"]["superuser_reserved_connections"]  = 3
default["postgresql"]["unix_socket_group"]               = ""
default["postgresql"]["unix_socket_permissions"]         = "0777"
default["postgresql"]["bonjour"]                         = "off"
default["postgresql"]["bonjour_name"]                    = ""

if Gem::Version.new(node["postgresql"]["version"]) >= Gem::Version.new("9.3")
  default["postgresql"]["unix_socket_directories"]       = "/var/run/postgresql"
else
  default["postgresql"]["unix_socket_directory"]         = "/var/run/postgresql"
end

# security and authentication
default["postgresql"]["authentication_timeout"]          = "1min"
default["postgresql"]["ssl"]                             = true
default["postgresql"]["ssl_ciphers"]                     = "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH"
default["postgresql"]["ssl_renegotiation_limit"]         = "512MB"
default["postgresql"]["ssl_ca_file"]                     = ""
default["postgresql"]["ssl_cert_file"]                   = "/etc/ssl/certs/ssl-cert-snakeoil.pem"
default["postgresql"]["ssl_crl_file"]                    = ""
default["postgresql"]["ssl_key_file"]                    = "/etc/ssl/private/ssl-cert-snakeoil.key"
default["postgresql"]["password_encryption"]             = "on"
default["postgresql"]["db_user_namespace"]               = "off"

# kerberos and gssapi
default["postgresql"]["db_user_namespace"]               = "off"
default["postgresql"]["krb_server_keyfile"]              = ""
default["postgresql"]["krb_srvname"]                     = "postgres"
default["postgresql"]["krb_caseins_users"]               = "off"

# tcp keepalives
default["postgresql"]["tcp_keepalives_idle"]             = 0
default["postgresql"]["tcp_keepalives_interval"]         = 0
default["postgresql"]["tcp_keepalives_count"]            = 0


#------------------------------------------------------------------------------
# RESOURCE USAGE (except WAL)
#------------------------------------------------------------------------------

# memory
default["postgresql"]["shared_buffers"]                  = "24MB"
default["postgresql"]["temp_buffers"]                    = "8MB"
default["postgresql"]["max_prepared_transactions"]       = 0
default["postgresql"]["work_mem"]                        = "1MB"
default["postgresql"]["maintenance_work_mem"]            = "16MB"
default["postgresql"]["max_stack_depth"]                 = "2MB"

# kernel resource usage
default["postgresql"]["max_files_per_process"]           = 1000
default["postgresql"]["shared_preload_libraries"]        = ""

# cost-based vacuum delay
default["postgresql"]["vacuum_cost_delay"]               = "0ms"
default["postgresql"]["vacuum_cost_page_hit"]            = 1
default["postgresql"]["vacuum_cost_page_miss"]           = 10
default["postgresql"]["vacuum_cost_page_dirty"]          = 20
default["postgresql"]["vacuum_cost_limit"]               = 200

# background writer
default["postgresql"]["bgwriter_delay"]                  = "200ms"
default["postgresql"]["bgwriter_lru_maxpages"]           = 100
default["postgresql"]["bgwriter_lru_multiplier"]         = 2.0

# asynchronous behavior
default["postgresql"]["effective_io_concurrency"]        = 1


#------------------------------------------------------------------------------
# WRITE AHEAD LOG
#------------------------------------------------------------------------------

# settings
default["postgresql"]["wal_level"]                       = "minimal"
default["postgresql"]["fsync"]                           = "on"
default["postgresql"]["synchronous_commit"]              = "on"
default["postgresql"]["wal_sync_method"]                 = "fsync"
default["postgresql"]["full_page_writes"]                = "on"
default["postgresql"]["wal_buffers"]                     = -1
default["postgresql"]["wal_writer_delay"]                = "200ms"
default["postgresql"]["commit_delay"]                    = 0
default["postgresql"]["commit_siblings"]                 = 5

# checkpoints
default["postgresql"]["checkpoint_segments"]             = 3
default["postgresql"]["checkpoint_timeout"]              = "5min"
default["postgresql"]["checkpoint_completion_target"]    = 0.5
default["postgresql"]["checkpoint_warning"]              = "30s"

# archiving
default["postgresql"]["archive_mode"]                    = "off"
default["postgresql"]["archive_command"]                 = ""
default["postgresql"]["archive_timeout"]                 = 0


#------------------------------------------------------------------------------
# REPLICATION
#------------------------------------------------------------------------------

# master server
default["postgresql"]["max_wal_senders"]                 = 0
default["postgresql"]["wal_sender_delay"]                = "1s"
default["postgresql"]["wal_keep_segments"]               = 0
default["postgresql"]["vacuum_defer_cleanup_age"]        = 0
default["postgresql"]["replication_timeout"]             = "60s"
default["postgresql"]["synchronous_standby_names"]       = ""

# standby servers
default["postgresql"]["hot_standby"]                     = "off"
default["postgresql"]["max_standby_archive_delay"]       = "30s"
default["postgresql"]["max_standby_streaming_delay"]     = "30s"
default["postgresql"]["wal_receiver_status_interval"]    = "10s"
default["postgresql"]["hot_standby_feedback"]            = "off"


#------------------------------------------------------------------------------
# QUERY TUNING
#------------------------------------------------------------------------------

# planner method configuration
default["postgresql"]["enable_bitmapscan"]               = "on"
default["postgresql"]["enable_hashagg"]                  = "on"
default["postgresql"]["enable_hashjoin"]                 = "on"
default["postgresql"]["enable_indexscan"]                = "on"
default["postgresql"]["enable_material"]                 = "on"
default["postgresql"]["enable_mergejoin"]                = "on"
default["postgresql"]["enable_nestloop"]                 = "on"
default["postgresql"]["enable_seqscan"]                  = "on"
default["postgresql"]["enable_sort"]                     = "on"
default["postgresql"]["enable_tidscan"]                  = "on"

# planner cost constants
default["postgresql"]["seq_page_cost"]                   = 1.0
default["postgresql"]["random_page_cost"]                = 4.0
default["postgresql"]["cpu_tuple_cost"]                  = 0.01
default["postgresql"]["cpu_index_tuple_cost"]            = 0.005
default["postgresql"]["cpu_operator_cost"]               = 0.0025
default["postgresql"]["effective_cache_size"]            = "128MB"

# genetic query optimizer
default["postgresql"]["geqo"]                            = "on"
default["postgresql"]["geqo_threshold"]                  = 12
default["postgresql"]["geqo_effort"]                     = 5
default["postgresql"]["geqo_pool_size"]                  = 0
default["postgresql"]["geqo_generations"]                = 0
default["postgresql"]["geqo_selection_bias"]             = 2.0
default["postgresql"]["geqo_seed"]                       = 0.0

# other planner options
default["postgresql"]["default_statistics_target"]       = 100
default["postgresql"]["constraint_exclusion"]            = "partition"
default["postgresql"]["cursor_tuple_fraction"]           = 0.1
default["postgresql"]["from_collapse_limit"]             = 8
default["postgresql"]["join_collapse_limit"]             = 8


#------------------------------------------------------------------------------
# ERROR REPORTING AND LOGGING
#------------------------------------------------------------------------------

# where to log
default["postgresql"]["log_destination"]                 = "stderr"
default["postgresql"]["logging_collector"]               = "off"
default["postgresql"]["log_directory"]                   = "pg_log"
default["postgresql"]["log_filename"]                    = "postgresql-%Y-%m-%d_%H%M%S.log"
default["postgresql"]["log_file_mode"]                   = 0600
default["postgresql"]["log_truncate_on_rotation"]        = "off"
default["postgresql"]["log_rotation_age"]                = "1d"
default["postgresql"]["log_rotation_size"]               = "10MB"

# These are relevant when logging to syslog:
default["postgresql"]["syslog_facility"]                 = "LOCAL0"
default["postgresql"]["syslog_ident"]                    = "postgres"
default["postgresql"]["silent_mode"]                     = "off"

# when to log
default["postgresql"]["client_min_messages"]             = "notice"
default["postgresql"]["log_min_messages"]                = "warning"
default["postgresql"]["log_min_error_statement"]         = "error"
default["postgresql"]["log_min_duration_statement"]      = -1

# what to log
default["postgresql"]["debug_print_parse"]               = "off"
default["postgresql"]["debug_print_rewritten"]           = "off"
default["postgresql"]["debug_print_plan"]                = "off"
default["postgresql"]["debug_pretty_print"]              = "on"
default["postgresql"]["log_checkpoints"]                 = "off"
default["postgresql"]["log_connections"]                 = "off"
default["postgresql"]["log_disconnections"]              = "off"
default["postgresql"]["log_duration"]                    = "off"
default["postgresql"]["log_error_verbosity"]             = "default"
default["postgresql"]["log_hostname"]                    = "off"
default["postgresql"]["log_line_prefix"]                 = "%t "
default["postgresql"]["log_lock_waits"]                  = "off"
default["postgresql"]["log_statement"]                   = "none"
default["postgresql"]["log_temp_files"]                  = -1
default["postgresql"]["log_timezone"]                    = "(defaults to server environment setting)"


#------------------------------------------------------------------------------
# RUNTIME STATISTICS
#------------------------------------------------------------------------------

# query/index statistics collector
default["postgresql"]["track_activities"]                = "on"
default["postgresql"]["track_counts"]                    = "on"
default["postgresql"]["track_functions"]                 = "none"
default["postgresql"]["track_activity_query_size"]       = 1024
default["postgresql"]["update_process_title"]            = "on"
default["postgresql"]["stats_temp_directory"]            = 'pg_stat_tmp'

# statistics monitoring
default["postgresql"]["log_parser_stats"]                = "off"
default["postgresql"]["log_planner_stats"]               = "off"
default["postgresql"]["log_executor_stats"]              = "off"
default["postgresql"]["log_statement_stats"]             = "off"


#------------------------------------------------------------------------------
# AUTOVACUUM PARAMETERS
#------------------------------------------------------------------------------

default["postgresql"]["autovacuum"]                      = "on"
default["postgresql"]["log_autovacuum_min_duration"]     = -1
default["postgresql"]["autovacuum_max_workers"]          = 3
default["postgresql"]["autovacuum_naptime"]              = "1min"
default["postgresql"]["autovacuum_vacuum_threshold"]     = 50
default["postgresql"]["autovacuum_analyze_threshold"]    = 50
default["postgresql"]["autovacuum_vacuum_scale_factor"]  = 0.2
default["postgresql"]["autovacuum_analyze_scale_factor"] = 0.1
default["postgresql"]["autovacuum_freeze_max_age"]       = 200000000
default["postgresql"]["autovacuum_vacuum_cost_delay"]    = "20ms"
default["postgresql"]["autovacuum_vacuum_cost_limit"]    = -1


#------------------------------------------------------------------------------
# CLIENT CONNECTION DEFAULTS
#------------------------------------------------------------------------------

# statement behavior
default["postgresql"]["search_path"]                     = '"$user",public'
default["postgresql"]["default_tablespace"]              = ""
default["postgresql"]["temp_tablespaces"]                = ""
default["postgresql"]["check_function_bodies"]           = "on"
default["postgresql"]["default_transaction_isolation"]   = "read committed"
default["postgresql"]["default_transaction_read_only"]   = "off"
default["postgresql"]["default_transaction_deferrable"]  = "off"
default["postgresql"]["session_replication_role"]        = "origin"
default["postgresql"]["statement_timeout"]               = 0
default["postgresql"]["vacuum_freeze_min_age"]           = 50000000
default["postgresql"]["vacuum_freeze_table_age"]         = 150000000
default["postgresql"]["bytea_output"]                    = "hex"
default["postgresql"]["xmlbinary"]                       = "base64"
default["postgresql"]["xmloption"]                       = "content"

# locale and formatting
default["postgresql"]["datestyle"]                       = "iso, mdy"
default["postgresql"]["intervalstyle"]                   = "postgres"
default["postgresql"]["timezone"]                        = "(defaults to server environment setting)"
default["postgresql"]["timezone_abbreviations"]          = "Default"
default["postgresql"]["extra_float_digits"]              = 0
default["postgresql"]["client_encoding"]                 = "sql_ascii"

# These settings are initialized by initdb, but they can be changed.
default["postgresql"]["lc_messages"]                     = "en_US.UTF-8"
default["postgresql"]["lc_monetary"]                     = "en_US.UTF-8"
default["postgresql"]["lc_numeric"]                      = "en_US.UTF-8"
default["postgresql"]["lc_time"]                         = "en_US.UTF-8"

# default configuration for text search
default["postgresql"]["default_text_search_config"]      = "pg_catalog.english"

# other defaults
default["postgresql"]["dynamic_library_path"]            = "$libdir"
default["postgresql"]["local_preload_libraries"]         = ""


#------------------------------------------------------------------------------
# LOCK MANAGEMENT
#------------------------------------------------------------------------------

default["postgresql"]["deadlock_timeout"]                = "1s"
default["postgresql"]["max_locks_per_transaction"]       = 64
default["postgresql"]["max_pred_locks_per_transaction"]  = 64


#------------------------------------------------------------------------------
# VERSION/PLATFORM COMPATIBILITY
#------------------------------------------------------------------------------

# previous postgresql versions
default["postgresql"]["array_nulls"]                     = "on"
default["postgresql"]["backslash_quote"]                 = "safe_encoding"
default["postgresql"]["default_with_oids"]               = "off"
default["postgresql"]["escape_string_warning"]           = "on"
default["postgresql"]["lo_compat_privileges"]            = "off"
default["postgresql"]["quote_all_identifiers"]           = "off"
default["postgresql"]["sql_inheritance"]                 = "on"
default["postgresql"]["standard_conforming_strings"]     = "on"
default["postgresql"]["synchronize_seqscans"]            = "on"

# other platforms and clients
default["postgresql"]["transform_null_equals"]           = "off"


#------------------------------------------------------------------------------
# ERROR HANDLING
#------------------------------------------------------------------------------

default["postgresql"]["exit_on_error"]                   = "off"
default["postgresql"]["restart_after_crash"]             = "on"


#------------------------------------------------------------------------------
# USERS AND DATABASES
#------------------------------------------------------------------------------

default["postgresql"]["users"]                           = []
default["postgresql"]["databases"]                       = []
default["postgresql"]["extensions"]                      = []
default["postgresql"]["languages"]                       = []



#------------------------------------------------------------------------------
# CUSTOMIZED OPTIONS
#------------------------------------------------------------------------------

default["postgresql"]["custom_variable_classes"]         = ""


#------------------------------------------------------------------------------
# POSTGIS OPTIONS
#------------------------------------------------------------------------------

default["postgis"]["version"] = "2.1"

TODO

  • Add support for replication setup
  • Add installation and configuration for the following packages:
postgresql-{version}-ip4r
postgresql-{version}-pgq3
postgresql-{version}-pgmp
postgresql-{version}-plproxy
postgresql-{version}-repmgr
postgresql-{version}-debversion
postgresql-{version}-pgpool2
postgresql-{version}-slony1-2

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Contributors

Many thanks go to the following who have contributed to making this cookbook even better:

  • @flashingpumpkin
    • recipe bugfixes
    • add pg_user and pg_database definitions
  • @cmer
    • add encrypted_password param for pg_user definition
  • @dickeyxxx
    • speed up recipe loading and execution
    • add support for specifying database locale
    • add support for adding users and databases via attributes
  • @alno
    • add support to install additional languages/extensions/postgis to existing databases
    • add pg_database_extensions definition
  • @ermolaev
    • improve platform check for source repo
    • support debian 7 (wheezy)
  • @escobera
    • fix for missing ssl directives in postgresql.conf
  • @cdoughty77
    • allow finer tuning inside pg_hba.conf file
  • @NOX73
    • fix postgresql.conf ssl parameter failure on 9.1
  • @navinpeiris
    • add ability to configure apt distribution
  • @michihuber
    • create data/config dirs recursively
  • @sethcall
    • allow 'lazy' evaluation of configs in the custom template
  • @jherdman
    • update README to include updated apt repository link
    • add support for version 9.3
  • @stianselland
    • fix idempotence for pg_user definition
  • @alenia
    • conditionally override attributes in postgresql.conf
    • support for customizable apt sources
    • add ability to use an apt keyserver
  • @Randommood
    • conditionally override attributes in postgresql.conf
    • support for customizable apt sources
    • add ability to use an apt keyserver
  • @vrischmann
    • uncomment wal_writer_delay attribute
  • @brainopia
    • support encrypted_password in the pg_user recipe
  • @tpitale
    • update example encoding/locales in README to fix error
  • @seamusabshere
    • uncomment various configuration settings
    • uncomment more configuration settings
    • uncomment commit_delay and temp_buffers settings
    • uncomment random_page_cost and seq_page_cost settings
  • @RichardWigley
    • fix empty password causes exception
  • @phumpal
    • update default["postgresql"]["apt_key"] to new location
  • @mjallday
    • allow controlling how to restart postgres
  • @cgunther
    • uncomment log_filename attribute
  • @rosenfeld
    • ensure proper database is selected in pg_database definition
  • @j-martin
    • ensure proper quoting of role name in pg_user definition
  • @helgi
    • add replication mode to pg_user definition
  • @vesln
    • add missing ssl_ca_file and ssl_crl_file attributes to the configuration template
  • @vivid-inc
    • add service_actions attribute
  • @rmoriz
    • remove redundant postgis attribute

License

chef-postgresql

chef-postgresql's People

Contributors

alno avatar bitdeli-chef avatar cdoughty77 avatar cgunther avatar cmer avatar dwradcliffe avatar ermolaev avatar escobera avatar flashingpumpkin avatar freshtonic avatar helgi avatar navinpeiris avatar notapatch avatar nox73 avatar phlipper avatar phumpal avatar rmoriz avatar rosenfeld avatar seamusabshere avatar sethcall avatar tpitale avatar vesln avatar vrischmann avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

chef-postgresql's Issues

custom config needs to be ordered

Our chef deploy uses ruby 1.8.7 which has unordered hashes. When generating a custom config, the file is in a different order every time, which triggers a postgres restart on every single run which is not so good. The following snippit clears it up.

<% @configuration.keys.sort.each do |key| %> │ *
<%= "#{key} = '#{@configuration[key]}'" %> │ * <% end %>

pg_hba error with 9.4

Hi, I'm trying to install Postgres 9.4. However, the server recipe is trying to access pg_hba in a version 9.3 directory structure.

My attributes:

default["postgresql"]["version"] = "9.4"

I'm getting this error:

==> default:
==> default: ================================================================================
==> default: Error executing action `create` on resource 'template[/etc/postgresql/9.3/main/pg_hba.conf]'
==> default: ================================================================================
==> default:
==> default: Chef::Exceptions::EnclosingDirectoryDoesNotExist
==> default: ------------------------------------------------
==> default: Parent directory /etc/postgresql/9.3/main does not exist.
==> default:
==> default: Resource Declaration:
==> default:
==> default: ---------------------
==> default: suppressed sensitive resource output
==> default:
==> default:
==> default: Compiled Resource:
==> default: ------------------
==> default: suppressed sensitive resource output
==> default:
==> default:
==> default: [2014-12-21T22:46:23+00:00] INFO: Running queued delayed notifications before re-raising exception
==> default: [2014-12-21T22:46:24+00:00] INFO: template[/etc/postgresql/9.4/main/environment] sending reload action to service[postgresql] (delayed)
==> default: [2014-12-21T22:46:24+00:00] ERROR: Running exception handlers
==> default: [2014-12-21T22:46:24+00:00] ERROR: Exception handlers complete
==> default: [2014-12-21T22:46:24+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
==> default: [2014-12-21T22:46:24+00:00] ERROR: template[/etc/postgresql/9.3/main/pg_hba.conf] (postgresql::configuration line 34) had an error: Chef::Exceptions::EnclosingDirectoryDoesNotExist: Parent directory /etc/postgresql/9.3/main does not exist.
==> default: [2014-12-21T22:46:24+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)
Chef never successfully completed! Any errors should be visible in the
output above. Please fix your recipes so that they properly complete.

Postgres Not Starting on Vagrant "reload"

I'm having trouble reloading my Vagrant box. When re-provisioning during the reload, I get the following error:

================================================================================                                                                    [16/404]
Error executing action `run` on resource 'execute[creating pg user someguy]'
================================================================================


Mixlib::ShellOut::ShellCommandFailed
------------------------------------
Expected process to exit with [0], but received '1'
---- Begin output of psql -c "CREATE ROLE someguy SUPERUSER CREATEDB LOGIN PASSWORD 'someguy'" ----
STDOUT:
STDERR: Error: Cannot stat /var/run/postgresql
---- End output of psql -c "CREATE ROLE someguy SUPERUSER CREATEDB LOGIN PASSWORD 'someguy'" ----
Ran psql -c "CREATE ROLE someguy SUPERUSER CREATEDB LOGIN PASSWORD 'someguy'" returned 1


Resource Declaration:

---------------------

# In /tmp/vagrant-chef-1/chef-solo-1/cookbooks/postgresql/definitions/pg_user.rb

 33:     execute "creating pg user #{params[:name]}" do
 34:       user "postgres"
 35:       command %(psql -c "CREATE ROLE #{sql}")
 36:       not_if exists, user: "postgres"
 37:     end
 38:



Compiled Resource:
------------------
# Declared in /tmp/vagrant-chef-1/chef-solo-1/cookbooks/postgresql/definitions/pg_user.rb:33:in `block in from_file'

execute("creating pg user someguy") do
  params {:action=>:create, :privileges=>{:superuser=>true, :createdb=>true, :login=>true}, :password=>"someguy", :name=>"someguy"}
  action "run"
  retries 0
  retry_delay 2
  command "psql -c \"CREATE ROLE someguy SUPERUSER CREATEDB LOGIN PASSWORD 'someguy'\""
  backup 5
  returns 0
  user "postgres"
  cookbook_name :postgresql
  recipe_name "pg_user"
  not_if "psql -c "SELECT usename FROM pg_user WHERE usename='someguy'" | grep someguy"
end

[2013-09-27T21:43:15+00:00] INFO: Running queued delayed notifications before re-raising exception
[2013-09-27T21:43:15+00:00] ERROR: Running exception handlers
[2013-09-27T21:43:15+00:00] ERROR: Exception handlers complete
[2013-09-27T21:43:15+00:00] FATAL: Stacktrace dumped to /tmp/vagrant-chef-1/chef-stacktrace.out
[2013-09-27T21:43:15+00:00] FATAL: Mixlib::ShellOut::ShellCommandFailed: execute[creating pg user someguy] (postgresql::pg_user line 33) had an error: Mixlib::Sh
ellOut::ShellCommandFailed: Expected process to exit with [0], but received '1'
---- Begin output of psql -c "CREATE ROLE es SUPERUSER CREATEDB LOGIN PASSWORD 'someguy'" ----
STDOUT:
STDERR: Error: Cannot stat /var/run/postgresql
---- End output of psql -c "CREATE ROLE someguy SUPERUSER CREATEDB LOGIN PASSWORD 'someguy'" ----
Ran psql -c "CREATE ROLE someguy SUPERUSER CREATEDB LOGIN PASSWORD 'someguy'" returned 1
Chef never successfully completed! Any errors should be visible in the
output above. Please fix your recipes so that they properly complete.

This suggests that Postgres isn't restarting. My hunch is that this is due to my 9.3 changes (#47). I haven't had much time to dig into this, but I thought I'd raise the issue to raise awareness.

server_debian recipe not found during install

While trying to install the cookbook I encountered:

Chef::Exceptions::RecipeNotFound
--------------------------------
could not find recipe server_debian for cookbook postgresql

[2014-01-04T18:53:55+00:00] ERROR: Running exception handlers
[2014-01-04T18:53:55+00:00] ERROR: Exception handlers complete
[2014-01-04T18:53:55+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
[2014-01-04T18:53:55+00:00] FATAL: Chef::Exceptions::RecipeNotFound: could not find recipe server_debian for cookbook postgresql
  'recipe[postgresql]',
  'recipe[postgresql::client]',
  'recipe[postgresql::server]',
  'recipe[postgresql::contrib]',
  'recipe[postgresql::postgis]',
  'recipe[postgresql::libpq]'

Thoughts?

Ability to use with RDS and other password protected remote servers

I was getting ready to implement this cookbook for the portion of my infrastructure that uses Amazon RDS. It works great for interacting with PG servers that I setup with this cookbook that can be accessed without password from the postgres user, but when it come to interacting with an RDS server, which requires password authentication, I don't see any way to use it.

The supermarket postgresql cookbook allows for this, as you can pass in a "connection" hash that includes a password. However that cookbook has ben almost useless for me as of late, especially when trying to upgrade to versions of Postgres that are not the one in the main OS repo.

Any plans to implement a way to interact with password based servers?

Can't Do Point Release Upgrades

I noticed recently that when cooking one of my servers to do an upgrade of Postgresql that it didn't install the latest package.

The problem seems to be how we're using the package directive. By default it uses the :install action, which won't install new versions of a package even if available. I think we should be using :upgrade, which will install newer packages if available. That said, this may be undesirable behaviour for some users. Perhaps the action used should be configurable? E.g.

# In chef-postgresql / attributes / default.rb
default["postgresql"]["version"]                         = "9.3"
default["postgresql"]["version_action"]               = "install"

# In chef-postgresql / recipes / client.rb
package "postgresql-client-#{node["postgresql"]["version"]}" do
  action node["postgresql"]["version_action"].to_sym
end

Thoughts?

Attempt to create duplicate roles

It seems the check used to determine if a role should be created isn't working properly because multiple runs with the same roles configured (via json) throw "role already exists" errors.

Error executing action `install` on resource 'package[chef-postgresql-9.2]'

I have use this recipe and found this error when deploy. Can someone shed some light on this error.

2013-04-24T06:05:58+00:00] INFO: Processing package[chef-postgresql-9.2] action install (chef-postgresql::server line 11)

Error executing action install on resource 'package[chef-postgresql-9.2]'

Chef::Exceptions::Package

No version specified, and no candidate version available for chef-postgresql-9.2

Resource Declaration:

In /var/chef/cache/cookbooks/chef-postgresql/recipes/server.rb

11: package "chef-postgresql-#{node["postgresql"]["version"]}"
12:

Compiled Resource:

Declared in /var/chef/cache/cookbooks/chef-postgresql/recipes/server.rb:11:in `from_file'

package("chef-postgresql-9.2") do
action :install
retries 0
retry_delay 2
package_name "chef-postgresql-9.2"
cookbook_name "chef-postgresql"
recipe_name "server"
end

[2013-04-24T06:05:58+00:00] ERROR: Running exception handlers
[2013-04-24T06:05:58+00:00] FATAL: Saving node information to /var/chef/cache/failed-run-data.json
[2013-04-24T06:05:58+00:00] ERROR: Exception handlers complete
[2013-04-24T06:05:58+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
[2013-04-24T06:05:58+00:00] FATAL: Chef::Exceptions::Package: package[chef-postgresql-9.2](chef-postgresql::server line 11) had an error: Chef::Exceptions::Package: No version specified, and no candidate version available for chef-postgresql-9.2
root@ip-10-130-62-202:/home/ubuntu#

Question: Best way to handle timezone configuration

First, thank you for this incredibly well-built cookbook. It has been a pleasure to work with. I have a best practices question:

How should we handle setting a default time zone if we do not want to use the server time zone as the default? Specifically, my goal is to have PostgreSQL always return timestamptz results in UTC time without having to (a) configure my server to UTC, or (b) change any settings in the clients that connect.

I was going to set the TZ environment variable per the PostgreSQL 9.1 Documentation, but this appears to be removed from the 9.3 Documentation without apparent explanation.

I could just edit the timezone property of postgresql.conf file (line 566 of latest release), but I am using the application cookbook wrapper pattern and try to avoid touching anything at all on community cookbooks.

Any suggestions on how to handle this?

hstore extension creation fails?

recipe fails to create the hstore extension on pgsql 9.2. naturally, trying to create it manually doesn't work either. some issue with the packaging?

t::ShellCommandFailed: Expected process to exit with [0], but received '1'
---- Begin output of psql -c 'CREATE EXTENSION IF NOT EXISTS hstore' remix_v3_test ----
STDOUT: 
STDERR: ERROR:  could not open extension control file "/usr/share/postgresql/9.2/extension/hstore.control": No such file or directory
---- End output of psql -c 'CREATE EXTENSION IF NOT EXISTS hstore' remix_v3_test ----
Ran psql -c 'CREATE EXTENSION IF NOT EXISTS hstore' remix_v3_test returned 1

libpq lib doesn't seem to work as intended for the rails pg gem

I have included include_recipe 'postgresql::libpq' but it's not installing the correct library that's needed for the rails pg gem.

My app is failing to deploy because of:

** [out :: 192.168.1.9:40402] Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
 ** [out :: 192.168.1.9:40402] 
 ** [out :: 192.168.1.9:40402] 
 ** [out :: 192.168.1.9:40402] /opt/ruby-210/bin/ruby extconf.rb
 ** [out :: 192.168.1.9:40402] 
 ** [out :: 192.168.1.9:40402] checking for pg_config... yes
 ** [out :: 192.168.1.9:40402] 
 ** [out :: 192.168.1.9:40402] Using config values from /usr/bin/pg_config
 ** [out :: 192.168.1.9:40402] 
 ** [out :: 192.168.1.9:40402] checking for libpq-fe.h... yes
 ** [out :: 192.168.1.9:40402] 
 ** [out :: 192.168.1.9:40402] checking for libpq/libpq-fs.h... yes
 ** [out :: 192.168.1.9:40402] 
 ** [out :: 192.168.1.9:40402] checking for pg_config_manual.h... yes
 ** [out :: 192.168.1.9:40402] 
 ** [out :: 192.168.1.9:40402] checking for PQconnectdb() in -lpq... no
 ** [out :: 192.168.1.9:40402] 
 ** [out :: 192.168.1.9:40402] checking for PQconnectdb() in -llibpq... no
 ** [out :: 192.168.1.9:40402] 
 ** [out :: 192.168.1.9:40402] checking for PQconnectdb() in -lms/libpq... no
 ** [out :: 192.168.1.9:40402] 
 ** [out :: 192.168.1.9:40402] Can't find the PostgreSQL client library (libpq)
 ** [out :: 192.168.1.9:40402] 
 ** [out :: 192.168.1.9:40402] *** extconf.rb failed ***
 ** [out :: 192.168.1.9:40402] 
 ** [out :: 192.168.1.9:40402] Could not create Makefile due to some reason, probably lack of necessary
 ** [out :: 192.168.1.9:40402] 
 ** [out :: 192.168.1.9:40402] libraries and/or headers.  Check the mkmf.log file for more details.  You may
 ** [out :: 192.168.1.9:40402] 
 ** [out :: 192.168.1.9:40402] need configuration options.
 ** [out :: 192.168.1.9:40402] 
 ** [out :: 192.168.1.9:40402] 
 ** [out :: 192.168.1.9:40402] Provided configuration options:
 ** [out :: 192.168.1.9:40402] 
 ** [out :: 192.168.1.9:40402] 
 ** [out :: 192.168.1.9:40402] --with-opt-dir
 ** [out :: 192.168.1.9:40402] 
 ** [out :: 192.168.1.9:40402] 
 ** [out :: 192.168.1.9:40402] --with-opt-include
 ** [out :: 192.168.1.9:40402] 
 ** [out :: 192.168.1.9:40402] 
 ** [out :: 192.168.1.9:40402] --without-opt-include=${opt-dir}/include
 ** [out :: 192.168.1.9:40402] 
 ** [out :: 192.168.1.9:40402] 
 ** [out :: 192.168.1.9:40402] --with-opt-lib
 ** [out :: 192.168.1.9:40402] 
 ** [out :: 192.168.1.9:40402] --without-opt-lib=${opt-dir}/lib
 ** [out :: 192.168.1.9:40402] 
 ** [out :: 192.168.1.9:40402] --with-make-prog
 ** [out :: 192.168.1.9:40402] --without-make-prog
 ** [out :: 192.168.1.9:40402] --srcdir=.
 ** [out :: 192.168.1.9:40402] 
 ** [out :: 192.168.1.9:40402] --curdir
 ** [out :: 192.168.1.9:40402] --ruby=/opt/ruby-210/bin/ruby
 ** [out :: 192.168.1.9:40402] --with-pg
 ** [out :: 192.168.1.9:40402] 
 ** [out :: 192.168.1.9:40402] --without-pg
 ** [out :: 192.168.1.9:40402] --with-pg-config
 ** [out :: 192.168.1.9:40402] 
 ** [out :: 192.168.1.9:40402] --without-pg-config
 ** [out :: 192.168.1.9:40402] --with-pg_config
 ** [out :: 192.168.1.9:40402] --without-pg_config
 ** [out :: 192.168.1.9:40402] 
 ** [out :: 192.168.1.9:40402] --with-pg-dir
 ** [out :: 192.168.1.9:40402] --without-pg-dir
 ** [out :: 192.168.1.9:40402] --with-pg-include
 ** [out :: 192.168.1.9:40402] 
 ** [out :: 192.168.1.9:40402] --without-pg-include=${pg-dir}/include
 ** [out :: 192.168.1.9:40402] --with-pg-lib
 ** [out :: 192.168.1.9:40402] --without-pg-lib=${pg-dir}/lib
 ** [out :: 192.168.1.9:40402] 
 ** [out :: 192.168.1.9:40402] --with-pqlib
 ** [out :: 192.168.1.9:40402] --without-pqlib
 ** [out :: 192.168.1.9:40402] --with-libpqlib
 ** [out :: 192.168.1.9:40402] 
 ** [out :: 192.168.1.9:40402] --without-libpqlib
 ** [out :: 192.168.1.9:40402] --with-ms/libpqlib
 ** [out :: 192.168.1.9:40402] --without-ms/libpqlib
 ** [out :: 192.168.1.9:40402] 
 ** [out :: 192.168.1.9:40402] extconf failed, exit code 1

I also gisted the mkmf.log file here:
https://gist.github.com/AntelopeSalad/8285590#file-mkmf-log

I did not want to drop it in here because it's pretty long.

Attributes that interpolate the node's postgres version remain at 9.1 (the default) when node overrides postgres version

See CHEF-3275 and CHEF-3296 as to why this is a problem.

The lines in question from attributes/default.rb are:

default["postgresql"]["data_directory"]                  = "/var/lib/postgresql/#{node["postgresql"]["version"]}/main"
default["postgresql"]["hba_file"]                        = "/etc/postgresql/#{node["postgresql"]["version"]}/main/pg_hba.conf"
default["postgresql"]["ident_file"]                      = "/etc/postgresql/#{node["postgresql"]["version"]}/main/pg_ident.conf"
default["postgresql"]["external_pid_file"]               = "/var/run/postgresql/#{node["postgresql"]["version"]}-main.pid"

Here is a sample of output taken from the chef-client run. You can see that for the pg_ctl.conf file, the version in the file path is correct. However, the version for pg_hba.conf is incorrect. The difference is when the version number interpolation occurs. For pg_ctl.conf, it happens in the recipe/server.rb after the node attributes are available as opposed to the attributes file.

Processing template[/etc/postgresql/9.2/main/environment] action create (postgresql::server line 15)
[Thu, 11 Oct 2012 01:06:06 +0000] INFO: Processing template[/etc/postgresql/9.2/main/pg_ctl.conf] action create (postgresql::server line 24)
[Thu, 11 Oct 2012 01:06:06 +0000] INFO: Processing template[/etc/postgresql/9.1/main/pg_hba.conf] action create (postgresql::server line 33)
[Thu, 11 Oct 2012 01:06:06 +0000] INFO: template[/etc/postgresql/9.1/main/pg_hba.conf] owner changed to 108
[Thu, 11 Oct 2012 01:06:06 +0000] INFO: template[/etc/postgresql/9.1/main/pg_hba.conf] group changed to 115
[Thu, 11 Oct 2012 01:06:06 +0000] INFO: template[/etc/postgresql/9.1/main/pg_hba.conf] mode changed to 640
[Thu, 11 Oct 2012 01:06:06 +0000] ERROR: template[/etc/postgresql/9.1/main/pg_hba.conf] (postgresql::server line 33) has had an error
[Thu, 11 Oct 2012 01:06:06 +0000] ERROR: template[/etc/postgresql/9.1/main/pg_hba.conf] (/var/cache/chef/cookbooks/postgresql/recipes/server.rb:33:in

pg_hba.conf not being found

I'm getting this error which is preventing install. Any idea?

[Wed, 26 Sep 2012 21:42:07 +0000] FATAL: Errno::ENOENT: template[/etc/postgresql/9.1/main/pg_hba.conf](postgresql::server line 33) had an error: No such file or directory - /tmp/chef-rendered-template20120926-19763-10386la-0 or /etc/postgresql/9.1/main/pg_hba.conf

whitespace is missing?

roles/db.json:

{
    "name": "db",
    "override_attributes": {
        "postgresql": {
            "users": [
                {
                    "username": "myuser",
                    "password": "myuser",
                    "login": true
                }
            ],
            "databases": [
                {
                    "name": "myuser",
                    "owner": "myuser",
                    "encoding": "utf8",
                    "locale": "en_US.UTF8"
                }
            ]
        }
    },
    "run_list": [
        "recipe[postgresql]",
        "recipe[postgresql::server]"
    ]
}

output:

Recipe: postgresql::pg_user
  * execute[alter pg user myuserNOSUPERUSER NOCREATEDB LOGINPASSWORD 'myuser'] action run (skipped due to only_if)
  * execute[create pg user myuserNOSUPERUSER NOCREATEDB LOGINPASSWORD 'myuser'] action run
================================================================================
Error executing action `run` on resource 'execute[create pg user myuserNOSUPERUSER NOCREATEDB LOGINPASSWORD 'myuser']'
================================================================================


Mixlib::ShellOut::ShellCommandFailed
------------------------------------
Expected process to exit with [0], but received '1'
---- Begin output of psql -c "CREATE ROLE myuserNOSUPERUSER NOCREATEDB LOGINPASSWORD 'myuser'" ----
STDOUT:
STDERR: ERROR:  unrecognized role option "loginpassword"
LINE 1: CREATE ROLE myuserNOSUPERUSER NOCREATEDB LOGINPASSWORD 'myuser...
                                                ^
---- End output of psql -c "CREATE ROLE myuserNOSUPERUSER NOCREATEDB LOGINPASSWORD 'myuser'" ----
Ran psql -c "CREATE ROLE myuserNOSUPERUSER NOCREATEDB LOGINPASSWORD 'myuser'" returned 1


Resource Declaration:
---------------------
# In /var/chef/cache/cookbooks/postgresql/definitions/pg_user.rb

 31:     execute "create pg user #{role_name}" do
 32:       user "postgres"
 33:       command %(psql -c "CREATE ROLE #{role_sql}")
 34:       not_if role_exists, user: "postgres"
 35:     end
 36:



Compiled Resource:
------------------
# Declared in /var/chef/cache/cookbooks/postgresql/definitions/pg_user.rb:31:in `block in from_file'

execute("create pg user myuserNOSUPERUSER NOCREATEDB LOGINPASSWORD 'myuser'") do
  params {:action=>:create, :privileges=>{:superuser=>nil, :createdb=>nil, :login=>true}, :password=>"myuser", :name=>"myuserNOSUPERUSER NOCREATEDB LOGINPASSWORD 'myuser'"}
  action "run"
  retries 0
  retry_delay 2
  command "psql -c \"CREATE ROLE myuserNOSUPERUSER NOCREATEDB LOGINPASSWORD 'myuser'\""
  backup 5
  returns 0
  user "postgres"
  cookbook_name "postgresql"
  recipe_name "pg_user"
  not_if "psql -c "SELECT rolname FROM pg_roles WHERE rolname='myuserNOSUPERUSER NOCREATEDB LOGINPASSWORD 'myuser''" | grep myuserNOSUPERUSER NOCREATEDB LOGINPASSWORD 'myuser'"
end

Error: Invalid data directory

I'm using this cookbook in my Vagrant config.

I use the following settings:

  config.vm.provision :chef_solo do |chef|
    chef.add_recipe 'postgresql::server'
    chef.add_recipe 'postgresql::client'
    chef.add_recipe 'postgresql::contrib'

    # noinspection RubyStringKeysInHashInspection
    chef.json = {
        'postgresql' => {
            'users' => [
                {
                    'username' => 'foo',
                    'password' => 'foo',
                    'superuser' => true,
                    'createdb' => true,
                    'login' => true
                }
            ],
            'databases' => [
                {
                    'name' => 'bar',
                    'owner' => 'foo',
                    'template' => 'template0',
                    'encoding' => 'utf8',
                    'locale' => 'en_US.UTF8'
                }
            ],
            'conf' => {
                'max_connections' => 100,
                'max_prepared_transactions' => 100
            }
        }
   }
  end

and I get Error: Invalid data directory. I logged in to VM and performing any action on Postgres results in the same error:

vagrant@precise32:~$ sudo service postgresql restart
Error: Invalid data directory
 * No PostgreSQL clusters exist; see "man pg_createcluster"

However, there is some data directory in /var/lib/postgres:

vagrant@precise32:~$ sudo ls -la /var/lib/postgresql/9.3/main/
total 64
drwx------ 15 postgres postgres 4096 Apr 12 07:51 .
drwxr-xr-x  3 postgres postgres 4096 Apr 12 07:51 ..
drwx------  5 postgres postgres 4096 Apr 12 07:51 base
drwx------  2 postgres postgres 4096 Apr 12 07:51 global
drwx------  2 postgres postgres 4096 Apr 12 07:51 pg_clog
drwx------  4 postgres postgres 4096 Apr 12 07:51 pg_multixact
drwx------  2 postgres postgres 4096 Apr 12 07:51 pg_notify
drwx------  2 postgres postgres 4096 Apr 12 07:51 pg_serial
drwx------  2 postgres postgres 4096 Apr 12 07:51 pg_snapshots
drwx------  2 postgres postgres 4096 Apr 12 07:51 pg_stat
drwx------  2 postgres postgres 4096 Apr 12 07:51 pg_stat_tmp
drwx------  2 postgres postgres 4096 Apr 12 07:51 pg_subtrans
drwx------  2 postgres postgres 4096 Apr 12 07:51 pg_tblspc
drwx------  2 postgres postgres 4096 Apr 12 07:51 pg_twophase
-rw-------  1 postgres postgres    4 Apr 12 07:51 PG_VERSION
drwx------  3 postgres postgres 4096 Apr 12 07:51 pg_xlog
postgres@precise32:/home/vagrant$ pg_createcluster 9.3 main
Error: cluster configuration already exists

Vagrant log:


[2014-04-12T07:51:26+00:00] INFO: file[/etc/apt/sources.list.d/apt.postgresql.org.list] owner changed to 0
DEBUG ssh: stdout: [2014-04-12T07:51:26+00:00] INFO: file[/etc/apt/sources.list.d/apt.postgresql.org.list] group changed to 0

 INFO interface: info: [2014-04-12T07:51:26+00:00] INFO: file[/etc/apt/sources.list.d/apt.postgresql.org.list] group changed to 0

[2014-04-12T07:51:26+00:00] INFO: file[/etc/apt/sources.list.d/apt.postgresql.org.list] group changed to 0
DEBUG ssh: stdout: [2014-04-12T07:51:26+00:00] INFO: file[/etc/apt/sources.list.d/apt.postgresql.org.list] mode changed to 644
[2014-04-12T07:51:26+00:00] INFO: file[/etc/apt/sources.list.d/apt.postgresql.org.list] created file /etc/apt/sources.list.d/apt.postgresql.org.list

 INFO interface: info: [2014-04-12T07:51:26+00:00] INFO: file[/etc/apt/sources.list.d/apt.postgresql.org.list] mode changed to 644
[2014-04-12T07:51:26+00:00] INFO: file[/etc/apt/sources.list.d/apt.postgresql.org.list] created file /etc/apt/sources.list.d/apt.postgresql.org.list

[2014-04-12T07:51:26+00:00] INFO: file[/etc/apt/sources.list.d/apt.postgresql.org.list] mode changed to 644
[2014-04-12T07:51:26+00:00] INFO: file[/etc/apt/sources.list.d/apt.postgresql.org.list] created file /etc/apt/sources.list.d/apt.postgresql.org.list
DEBUG ssh: stdout: [2014-04-12T07:51:26+00:00] INFO: file[/etc/apt/sources.list.d/apt.postgresql.org.list] sending delete action to file[/var/lib/apt/periodic/update-success-stamp] (immediate)

 INFO interface: info: [2014-04-12T07:51:26+00:00] INFO: file[/etc/apt/sources.list.d/apt.postgresql.org.list] sending delete action to file[/var/lib/apt/periodic/update-success-stamp] (immediate)

[2014-04-12T07:51:26+00:00] INFO: file[/etc/apt/sources.list.d/apt.postgresql.org.list] sending delete action to file[/var/lib/apt/periodic/update-success-stamp] (immediate)
DEBUG ssh: stdout: [2014-04-12T07:51:26+00:00] INFO: file[/var/lib/apt/periodic/update-success-stamp] backed up to /var/chef/backup/var/lib/apt/periodic/update-success-stamp.chef-20140412075126

 INFO interface: info: [2014-04-12T07:51:26+00:00] INFO: file[/var/lib/apt/periodic/update-success-stamp] backed up to /var/chef/backup/var/lib/apt/periodic/update-success-stamp.chef-20140412075126

[2014-04-12T07:51:26+00:00] INFO: file[/var/lib/apt/periodic/update-success-stamp] backed up to /var/chef/backup/var/lib/apt/periodic/update-success-stamp.chef-20140412075126
DEBUG ssh: stdout: [2014-04-12T07:51:26+00:00] INFO: file[/var/lib/apt/periodic/update-success-stamp] deleted file at /var/lib/apt/periodic/update-success-stamp

 INFO interface: info: [2014-04-12T07:51:26+00:00] INFO: file[/var/lib/apt/periodic/update-success-stamp] deleted file at /var/lib/apt/periodic/update-success-stamp

[2014-04-12T07:51:26+00:00] INFO: file[/var/lib/apt/periodic/update-success-stamp] deleted file at /var/lib/apt/periodic/update-success-stamp
DEBUG ssh: stdout: [2014-04-12T07:51:26+00:00] INFO: file[/etc/apt/sources.list.d/apt.postgresql.org.list] sending run action to execute[apt-get update] (immediate)

 INFO interface: info: [2014-04-12T07:51:26+00:00] INFO: file[/etc/apt/sources.list.d/apt.postgresql.org.list] sending run action to execute[apt-get update] (immediate)

[2014-04-12T07:51:26+00:00] INFO: file[/etc/apt/sources.list.d/apt.postgresql.org.list] sending run action to execute[apt-get update] (immediate)
DEBUG ssh: Sending SSH keep-alive...
DEBUG ssh: stdout: [2014-04-12T07:51:28+00:00] INFO: execute[apt-get update] ran successfully

 INFO interface: info: [2014-04-12T07:51:28+00:00] INFO: execute[apt-get update] ran successfully

[2014-04-12T07:51:28+00:00] INFO: execute[apt-get update] ran successfully
DEBUG ssh: stdout: [2014-04-12T07:51:28+00:00] INFO: execute[apt-get update] sending run action to execute[apt-cache gencaches] (immediate)

 INFO interface: info: [2014-04-12T07:51:28+00:00] INFO: execute[apt-get update] sending run action to execute[apt-cache gencaches] (immediate)

[2014-04-12T07:51:28+00:00] INFO: execute[apt-get update] sending run action to execute[apt-cache gencaches] (immediate)
DEBUG ssh: stdout: [2014-04-12T07:51:29+00:00] INFO: execute[apt-cache gencaches] ran successfully

 INFO interface: info: [2014-04-12T07:51:29+00:00] INFO: execute[apt-cache gencaches] ran successfully

[2014-04-12T07:51:29+00:00] INFO: execute[apt-cache gencaches] ran successfully
DEBUG ssh: Sending SSH keep-alive...
DEBUG ssh: stdout: [2014-04-12T07:51:33+00:00] INFO: entered create

 INFO interface: info: [2014-04-12T07:51:33+00:00] INFO: entered create

[2014-04-12T07:51:33+00:00] INFO: entered create
DEBUG ssh: stdout: [2014-04-12T07:51:33+00:00] INFO: file[/usr/sbin/policy-rc.d] mode changed to 755
[2014-04-12T07:51:33+00:00] INFO: file[/usr/sbin/policy-rc.d] created file /usr/sbin/policy-rc.d

 INFO interface: info: [2014-04-12T07:51:33+00:00] INFO: file[/usr/sbin/policy-rc.d] mode changed to 755
[2014-04-12T07:51:33+00:00] INFO: file[/usr/sbin/policy-rc.d] created file /usr/sbin/policy-rc.d

[2014-04-12T07:51:33+00:00] INFO: file[/usr/sbin/policy-rc.d] mode changed to 755
[2014-04-12T07:51:33+00:00] INFO: file[/usr/sbin/policy-rc.d] created file /usr/sbin/policy-rc.d
DEBUG ssh: Sending SSH keep-alive...
DEBUG ssh: Sending SSH keep-alive...
DEBUG ssh: Sending SSH keep-alive...
DEBUG ssh: stdout: [2014-04-12T07:51:48+00:00] INFO: template[/etc/postgresql/9.3/main/environment] backed up to /var/chef/backup/etc/postgresql/9.3/main/environment.chef-20140412075148

 INFO interface: info: [2014-04-12T07:51:48+00:00] INFO: template[/etc/postgresql/9.3/main/environment] backed up to /var/chef/backup/etc/postgresql/9.3/main/environment.chef-20140412075148

[2014-04-12T07:51:48+00:00] INFO: template[/etc/postgresql/9.3/main/environment] backed up to /var/chef/backup/etc/postgresql/9.3/main/environment.chef-20140412075148
DEBUG ssh: stdout: [2014-04-12T07:51:48+00:00] INFO: template[/etc/postgresql/9.3/main/environment] updated content

 INFO interface: info: [2014-04-12T07:51:48+00:00] INFO: template[/etc/postgresql/9.3/main/environment] updated content

[2014-04-12T07:51:48+00:00] INFO: template[/etc/postgresql/9.3/main/environment] updated content
DEBUG ssh: stdout: [2014-04-12T07:51:48+00:00] INFO: template[/etc/postgresql/9.3/main/environment] owner changed to 107

 INFO interface: info: [2014-04-12T07:51:48+00:00] INFO: template[/etc/postgresql/9.3/main/environment] owner changed to 107

[2014-04-12T07:51:48+00:00] INFO: template[/etc/postgresql/9.3/main/environment] owner changed to 107
DEBUG ssh: stdout: [2014-04-12T07:51:48+00:00] INFO: template[/etc/postgresql/9.3/main/environment] group changed to 113

 INFO interface: info: [2014-04-12T07:51:48+00:00] INFO: template[/etc/postgresql/9.3/main/environment] group changed to 113

[2014-04-12T07:51:48+00:00] INFO: template[/etc/postgresql/9.3/main/environment] group changed to 113
DEBUG ssh: stdout: [2014-04-12T07:51:48+00:00] INFO: template[/etc/postgresql/9.3/main/environment] mode changed to 644

 INFO interface: info: [2014-04-12T07:51:48+00:00] INFO: template[/etc/postgresql/9.3/main/environment] mode changed to 644

[2014-04-12T07:51:48+00:00] INFO: template[/etc/postgresql/9.3/main/environment] mode changed to 644
DEBUG ssh: stdout: [2014-04-12T07:51:48+00:00] INFO: template[/etc/postgresql/9.3/main/pg_hba.conf] backed up to /var/chef/backup/etc/postgresql/9.3/main/pg_hba.conf.chef-20140412075148

 INFO interface: info: [2014-04-12T07:51:48+00:00] INFO: template[/etc/postgresql/9.3/main/pg_hba.conf] backed up to /var/chef/backup/etc/postgresql/9.3/main/pg_hba.conf.chef-20140412075148

[2014-04-12T07:51:48+00:00] INFO: template[/etc/postgresql/9.3/main/pg_hba.conf] backed up to /var/chef/backup/etc/postgresql/9.3/main/pg_hba.conf.chef-20140412075148
DEBUG ssh: stdout: [2014-04-12T07:51:48+00:00] INFO: template[/etc/postgresql/9.3/main/pg_hba.conf] updated content

 INFO interface: info: [2014-04-12T07:51:48+00:00] INFO: template[/etc/postgresql/9.3/main/pg_hba.conf] updated content

[2014-04-12T07:51:48+00:00] INFO: template[/etc/postgresql/9.3/main/pg_hba.conf] updated content
DEBUG ssh: stdout: [2014-04-12T07:51:48+00:00] INFO: template[/etc/postgresql/9.3/main/pg_hba.conf] owner changed to 107

 INFO interface: info: [2014-04-12T07:51:48+00:00] INFO: template[/etc/postgresql/9.3/main/pg_hba.conf] owner changed to 107

[2014-04-12T07:51:48+00:00] INFO: template[/etc/postgresql/9.3/main/pg_hba.conf] owner changed to 107
DEBUG ssh: stdout: [2014-04-12T07:51:48+00:00] INFO: template[/etc/postgresql/9.3/main/pg_hba.conf] group changed to 113

 INFO interface: info: [2014-04-12T07:51:48+00:00] INFO: template[/etc/postgresql/9.3/main/pg_hba.conf] group changed to 113

[2014-04-12T07:51:48+00:00] INFO: template[/etc/postgresql/9.3/main/pg_hba.conf] group changed to 113
DEBUG ssh: stdout: [2014-04-12T07:51:48+00:00] INFO: template[/etc/postgresql/9.3/main/pg_hba.conf] mode changed to 640

 INFO interface: info: [2014-04-12T07:51:48+00:00] INFO: template[/etc/postgresql/9.3/main/pg_hba.conf] mode changed to 640

[2014-04-12T07:51:48+00:00] INFO: template[/etc/postgresql/9.3/main/pg_hba.conf] mode changed to 640
DEBUG ssh: stdout: [2014-04-12T07:51:48+00:00] INFO: template[/etc/postgresql/9.3/main/pg_hba.conf] not queuing delayed action restart on service[postgresql] (delayed), as it's already been queued

 INFO interface: info: [2014-04-12T07:51:48+00:00] INFO: template[/etc/postgresql/9.3/main/pg_hba.conf] not queuing delayed action restart on service[postgresql] (delayed), as it's already been queued

[2014-04-12T07:51:48+00:00] INFO: template[/etc/postgresql/9.3/main/pg_hba.conf] not queuing delayed action restart on service[postgresql] (delayed), as it's already been queued
DEBUG ssh: stdout: [2014-04-12T07:51:48+00:00] INFO: template[/etc/postgresql/9.3/main/pg_ident.conf] backed up to /var/chef/backup/etc/postgresql/9.3/main/pg_ident.conf.chef-20140412075148

 INFO interface: info: [2014-04-12T07:51:48+00:00] INFO: template[/etc/postgresql/9.3/main/pg_ident.conf] backed up to /var/chef/backup/etc/postgresql/9.3/main/pg_ident.conf.chef-20140412075148

[2014-04-12T07:51:48+00:00] INFO: template[/etc/postgresql/9.3/main/pg_ident.conf] backed up to /var/chef/backup/etc/postgresql/9.3/main/pg_ident.conf.chef-20140412075148
DEBUG ssh: stdout: [2014-04-12T07:51:48+00:00] INFO: template[/etc/postgresql/9.3/main/pg_ident.conf] updated content

 INFO interface: info: [2014-04-12T07:51:48+00:00] INFO: template[/etc/postgresql/9.3/main/pg_ident.conf] updated content

[2014-04-12T07:51:48+00:00] INFO: template[/etc/postgresql/9.3/main/pg_ident.conf] updated content
DEBUG ssh: stdout: [2014-04-12T07:51:48+00:00] INFO: template[/etc/postgresql/9.3/main/pg_ident.conf] owner changed to 107

 INFO interface: info: [2014-04-12T07:51:48+00:00] INFO: template[/etc/postgresql/9.3/main/pg_ident.conf] owner changed to 107

[2014-04-12T07:51:48+00:00] INFO: template[/etc/postgresql/9.3/main/pg_ident.conf] owner changed to 107
DEBUG ssh: stdout: [2014-04-12T07:51:48+00:00] INFO: template[/etc/postgresql/9.3/main/pg_ident.conf] group changed to 113

 INFO interface: info: [2014-04-12T07:51:48+00:00] INFO: template[/etc/postgresql/9.3/main/pg_ident.conf] group changed to 113

[2014-04-12T07:51:48+00:00] INFO: template[/etc/postgresql/9.3/main/pg_ident.conf] group changed to 113
DEBUG ssh: stdout: [2014-04-12T07:51:48+00:00] INFO: template[/etc/postgresql/9.3/main/pg_ident.conf] mode changed to 640

 INFO interface: info: [2014-04-12T07:51:48+00:00] INFO: template[/etc/postgresql/9.3/main/pg_ident.conf] mode changed to 640

[2014-04-12T07:51:48+00:00] INFO: template[/etc/postgresql/9.3/main/pg_ident.conf] mode changed to 640
DEBUG ssh: stdout: [2014-04-12T07:51:48+00:00] INFO: template[/etc/postgresql/9.3/main/pg_ident.conf] not queuing delayed action restart on service[postgresql] (delayed), as it's already been queued

 INFO interface: info: [2014-04-12T07:51:48+00:00] INFO: template[/etc/postgresql/9.3/main/pg_ident.conf] not queuing delayed action restart on service[postgresql] (delayed), as it's already been queued

[2014-04-12T07:51:48+00:00] INFO: template[/etc/postgresql/9.3/main/pg_ident.conf] not queuing delayed action restart on service[postgresql] (delayed), as it's already been queued
DEBUG ssh: stdout: [2014-04-12T07:51:48+00:00] INFO: template[/etc/postgresql/9.3/main/postgresql.conf] backed up to /var/chef/backup/etc/postgresql/9.3/main/postgresql.conf.chef-20140412075148

 INFO interface: info: [2014-04-12T07:51:48+00:00] INFO: template[/etc/postgresql/9.3/main/postgresql.conf] backed up to /var/chef/backup/etc/postgresql/9.3/main/postgresql.conf.chef-20140412075148

[2014-04-12T07:51:48+00:00] INFO: template[/etc/postgresql/9.3/main/postgresql.conf] backed up to /var/chef/backup/etc/postgresql/9.3/main/postgresql.conf.chef-20140412075148
DEBUG ssh: stdout: [2014-04-12T07:51:48+00:00] INFO: template[/etc/postgresql/9.3/main/postgresql.conf] updated content

 INFO interface: info: [2014-04-12T07:51:48+00:00] INFO: template[/etc/postgresql/9.3/main/postgresql.conf] updated content

[2014-04-12T07:51:48+00:00] INFO: template[/etc/postgresql/9.3/main/postgresql.conf] updated content
DEBUG ssh: stdout: [2014-04-12T07:51:48+00:00] INFO: template[/etc/postgresql/9.3/main/postgresql.conf] owner changed to 107

 INFO interface: info: [2014-04-12T07:51:48+00:00] INFO: template[/etc/postgresql/9.3/main/postgresql.conf] owner changed to 107

[2014-04-12T07:51:48+00:00] INFO: template[/etc/postgresql/9.3/main/postgresql.conf] owner changed to 107
DEBUG ssh: stdout: [2014-04-12T07:51:48+00:00] INFO: template[/etc/postgresql/9.3/main/postgresql.conf] group changed to 113

 INFO interface: info: [2014-04-12T07:51:48+00:00] INFO: template[/etc/postgresql/9.3/main/postgresql.conf] group changed to 113

[2014-04-12T07:51:48+00:00] INFO: template[/etc/postgresql/9.3/main/postgresql.conf] group changed to 113
DEBUG ssh: stdout: [2014-04-12T07:51:48+00:00] INFO: template[/etc/postgresql/9.3/main/postgresql.conf] mode changed to 644

 INFO interface: info: [2014-04-12T07:51:48+00:00] INFO: template[/etc/postgresql/9.3/main/postgresql.conf] mode changed to 644

[2014-04-12T07:51:48+00:00] INFO: template[/etc/postgresql/9.3/main/postgresql.conf] mode changed to 644
DEBUG ssh: stdout: [2014-04-12T07:51:48+00:00] INFO: template[/etc/postgresql/9.3/main/postgresql.conf] not queuing delayed action restart on service[postgresql] (delayed), as it's already been queued

 INFO interface: info: [2014-04-12T07:51:48+00:00] INFO: template[/etc/postgresql/9.3/main/postgresql.conf] not queuing delayed action restart on service[postgresql] (delayed), as it's already been queued

[2014-04-12T07:51:48+00:00] INFO: template[/etc/postgresql/9.3/main/postgresql.conf] not queuing delayed action restart on service[postgresql] (delayed), as it's already been queued
DEBUG ssh: stdout: [2014-04-12T07:51:48+00:00] INFO: file[/usr/sbin/policy-rc.d] backed up to /var/chef/backup/usr/sbin/policy-rc.d.chef-20140412075148

 INFO interface: info: [2014-04-12T07:51:48+00:00] INFO: file[/usr/sbin/policy-rc.d] backed up to /var/chef/backup/usr/sbin/policy-rc.d.chef-20140412075148

[2014-04-12T07:51:48+00:00] INFO: file[/usr/sbin/policy-rc.d] backed up to /var/chef/backup/usr/sbin/policy-rc.d.chef-20140412075148
DEBUG ssh: stdout: [2014-04-12T07:51:48+00:00] INFO: file[/usr/sbin/policy-rc.d] deleted file at /usr/sbin/policy-rc.d

 INFO interface: info: [2014-04-12T07:51:48+00:00] INFO: file[/usr/sbin/policy-rc.d] deleted file at /usr/sbin/policy-rc.d

[2014-04-12T07:51:48+00:00] INFO: file[/usr/sbin/policy-rc.d] deleted file at /usr/sbin/policy-rc.d
DEBUG ssh: stdout: [2014-04-12T07:51:49+00:00] INFO: service[postgresql] started

 INFO interface: info: [2014-04-12T07:51:49+00:00] INFO: service[postgresql] started

[2014-04-12T07:51:49+00:00] INFO: service[postgresql] started
DEBUG ssh: stdout: 
================================================================================
Error executing action `run` on resource 'execute[create pg user foo]'

 INFO interface: info: 
================================================================================
Error executing action `run` on resource 'execute[create pg user foo]'


================================================================================
Error executing action `run` on resource 'execute[create pg user foo]'
DEBUG ssh: stdout: ================================================================================

 INFO interface: info: ================================================================================

================================================================================
DEBUG ssh: stdout: 

Mixlib::ShellOut::ShellCommandFailed
------------------------------------
Expected process to exit with [0], but received '1'
---- Begin output of psql -c "CREATE ROLE foo SUPERUSER CREATEDB LOGIN PASSWORD 'foo'" ----
STDOUT: 
STDERR: Error: Invalid data directory
---- End output of psql -c "CREATE ROLE foo SUPERUSER CREATEDB LOGIN PASSWORD 'foo'" ----
Ran psql -c "CREATE ROLE foo SUPERUSER CREATEDB LOGIN PASSWORD 'foo'" returned 1


Resource Declaration:
---------------------
# In /tmp/vagrant-chef-2/chef-solo-1/cookbooks/postgresql/definitions/pg_user.rb

 31:     execute "create pg user #{role_name}" do
 32:       user "postgres"
 33:       command %(psql -c "CREATE ROLE #{role_sql}")
 34:       not_if role_exists, user: "postgres"
 35:     end
 36: 




 INFO interface: info: 

Mixlib::ShellOut::ShellCommandFailed
------------------------------------
Expected process to exit with [0], but received '1'
---- Begin output of psql -c "CREATE ROLE foo SUPERUSER CREATEDB LOGIN PASSWORD 'foo'" ----
STDOUT: 
STDERR: Error: Invalid data directory
---- End output of psql -c "CREATE ROLE foo SUPERUSER CREATEDB LOGIN PASSWORD 'foo'" ----
Ran psql -c "CREATE ROLE foo SUPERUSER CREATEDB LOGIN PASSWORD 'foo'" returned 1


Resource Declaration:
---------------------
# In /tmp/vagrant-chef-2/chef-solo-1/cookbooks/postgresql/definitions/pg_user.rb

 31:     execute "create pg user #{role_name}" do
 32:       user "postgres"
 33:       command %(psql -c "CREATE ROLE #{role_sql}")
 34:       not_if role_exists, user: "postgres"
 35:     end
 36: 






Mixlib::ShellOut::ShellCommandFailed
------------------------------------
Expected process to exit with [0], but received '1'
---- Begin output of psql -c "CREATE ROLE foo SUPERUSER CREATEDB LOGIN PASSWORD 'foo'" ----
STDOUT: 
STDERR: Error: Invalid data directory
---- End output of psql -c "CREATE ROLE foo SUPERUSER CREATEDB LOGIN PASSWORD 'foo'" ----
Ran psql -c "CREATE ROLE foo SUPERUSER CREATEDB LOGIN PASSWORD 'foo'" returned 1


Resource Declaration:
---------------------
# In /tmp/vagrant-chef-2/chef-solo-1/cookbooks/postgresql/definitions/pg_user.rb

 31:     execute "create pg user #{role_name}" do
 32:       user "postgres"
 33:       command %(psql -c "CREATE ROLE #{role_sql}")
 34:       not_if role_exists, user: "postgres"
 35:     end
 36: 



DEBUG ssh: stdout: Compiled Resource:
------------------
# Declared in /tmp/vagrant-chef-2/chef-solo-1/cookbooks/postgresql/definitions/pg_user.rb:31:in `block in from_file'

execute("create pg user foo") do
  params {:action=>:create, :privileges=>{:superuser=>true, :createdb=>true, :login=>true}, :password=>"foo", :name=>"foo"}
  action "run"
  retries 0
  retry_delay 2
  command "psql -c \"CREATE ROLE foo SUPERUSER CREATEDB LOGIN PASSWORD 'foo'\""
  backup 5
  returns 0
  user "postgres"
  cookbook_name :postgresql
  recipe_name "pg_user"
  not_if "psql -c "SELECT rolname FROM pg_roles WHERE rolname='foo'" | grep foo"
end




 INFO interface: info: Compiled Resource:
------------------
# Declared in /tmp/vagrant-chef-2/chef-solo-1/cookbooks/postgresql/definitions/pg_user.rb:31:in `block in from_file'

execute("create pg user foo") do
  params {:action=>:create, :privileges=>{:superuser=>true, :createdb=>true, :login=>true}, :password=>"foo", :name=>"foo"}
  action "run"
  retries 0
  retry_delay 2
  command "psql -c \"CREATE ROLE foo SUPERUSER CREATEDB LOGIN PASSWORD 'foo'\""
  backup 5
  returns 0
  user "postgres"
  cookbook_name :postgresql
  recipe_name "pg_user"
  not_if "psql -c "SELECT rolname FROM pg_roles WHERE rolname='foo'" | grep foo"
end




Compiled Resource:
------------------
# Declared in /tmp/vagrant-chef-2/chef-solo-1/cookbooks/postgresql/definitions/pg_user.rb:31:in `block in from_file'

execute("create pg user foo") do
  params {:action=>:create, :privileges=>{:superuser=>true, :createdb=>true, :login=>true}, :password=>"foo", :name=>"foo"}
  action "run"
  retries 0
  retry_delay 2
  command "psql -c \"CREATE ROLE foo SUPERUSER CREATEDB LOGIN PASSWORD 'foo'\""
  backup 5
  returns 0
  user "postgres"
  cookbook_name :postgresql
  recipe_name "pg_user"
  not_if "psql -c "SELECT rolname FROM pg_roles WHERE rolname='foo'" | grep foo"
end



DEBUG ssh: stdout: [2014-04-12T07:51:49+00:00] INFO: Running queued delayed notifications before re-raising exception

 INFO interface: info: [2014-04-12T07:51:49+00:00] INFO: Running queued delayed notifications before re-raising exception

[2014-04-12T07:51:49+00:00] INFO: Running queued delayed notifications before re-raising exception
DEBUG ssh: stdout: [2014-04-12T07:51:49+00:00] INFO: template[/etc/postgresql/9.3/main/environment] sending restart action to service[postgresql] (delayed)

 INFO interface: info: [2014-04-12T07:51:49+00:00] INFO: template[/etc/postgresql/9.3/main/environment] sending restart action to service[postgresql] (delayed)

[2014-04-12T07:51:49+00:00] INFO: template[/etc/postgresql/9.3/main/environment] sending restart action to service[postgresql] (delayed)
DEBUG ssh: stdout: [2014-04-12T07:51:49+00:00] INFO: service[postgresql] restarted

 INFO interface: info: [2014-04-12T07:51:49+00:00] INFO: service[postgresql] restarted

[2014-04-12T07:51:49+00:00] INFO: service[postgresql] restarted
DEBUG ssh: stdout: [2014-04-12T07:51:49+00:00] ERROR: Running exception handlers
[2014-04-12T07:51:49+00:00] ERROR: Exception handlers complete

 INFO interface: info: [2014-04-12T07:51:49+00:00] ERROR: Running exception handlers
[2014-04-12T07:51:49+00:00] ERROR: Exception handlers complete

[2014-04-12T07:51:49+00:00] ERROR: Running exception handlers
[2014-04-12T07:51:49+00:00] ERROR: Exception handlers complete
DEBUG ssh: stdout: [2014-04-12T07:51:49+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
[2014-04-12T07:51:49+00:00] FATAL: Mixlib::ShellOut::ShellCommandFailed: execute[create pg user foo] (postgresql::pg_user line 31) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '1'
---- Begin output of psql -c "CREATE ROLE foo SUPERUSER CREATEDB LOGIN PASSWORD 'foo'" ----
STDOUT: 
STDERR: Error: Invalid data directory
---- End output of psql -c "CREATE ROLE foo SUPERUSER CREATEDB LOGIN PASSWORD 'foo'" ----
Ran psql -c "CREATE ROLE foo SUPERUSER CREATEDB LOGIN PASSWORD 'foo'" returned 1

 INFO interface: info: [2014-04-12T07:51:49+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
[2014-04-12T07:51:49+00:00] FATAL: Mixlib::ShellOut::ShellCommandFailed: execute[create pg user foo] (postgresql::pg_user line 31) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '1'
---- Begin output of psql -c "CREATE ROLE foo SUPERUSER CREATEDB LOGIN PASSWORD 'foo'" ----
STDOUT: 
STDERR: Error: Invalid data directory
---- End output of psql -c "CREATE ROLE foo SUPERUSER CREATEDB LOGIN PASSWORD 'foo'" ----
Ran psql -c "CREATE ROLE foo SUPERUSER CREATEDB LOGIN PASSWORD 'foo'" returned 1

[2014-04-12T07:51:49+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
[2014-04-12T07:51:49+00:00] FATAL: Mixlib::ShellOut::ShellCommandFailed: execute[create pg user foo] (postgresql::pg_user line 31) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '1'
---- Begin output of psql -c "CREATE ROLE foo SUPERUSER CREATEDB LOGIN PASSWORD 'foo'" ----
STDOUT: 
STDERR: Error: Invalid data directory
---- End output of psql -c "CREATE ROLE foo SUPERUSER CREATEDB LOGIN PASSWORD 'foo'" ----
Ran psql -c "CREATE ROLE foo SUPERUSER CREATEDB LOGIN PASSWORD 'foo'" returned 1
DEBUG ssh: Exit status: 1
ERROR warden: Error occurred: Chef never successfully completed! Any errors should be visible in the
output above. Please fix your recipes so that they properly complete.
 INFO warden: Beginning recovery process...
 INFO warden: Recovery complete.
ERROR warden: Error occurred: Chef never successfully completed! Any errors should be visible in the
output above. Please fix your recipes so that they properly complete.
 INFO warden: Beginning recovery process...
 INFO warden: Recovery complete.
 INFO warden: Beginning recovery process...
 INFO warden: Recovery complete.
 INFO warden: Beginning recovery process...
 INFO warden: Recovery complete.
 INFO warden: Beginning recovery process...
 INFO warden: Recovery complete.
 INFO warden: Beginning recovery process...
 INFO warden: Recovery complete.
 INFO warden: Beginning recovery process...
 INFO warden: Recovery complete.
 INFO warden: Beginning recovery process...
 INFO warden: Recovery complete.
 INFO warden: Beginning recovery process...
 INFO warden: Recovery complete.
 INFO warden: Beginning recovery process...
 INFO warden: Recovery complete.
ERROR warden: Error occurred: Chef never successfully completed! Any errors should be visible in the
output above. Please fix your recipes so that they properly complete.
 INFO warden: Beginning recovery process...
 INFO warden: Recovery complete.
ERROR warden: Error occurred: Chef never successfully completed! Any errors should be visible in the
output above. Please fix your recipes so that they properly complete.
 INFO warden: Beginning recovery process...
 INFO warden: Calling recover: #<Vagrant::Action::Builtin::Call:0x00000101906c38>
 INFO warden: Beginning recovery process...
 INFO warden: Recovery complete.
 INFO warden: Recovery complete.
ERROR warden: Error occurred: Chef never successfully completed! Any errors should be visible in the
output above. Please fix your recipes so that they properly complete.
 INFO warden: Beginning recovery process...
 INFO warden: Recovery complete.
ERROR warden: Error occurred: Chef never successfully completed! Any errors should be visible in the
output above. Please fix your recipes so that they properly complete.
 INFO warden: Beginning recovery process...
 INFO warden: Calling recover: #<Vagrant::Action::Builtin::Call:0x00000100c7d7a0>
 INFO warden: Beginning recovery process...
 INFO warden: Recovery complete.
 INFO warden: Recovery complete.
ERROR warden: Error occurred: Chef never successfully completed! Any errors should be visible in the
output above. Please fix your recipes so that they properly complete.
 INFO warden: Beginning recovery process...
 INFO warden: Recovery complete.
ERROR warden: Error occurred: Chef never successfully completed! Any errors should be visible in the
output above. Please fix your recipes so that they properly complete.
 INFO warden: Beginning recovery process...
 INFO warden: Calling recover: #<Vagrant::Action::Builtin::Call:0x00000104527da8>
 INFO warden: Beginning recovery process...
 INFO warden: Recovery complete.
 INFO warden: Calling recover: #<Vagrant::Action::Builtin::Call:0x00000104527e98>
 INFO warden: Beginning recovery process...
 INFO warden: Calling recover: #<Vagrant::Action::Builtin::Call:0x0000010425a7b0>
 INFO warden: Beginning recovery process...
 INFO warden: Recovery complete.
 INFO warden: Calling recover: #<Vagrant::Action::Builtin::Call:0x0000010425a8a0>
 INFO warden: Beginning recovery process...
 INFO warden: Recovery complete.
 INFO warden: Recovery complete.
 INFO warden: Recovery complete.
 INFO warden: Beginning recovery process...
 INFO warden: Recovery complete.
 INFO warden: Beginning recovery process...
 INFO warden: Recovery complete.
 INFO warden: Beginning recovery process...
 INFO warden: Recovery complete.
 INFO warden: Beginning recovery process...
 INFO warden: Recovery complete.
 INFO warden: Beginning recovery process...
 INFO warden: Recovery complete.
 INFO warden: Beginning recovery process...
 INFO warden: Recovery complete.
 INFO warden: Beginning recovery process...
 INFO warden: Recovery complete.
 INFO warden: Beginning recovery process...
 INFO warden: Recovery complete.
 INFO warden: Beginning recovery process...
 INFO warden: Recovery complete.
 INFO warden: Beginning recovery process...
 INFO warden: Recovery complete.
 INFO warden: Beginning recovery process...
 INFO warden: Recovery complete.
ERROR warden: Error occurred: Chef never successfully completed! Any errors should be visible in the
output above. Please fix your recipes so that they properly complete.
 INFO warden: Beginning recovery process...
 INFO warden: Recovery complete.
ERROR warden: Error occurred: Chef never successfully completed! Any errors should be visible in the
output above. Please fix your recipes so that they properly complete.
 INFO warden: Beginning recovery process...
 INFO warden: Calling recover: #<Vagrant::Action::Builtin::Call:0x00000102998b28>
 INFO warden: Beginning recovery process...
 INFO warden: Recovery complete.
 INFO warden: Recovery complete.
 INFO warden: Beginning recovery process...
 INFO warden: Recovery complete.
 INFO environment: Running hook: environment_unload
 INFO runner: Preparing hooks for middleware sequence...
 INFO runner: 3 hooks defined.
 INFO runner: Running action: #<Vagrant::Action::Builder:0x000001046fe820>
ERROR vagrant: Vagrant experienced an error! Details:
ERROR vagrant: #<VagrantPlugins::Chef::Provisioner::Base::ChefError: Chef never successfully completed! Any errors should be visible in the
output above. Please fix your recipes so that they properly complete.>
ERROR vagrant: Chef never successfully completed! Any errors should be visible in the
output above. Please fix your recipes so that they properly complete.
ERROR vagrant: /Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/plugins/provisioners/chef/provisioner/chef_solo.rb:187:in `run_chef_solo'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/plugins/provisioners/chef/provisioner/chef_solo.rb:54:in `provision'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/action/builtin/provision.rb:89:in `run_provisioner'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/action/warden.rb:95:in `call'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/action/warden.rb:95:in `block in finalize_action'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/action/warden.rb:34:in `call'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/action/warden.rb:34:in `call'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/action/builder.rb:116:in `call'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/action/runner.rb:69:in `block in run'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/util/busy.rb:19:in `busy'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/action/runner.rb:69:in `run'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/environment.rb:283:in `hook'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/action/builtin/provision.rb:74:in `call'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/action/builtin/provision.rb:74:in `block in call'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/action/builtin/provision.rb:65:in `each'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/action/builtin/provision.rb:65:in `call'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/action/warden.rb:34:in `call'
/Users/michal.knapik/.vagrant.d/gems/gems/vagrant-chef-zero-0.6.0/lib/vagrant-chef-zero/action/upload.rb:23:in `call'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/action/warden.rb:34:in `call'
/Users/michal.knapik/.vagrant.d/gems/gems/vagrant-chef-zero-0.6.0/lib/vagrant-chef-zero/action/start.rb:17:in `call'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/action/warden.rb:34:in `call'
/Users/michal.knapik/.vagrant.d/gems/gems/vagrant-chef-zero-0.6.0/lib/vagrant-chef-zero/action/upload.rb:23:in `call'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/action/warden.rb:34:in `call'
/Users/michal.knapik/.vagrant.d/gems/gems/vagrant-chef-zero-0.6.0/lib/vagrant-chef-zero/action/start.rb:17:in `call'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/action/warden.rb:34:in `call'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/plugins/providers/virtualbox/action/clear_forwarded_ports.rb:13:in `call'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/action/warden.rb:34:in `call'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/plugins/providers/virtualbox/action/set_name.rb:19:in `call'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/action/warden.rb:34:in `call'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/plugins/providers/virtualbox/action/clean_machine_folder.rb:17:in `call'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/action/warden.rb:34:in `call'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/plugins/providers/virtualbox/action/check_accessible.rb:18:in `call'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/action/warden.rb:34:in `call'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/action/warden.rb:95:in `block in finalize_action'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/action/warden.rb:34:in `call'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/action/warden.rb:34:in `call'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/action/builder.rb:116:in `call'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/action/runner.rb:69:in `block in run'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/util/busy.rb:19:in `busy'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/action/runner.rb:69:in `run'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/action/builtin/call.rb:51:in `call'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/action/warden.rb:34:in `call'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/action/warden.rb:95:in `block in finalize_action'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/action/warden.rb:34:in `call'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/action/warden.rb:34:in `call'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/action/builder.rb:116:in `call'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/action/runner.rb:69:in `block in run'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/util/busy.rb:19:in `busy'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/action/runner.rb:69:in `run'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/action/builtin/call.rb:51:in `call'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/action/warden.rb:34:in `call'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/action/warden.rb:95:in `block in finalize_action'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/action/warden.rb:34:in `call'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/action/warden.rb:34:in `call'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/action/builder.rb:116:in `call'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/action/runner.rb:69:in `block in run'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/util/busy.rb:19:in `busy'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/action/runner.rb:69:in `run'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/action/builtin/call.rb:51:in `call'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/action/warden.rb:34:in `call'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/action/builtin/config_validate.rb:25:in `call'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/action/warden.rb:34:in `call'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/plugins/providers/virtualbox/action/check_virtualbox.rb:17:in `call'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/action/warden.rb:34:in `call'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/action/builtin/call.rb:57:in `call'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/action/warden.rb:34:in `call'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/plugins/providers/virtualbox/action/check_virtualbox.rb:17:in `call'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/action/warden.rb:34:in `call'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/action/builtin/config_validate.rb:25:in `call'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/action/warden.rb:34:in `call'
/Users/michal.knapik/.vagrant.d/gems/gems/vagrant-chef-zero-0.6.0/lib/vagrant-chef-zero/action/reconfig.rb:33:in `call'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/action/warden.rb:34:in `call'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/action/builtin/env_set.rb:19:in `call'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/action/warden.rb:34:in `call'
/Users/michal.knapik/.vagrant.d/gems/gems/vagrant-berkshelf-1.3.7/lib/berkshelf/vagrant/action/configure_chef.rb:23:in `call'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/action/warden.rb:34:in `call'
/Users/michal.knapik/.vagrant.d/gems/gems/vagrant-berkshelf-1.3.7/lib/berkshelf/vagrant/action/load_shelf.rb:28:in `call'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/action/warden.rb:34:in `call'
/Users/michal.knapik/.vagrant.d/gems/gems/vagrant-berkshelf-1.3.7/lib/berkshelf/vagrant/action/set_ui.rb:12:in `call'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/action/warden.rb:34:in `call'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/action/builtin/env_set.rb:19:in `call'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/action/warden.rb:34:in `call'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/action/warden.rb:95:in `block in finalize_action'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/action/warden.rb:34:in `call'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/action/warden.rb:34:in `call'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/action/builder.rb:116:in `call'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/action/runner.rb:69:in `block in run'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/util/busy.rb:19:in `busy'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/action/runner.rb:69:in `run'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/action/builtin/call.rb:51:in `call'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/action/warden.rb:34:in `call'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/plugins/providers/virtualbox/action/check_virtualbox.rb:17:in `call'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/action/warden.rb:34:in `call'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/action/builder.rb:116:in `call'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/action/runner.rb:69:in `block in run'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/util/busy.rb:19:in `busy'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/action/runner.rb:69:in `run'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/machine.rb:147:in `action'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/plugins/commands/reload/command.rb:37:in `block in execute'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/plugin/v2/command.rb:193:in `block in with_target_vms'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/plugin/v2/command.rb:191:in `each'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/plugin/v2/command.rb:191:in `with_target_vms'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/plugins/commands/reload/command.rb:36:in `execute'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/cli.rb:38:in `execute'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/environment.rb:484:in `cli'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/bin/vagrant:127:in `<top (required)>'
/Applications/Vagrant/bin/../embedded/gems/bin/vagrant:23:in `load'
/Applications/Vagrant/bin/../embedded/gems/bin/vagrant:23:in `<main>'
 INFO interface: error: Chef never successfully completed! Any errors should be visible in the
output above. Please fix your recipes so that they properly complete.
Chef never successfully completed! Any errors should be visible in the
output above. Please fix your recipes so that they properly complete.

Potentially does not work with Ubuntu 13.10

Here's the chef-client dump when I tried to use this cookbook:

I'm still inexperienced with chef but this is the first time I've seen this type of error.

Recipe: postgresql::apt_repository
  * package[pgdg-keyring] action install
    * No version specified, and no candidate version available for pgdg-keyring
================================================================================
Error executing action `install` on resource 'package[pgdg-keyring]'
================================================================================


Chef::Exceptions::Package
-------------------------
No version specified, and no candidate version available for pgdg-keyring


Resource Declaration:
---------------------
# In /var/chef/cache/cookbooks/postgresql/recipes/apt_repository.rb

 17: package "pgdg-keyring"



Compiled Resource:
------------------
# Declared in /var/chef/cache/cookbooks/postgresql/recipes/apt_repository.rb:17:in `from_file'

package("pgdg-keyring") do
  action :install
  retries 0
  retry_delay 2
  package_name "pgdg-keyring"
  cookbook_name "postgresql"
  recipe_name "apt_repository"
end



[2014-01-02T11:02:51-05:00] ERROR: Running exception handlers
[2014-01-02T11:02:51-05:00] ERROR: Exception handlers complete
[2014-01-02T11:02:51-05:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
Chef Client failed. 11 resources updated
[2014-01-02T11:02:52-05:00] ERROR: package[pgdg-keyring] (postgresql::apt_repository line 17) had an error: Chef::Exceptions::Package: No version specified, and no candidate version available for pgdg-keyring
[2014-01-02T11:02:52-05:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)

How to include libpq-dev

I have some issues deploying an app after cooking a server. Is there some what to include: libpq-dev for ubuntu as a dependency?

Error executing action `add` on resource 'apt_repository[apt.postgresql.org]'

My setup: Vagrant, Vagrant-Librarian, Precise32 and I'm facing the following error:

================================================================================

Error executing action `add` on resource 'apt_repository[apt.postgresql.org]'

================================================================================


RuntimeError

------------

The repository file to create is nil, cannot continue.


Cookbook Trace:

---------------

/tmp/vagrant-chef-1/chef-solo-1/cookbooks/apt/providers/repository.rb:127:in `class_from_file'

Resource Declaration:
---------------------
# In /tmp/vagrant-chef-1/chef-solo-1/cookbooks/postgresql/recipes/apt_repository.rb

  7: # use `apt.postgresql.org` for primary package installation support
  8: apt_repository "apt.postgresql.org" do
  9:   uri "http://apt.postgresql.org/pub/repos/apt"
 10:   distribution "#{node["lsb"]["codename"]}-pgdg"
 11:   components ["main"]
 12:   key "http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc"
 13:   action :add
 14: end
 15: 

Compiled Resource:
------------------
# Declared in /tmp/vagrant-chef-1/chef-solo-1/cookbooks/postgresql/recipes/apt_repository.rb:8:in `from_file'

apt_repository("apt.postgresql.org") do
  uri "http://apt.postgresql.org/pub/repos/apt"
  retry_delay 2
  components ["main"]
  retries 0
  recipe_name "apt_repository"
  distribution "precise-pgdg"
  action [:add]
  cookbook_name :postgresql
  key "http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc"
end

[2013-02-18T21:03:53+00:00] ERROR: Running exception handlers
[2013-02-18T21:03:53+00:00] ERROR: Exception handlers complete
[2013-02-18T21:03:53+00:00] FATAL: Stacktrace dumped to /tmp/vagrant-chef-1/chef-stacktrace.out
[2013-02-18T21:03:53+00:00] FATAL: RuntimeError: apt_repository[apt.postgresql.org] (postgresql::apt_repository line 8) had an error: RuntimeError: The repository file to create is nil, cannot continue.

Postgis doesn't work with 9.2 on ubuntu 12.04 by default

I've spent a while looking for a solution to this, as far as I can tell there isn't a version of postgis built against the backported postgresl-9.2 for precise, otherwise I'd submit a pull request.

I'm really not sure what to do about this, currently I'm using a in house cookbook for installing postgis (packaged using fpm) which works, however it isn't a very clean solution.

Posting this on the off-chance someone finds a solution and feels like sharing =)

Restart not supported.

As of the new update about half an hour ago, the following code breaks (that used to work):

include_recipe 'postgresql::server'
include_recipe 'postgresql::server-dev'
include_recipe 'postgresql::client'

# Explicitly restart PostgreSQL at this point.
# This is required because although the proper permissions have
#   been written, they don't actually take effect until a restart.
service 'postgresql' do
  action :restart
end

I tried adding include_recipe 'postgresql::service' before it...no dice. :(

posgresql::pg_user freezes

Im using knife-solo to setup my machines.

When adding a user to the database through attributes it freezes here:

Recipe: postgresql::pg_user
  * execute[alter pg user loovin] action runPassword:

My role looks like this:

{
  "name":"Developer",
  "chef_type":"role",
  "json_class":"Chef::Role",
  "default_attributes":{
    "postgresql":{
      "users":[ { "username":"developer", "password":"password", "superuser":true, "createdb":true, "login":true } ],
      "pg_hba": [ { "type":"local", "db":"all", "user":"postgres","addr":"", "method":"md5" } ],
      "postgis": [ { "version" : "2.1" } ],
      "version": "9.3",
      "port": 5432
    },
    "rvm": {
      "user_installs":[ {"user": "vagrant","default_ruby":"2.0.0","rubies":["2.0.0"] } ]
    }
  }
}

Chef version: 11.10.4

Opsworks incompatibility

So this is a long shot, but I figured I'd check in...

I'm experimenting with AWS Opsworks. I've got a local vagrant setup that wraps postgresql and works without issue. However, when applying the cookbooks as part of an opsworks layer, the bootstrap fails. My initial impression is that there's some sort of namespace conflict, but as yet I haven't uncovered it.

Specifically, the failure occurs when including postgresql::server. The stack trace looks like this: http://hastebin.com/quyugijeta. The short version is:

package("autofs") do
retries 0
cookbook_name :opsworks_initial_setup
recipe_name "autofs"
package_name "autofs"
action :install
retry_delay 2
end
================================================================================
Error executing action `run` on resource 'ruby_blockCompile Custom OpsWorks Run List'
================================================================================
NameError
packageautofs (opsworks_initial_setup::autofs line 1) had an error: NameError: Cannot find a resource for action_restart on ubuntu version 12.04

The opsworks recipe is here, but I suspect this might be something inherited from further upstream: https://github.com/aws/opsworks-cookbooks/blob/master-chef-11.4/opsworks_initial_setup/recipes/autofs.rb

In any case, I think the issue is likely opsworks related given my testing thus far, but I figured I'd throw it out there and see if the stack trace led you to some eureka moment that might help me get it working ;)

Cheers,
-Grant

Cookbook postgresql not found.

Hi, not sure where I'm going wrong, but I've the following:

Berksfile
cookbook 'chef-postgresql', git: '[email protected]:phlipper/chef-postgresql.git'

metadata.rb
depends "chef-postgresql"

and then in my recipe file
include_recipe "postgresql::server"

I'm using vagrant, chef-solo, debian or ubuntu, ruby1.9.1-dev, Chef 11.6.2 Omnibus package.

and get the error:

Recipe Compile Error in /tmp/vagrant-chef-1/chef-solo-1/cookbooks/shift72-chef/recipes/database.rb
================================================================================


Chef::Exceptions::CookbookNotFound
----------------------------------
Cookbook postgresql not found. If you're loading postgresql from another cookbook, make sure you configure the dependency in your metadata


Cookbook Trace:
---------------
  /tmp/vagrant-chef-1/chef-solo-1/cookbooks/shift72-chef/recipes/database.rb:7:in `from_file'


Relevant File Content:
----------------------
/tmp/vagrant-chef-1/chef-solo-1/cookbooks/shift72-chef/recipes/database.rb:

  1:  # Cookbook Name:: shift72-chef
  2:  # Recipe:: database
  3:  #
  4:  # Install postgres
  5:  #
  6:
  7>> include_recipe "postgresql::server"
  8:

cheers!

Unable to use pg::contrib due to version string changing?

this is the error I'm getting:

[Fri, 02 Nov 2012 23:04:15 +0100] INFO: Processing package[postgresql-client-9.2] action install (postgresql::client line 8)
[Fri, 02 Nov 2012 23:04:15 +0100] ERROR: package[postgresql-client-9.2] (postgresql::client line 8) has had an error
[Fri, 02 Nov 2012 23:04:15 +0100] ERROR: package[postgresql-client-9.2] (/tmp/vagrant-chef-1/chef-solo-1/cookbooks/postgresql/recipes/client.rb:8:in `from_file') had an error:
package[postgresql-client-9.2] (postgresql::client line 8) had an error: Chef::Exceptions::Exec: apt-get -q -y install postgresql-client-9.2=9.2.1-1~lucid1 returned 100, expected 0
/opt/vagrant_ruby/lib/ruby/gems/1.8/gems/chef-0.10.10/bin/../lib/chef/mixin/command.rb:128:in `handle_command_failures'
/opt/vagrant_ruby/lib/ruby/gems/1.8/gems/chef-0.10.10/bin/../lib/chef/mixin/command.rb:75:in `run_command'
/opt/vagrant_ruby/lib/ruby/gems/1.8/gems/chef-0.10.10/bin/../lib/chef/mixin/command.rb:143:in `run_command_with_systems_locale'
/opt/vagrant_ruby/lib/ruby/gems/1.8/gems/chef-0.10.10/bin/../lib/chef/provider/package/apt.rb:94:in `install_package'
/opt/vagrant_ruby/lib/ruby/gems/1.8/gems/chef-0.10.10/bin/../lib/chef/provider/package.rb:59:in `action_install'
/opt/vagrant_ruby/lib/ruby/gems/1.8/gems/chef-0.10.10/bin/../lib/chef/resource.rb:454:in `send'
/opt/vagrant_ruby/lib/ruby/gems/1.8/gems/chef-0.10.10/bin/../lib/chef/resource.rb:454:in `run_action'
/opt/vagrant_ruby/lib/ruby/gems/1.8/gems/chef-0.10.10/bin/../lib/chef/runner.rb:49:in `run_action'
/opt/vagrant_ruby/lib/ruby/gems/1.8/gems/chef-0.10.10/bin/../lib/chef/runner.rb:85:in `converge'
/opt/vagrant_ruby/lib/ruby/gems/1.8/gems/chef-0.10.10/bin/../lib/chef/runner.rb:85:in `each'
/opt/vagrant_ruby/lib/ruby/gems/1.8/gems/chef-0.10.10/bin/../lib/chef/runner.rb:85:in `converge'
/opt/vagrant_ruby/lib/ruby/gems/1.8/gems/chef-0.10.10/bin/../lib/chef/resource_collection.rb:94:in `execute_each_resource'
/opt/vagrant_ruby/lib/ruby/gems/1.8/gems/chef-0.10.10/bin/../lib/chef/resource_collection/stepable_iterator.rb:116:in `call'
/opt/vagrant_ruby/lib/ruby/gems/1.8/gems/chef-0.10.10/bin/../lib/chef/resource_collection/stepable_iterator.rb:116:in `call_iterator_block'
/opt/vagrant_ruby/lib/ruby/gems/1.8/gems/chef-0.10.10/bin/../lib/chef/resource_collection/stepable_iterator.rb:85:in `step'
/opt/vagrant_ruby/lib/ruby/gems/1.8/gems/chef-0.10.10/bin/../lib/chef/resource_collection/stepable_iterator.rb:104:in `iterate'
/opt/vagrant_ruby/lib/ruby/gems/1.8/gems/chef-0.10.10/bin/../lib/chef/resource_collection/stepable_iterator.rb:55:in `each_with_index'
/opt/vagrant_ruby/lib/ruby/gems/1.8/gems/chef-0.10.10/bin/../lib/chef/resource_collection.rb:92:in `execute_each_resource'
/opt/vagrant_ruby/lib/ruby/gems/1.8/gems/chef-0.10.10/bin/../lib/chef/runner.rb:80:in `converge'
/opt/vagrant_ruby/lib/ruby/gems/1.8/gems/chef-0.10.10/bin/../lib/chef/client.rb:330:in `converge'
/opt/vagrant_ruby/lib/ruby/gems/1.8/gems/chef-0.10.10/bin/../lib/chef/client.rb:163:in `run'
/opt/vagrant_ruby/lib/ruby/gems/1.8/gems/chef-0.10.10/bin/../lib/chef/application/solo.rb:207:in `run_application'
/opt/vagrant_ruby/lib/ruby/gems/1.8/gems/chef-0.10.10/bin/../lib/chef/application/solo.rb:195:in `loop'
/opt/vagrant_ruby/lib/ruby/gems/1.8/gems/chef-0.10.10/bin/../lib/chef/application/solo.rb:195:in `run_application'
/opt/vagrant_ruby/lib/ruby/gems/1.8/gems/chef-0.10.10/bin/../lib/chef/application.rb:70:in `run'
/opt/vagrant_ruby/lib/ruby/gems/1.8/gems/chef-0.10.10/bin/chef-solo:25
/opt/vagrant_ruby/bin/chef-solo:19:in `load'
/opt/vagrant_ruby/bin/chef-solo:19
[Fri, 02 Nov 2012 23:04:15 +0100] ERROR: Running exception handlers
[Fri, 02 Nov 2012 23:04:15 +0100] ERROR: Exception handlers complete
[Fri, 02 Nov 2012 23:04:15 +0100] FATAL: Stacktrace dumped to /tmp/vagrant-chef-1/chef-stacktrace.out
[Fri, 02 Nov 2012 23:04:15 +0100] FATAL: Chef::Exceptions::Exec: package[postgresql-client-9.2] (postgresql::client line 8) had an error: Chef::Exceptions::Exec: apt-get -q -y install postgresql-client-9.2=9.2.1-1~lucid1 returned 100, expected 0
Chef never successfully completed! Any errors should be visible in the
output above. Please fix your recipes so that they properly complete.

I think what's happening is the version is getting set to something funky... I'm investigating, but hoping you might have an idea off the top of your head @phlipper

changing data directory causes issue on ubuntu

When apt-get installs the postgres server package on ubuntu, it automatically starts the server. It is only after the server is started that the the rest of the config is generated by this cookbook. The problem then occurs that if you change the data directory, postgres will fail to restart because it's looking for the pid file in the new data directory, which doesn't exist.

This is causing my deploys to fail. I'm not sure of a clean way to resolve it.

Can't start 9.2 after install

I'm getting this error after running this cookbook:

2013-01-29T21:44:59-02:00] FATAL: Mixlib::ShellOut::ShellCommandFailed: service[postgresql] (postgresql::server line 91) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '1'
---- Begin output of /etc/init.d/postgresql restart ----
STDOUT: * Restarting PostgreSQL 9.2 database server
 * The PostgreSQL server failed to start. Please check the log output:
2013-01-29 23:44:59 GMT FATAL:  could not load server certificate file "server.crt": No such file or directory
   ...fail!
STDERR: 
---- End output of /etc/init.d/postgresql restart ----
Ran /etc/init.d/postgresql restart returned 1

If I purge everything and simply apt-get install postgresql-9.2 it works. Very strange.
I'm using ubuntu 12.10. I dont know if this is a bug in this recipe but any help will be appreciated! =)

Version in .ruby-version is causing isue when using berkshelf to upload cookbook to Chef server

I have included this cookbook as a dependency in a wrapper cookbook. I am trying to use Berkshelf 3.1.3 to run a berks upload to upload my wrapper cookbook and all of it's dependencies to the Chef Server. However, when Berkshefl gets to this cookbook it spits out an error:

E, [2014-09-23T17:59:24.582763 #12389] ERROR -- : Cookbook file attributes/default.rb has a ruby syntax error:
E, [2014-09-23T17:59:24.582875 #12389] ERROR -- : rbenv: version `1.9.3' is not installed
E, [2014-09-23T17:59:24.582908 #12389] ERROR -- : rbenv: version `1.9.3' is not installed
E, [2014-09-23T17:59:24.586324 #12389] ERROR -- : Ridley::Errors::CookbookSyntaxError: Invalid ruby files in cookbook: postgresql (0.14.1).
E, [2014-09-23T17:59:24.587552 #12389] ERROR -- : /opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/ridley-4.0.0/lib/ridley/chef/cookbook.rb:198:in `validate'

I manually opened up the cookbook that Berkshelf had in it's cache, and updated the .ruby-version file to one of the version that I had available in the rbenv repo (in my case 1.9.3-p545), and Berkshelf stopped complaining.

It odes not appear that there is a plain 1.9.3 version even available in the rbenv repo. Here are all the 1.9.3 builds available:

  1.9.3-dev
  1.9.3-p0
  1.9.3-p125
  1.9.3-p194
  1.9.3-p286
  1.9.3-p327
  1.9.3-p362
  1.9.3-p374
  1.9.3-p385
  1.9.3-p392
  1.9.3-p429
  1.9.3-p448
  1.9.3-p484
  1.9.3-p545
  1.9.3-preview1
  1.9.3-rc1

If this cookbook is going to lock itself to 1.9.3, perhaps it should be locked to a build that is available via rbenv

Syntax error in definitions files

While using 0.12.0 in a recipe under Chef Solo, I encountered the following errors. These errors don't occur using 0.11.3.

Recipe Compile Error in /tmp/chef-solo/site-cookbooks/postgresql/definitions/pg_database.rb

SyntaxError

compile error
/tmp/chef-solo/site-cookbooks/postgresql/definitions/pg_database.rb:1: syntax error, unexpected ':', expecting $end
define :pg_database, action: :create do
^

Cookbook Trace:

/tmp/chef-solo/site-cookbooks/postgresql/definitions/pg_database.rb:1:in from_file' /usr/lib/ruby/vendor_ruby/chef/run_context.rb:207:inload_resource_definitions'
/usr/lib/ruby/vendor_ruby/chef/run_context.rb:230:in call' /usr/lib/ruby/vendor_ruby/chef/run_context.rb:230:inforeach_cookbook_load_segment'
/usr/lib/ruby/vendor_ruby/chef/run_context.rb:229:in each' /usr/lib/ruby/vendor_ruby/chef/run_context.rb:229:inforeach_cookbook_load_segment'
/usr/lib/ruby/vendor_ruby/chef/run_context.rb:227:in each' /usr/lib/ruby/vendor_ruby/chef/run_context.rb:227:inforeach_cookbook_load_segment'
/usr/lib/ruby/vendor_ruby/chef/run_context.rb:203:in load_resource_definitions' /usr/lib/ruby/vendor_ruby/chef/run_context.rb:66:inload'
/usr/lib/ruby/vendor_ruby/chef/client.rb:198:in setup_run_context' /usr/lib/ruby/vendor_ruby/chef/client.rb:418:indo_run'
/usr/lib/ruby/vendor_ruby/chef/client.rb:176:in run' /usr/lib/ruby/vendor_ruby/chef/application.rb:140:inrun_chef_client'
/usr/lib/ruby/vendor_ruby/chef/application/solo.rb:224:in run_application' /usr/lib/ruby/vendor_ruby/chef/application/solo.rb:216:inloop'
/usr/lib/ruby/vendor_ruby/chef/application/solo.rb:216:in run_application' /usr/lib/ruby/vendor_ruby/chef/application.rb:72:inrun'
/usr/bin/chef-solo:24

Relevant File Content:

/tmp/chef-solo/site-cookbooks/postgresql/definitions/pg_database.rb:

1>> define :pg_database, action: :create do
2:
3: defaults = {
4: user: "postgres",
5: username: nil,
6: host: nil,
7: port: nil,
8: encoding: "utf8",
9: locale: nil,
10: template: nil,

Recipe Compile Error in /tmp/chef-solo/site-cookbooks/postgresql/definitions/pg_database_extensions.rb

SyntaxError

compile error
/tmp/chef-solo/site-cookbooks/postgresql/definitions/pg_database_extensions.rb:1: syntax error, unexpected ':', expecting $end
define :pg_database_extensions, action: :create do
^

Cookbook Trace:

/tmp/chef-solo/site-cookbooks/postgresql/definitions/pg_database_extensions.rb:1:in from_file' /usr/lib/ruby/vendor_ruby/chef/run_context.rb:207:inload_resource_definitions'
/usr/lib/ruby/vendor_ruby/chef/run_context.rb:230:in call' /usr/lib/ruby/vendor_ruby/chef/run_context.rb:230:inforeach_cookbook_load_segment'
/usr/lib/ruby/vendor_ruby/chef/run_context.rb:229:in each' /usr/lib/ruby/vendor_ruby/chef/run_context.rb:229:inforeach_cookbook_load_segment'
/usr/lib/ruby/vendor_ruby/chef/run_context.rb:227:in each' /usr/lib/ruby/vendor_ruby/chef/run_context.rb:227:inforeach_cookbook_load_segment'
/usr/lib/ruby/vendor_ruby/chef/run_context.rb:203:in load_resource_definitions' /usr/lib/ruby/vendor_ruby/chef/run_context.rb:66:inload'
/usr/lib/ruby/vendor_ruby/chef/client.rb:198:in setup_run_context' /usr/lib/ruby/vendor_ruby/chef/client.rb:418:indo_run'
/usr/lib/ruby/vendor_ruby/chef/client.rb:176:in run' /usr/lib/ruby/vendor_ruby/chef/application.rb:140:inrun_chef_client'
/usr/lib/ruby/vendor_ruby/chef/application/solo.rb:224:in run_application' /usr/lib/ruby/vendor_ruby/chef/application/solo.rb:216:inloop'
/usr/lib/ruby/vendor_ruby/chef/application/solo.rb:216:in run_application' /usr/lib/ruby/vendor_ruby/chef/application.rb:72:inrun'
/usr/bin/chef-solo:24

Relevant File Content:

/tmp/chef-solo/site-cookbooks/postgresql/definitions/pg_database_extensions.rb:

1>> define :pg_database_extensions, action: :create do
2:
3: dbname = params[:name]
4: languages = Array(params[:languages]) # Allow single value or array of values
5: extensions = Array(params[:extensions])
6: postgis = params[:postgis]
7:
8: case params[:action]
9: when :create
10:

Recipe Compile Error in /tmp/chef-solo/site-cookbooks/postgresql/definitions/pg_user.rb

SyntaxError

compile error
/tmp/chef-solo/site-cookbooks/postgresql/definitions/pg_user.rb:1: syntax error, unexpected ':', expecting $end
define :pg_user, action: :create do
^

Cookbook Trace:

/tmp/chef-solo/site-cookbooks/postgresql/definitions/pg_user.rb:1:in from_file' /usr/lib/ruby/vendor_ruby/chef/run_context.rb:207:inload_resource_definitions'
/usr/lib/ruby/vendor_ruby/chef/run_context.rb:230:in call' /usr/lib/ruby/vendor_ruby/chef/run_context.rb:230:inforeach_cookbook_load_segment'
/usr/lib/ruby/vendor_ruby/chef/run_context.rb:229:in each' /usr/lib/ruby/vendor_ruby/chef/run_context.rb:229:inforeach_cookbook_load_segment'
/usr/lib/ruby/vendor_ruby/chef/run_context.rb:227:in each' /usr/lib/ruby/vendor_ruby/chef/run_context.rb:227:inforeach_cookbook_load_segment'
/usr/lib/ruby/vendor_ruby/chef/run_context.rb:203:in load_resource_definitions' /usr/lib/ruby/vendor_ruby/chef/run_context.rb:66:inload'
/usr/lib/ruby/vendor_ruby/chef/client.rb:198:in setup_run_context' /usr/lib/ruby/vendor_ruby/chef/client.rb:418:indo_run'
/usr/lib/ruby/vendor_ruby/chef/client.rb:176:in run' /usr/lib/ruby/vendor_ruby/chef/application.rb:140:inrun_chef_client'
/usr/lib/ruby/vendor_ruby/chef/application/solo.rb:224:in run_application' /usr/lib/ruby/vendor_ruby/chef/application/solo.rb:216:inloop'
/usr/lib/ruby/vendor_ruby/chef/application/solo.rb:216:in run_application' /usr/lib/ruby/vendor_ruby/chef/application.rb:72:inrun'
/usr/bin/chef-solo:24

Relevant File Content:

/tmp/chef-solo/site-cookbooks/postgresql/definitions/pg_user.rb:

1>> define :pg_user, action: :create do
2: case params[:action]
3: when :create
4: privileges = {
5: superuser: false,
6: createdb: false,
7: login: true
8: }
9: privileges.merge! params[:privileges] if params[:privileges]
10:

no pg_user idempotency

Hello @phlipper, your recipe is cool, but the pg_user definition doesn't seem idempotent.
So for instance with a resource declaration like

pg_user foo do
privileges superuser: false, createdb: true, login: true
end

At each run I have the following execute occurring:

  • execute[alter pg user foo] action run
    • execute psql -c "ALTER ROLE foo NOSUPERUSER CREATEDB LOGIN"

This is a detail but this is bad because ideally at the end of the run you want to know exactly what changed or not. Here you can not know.

adding encrypted password

echo -n "SomeCrazyPassword" | openssl md5 | sed -e 's/.* /md5'

doesn't seem to be the appropriate way to set the encrypted password via dsl and have it actuall work with logging in. What is the right way to do this? Or should this work?

Stop restarting postgresql service

Many of the times that the postgres server is restarted could be replaced with reloads.

Also, for a production server you may prefer to defer restarting completely and do that part by hand.

It would be good if there was a flag that allowed choosing the behavior since having a postgres server restart in the middle of your day because you changed a security rule does not seem like a good idea.

e.g. https://github.com/phlipper/chef-postgresql/blob/master/recipes/configuration.rb#L38

The pg_hba.conf file is read on start-up and when the main server process receives a SIGHUP signal. If you edit the file on an active system, you will need to signal the postmaster (using pg_ctl reload or kill -HUP) to make it re-read the file.

http://www.postgresql.org/docs/9.1/static/auth-pg-hba-conf.html

RuntimeError: The repository file to create is nil, cannot continue.

Getting the error below:

[2013-04-09T22:22:20+00:00] INFO: Processing apt_repository[apt.postgresql.org] action add (postgresql::apt_repository line 8)

================================================================================
Error executing action `add` on resource 'apt_repository[apt.postgresql.org]'
================================================================================

RuntimeError
------------
The repository file to create is nil, cannot continue.


Cookbook Trace:
---------------
/tmp/vagrant-chef-1/chef-solo-1/cookbooks/apt/providers/repository.rb:127:in `class_from_file'

Resource Declaration:
---------------------
# In /tmp/vagrant-chef-1/chef-solo-1/cookbooks/postgresql/recipes/apt_repository.rb

  7: # use `apt.postgresql.org` for primary package installation support
  8: apt_repository "apt.postgresql.org" do
  9:   uri "http://apt.postgresql.org/pub/repos/apt"
 10:   distribution "#{node["lsb"]["codename"]}-pgdg"
 11:   components ["main"]
 12:   key "http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc"
 13:   action :add
 14: end
 15: 

Compiled Resource:
------------------
# Declared in /tmp/vagrant-chef-1/chef-solo-1/cookbooks/postgresql/recipes/apt_repository.rb:8:in `from_file'

apt_repository("apt.postgresql.org") do
  uri "http://apt.postgresql.org/pub/repos/apt"
  retry_delay 2
  components ["main"]
  retries 0
  recipe_name "apt_repository"
  distribution "precise-pgdg"
  action [:add]
  cookbook_name :postgresql
  key "http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc"
end

[2013-04-09T22:22:20+00:00] ERROR: Running exception handlers
[2013-04-09T22:22:20+00:00] ERROR: Exception handlers complete
[2013-04-09T22:22:21+00:00] FATAL: Stacktrace dumped to /tmp/vagrant-chef-1/chef-stacktrace.out
[2013-04-09T22:22:21+00:00] FATAL: RuntimeError: apt_repository[apt.postgresql.org] (postgresql::apt_repository line 8) had an error: RuntimeError: The repository file to create is nil, cannot continue.

Cookbook name conflict

How can I use this cookbook alongside of community "postgresql" cookbook?
Many cookbooks depend on "postgresql" cookbook and Chef Librarian just hungs trying to resolve this conflict :(

postgres user not Superuser?

On a newly provisioned machine running pg_user, I see:

                  List of roles
 Role name |        Attributes        | Member of 
-----------+--------------------------+-----------
 postgres  | Create role, Replication | {}
 test      |                          | {}

I was expecting:

                             List of roles
 Role name |                   Attributes                   | Member of 
-----------+------------------------------------------------+-----------
 postgres  | Superuser, Create role, Create DB, Replication | {}
 test      |                                                | {}

If I do:

pg_user 'postgres' do
  privileges superuser: true, createdb: true
end

I get:

Expected process to exit with [0], but received '1'
---- Begin output of psql -c "ALTER ROLE postgres SUPERUSER CREATEDB LOGIN" ----
STDOUT: 
STDERR: ERROR:  must be superuser to alter superusers
---- End output of psql -c "ALTER ROLE postgres SUPERUSER CREATEDB LOGIN" ----
Ran psql -c "ALTER ROLE postgres SUPERUSER CREATEDB LOGIN" returned 1

My original code was this -- it failed on creating a database because postgres doesn't have permission:

include_recipe 'postgresql'
include_recipe 'postgresql::server'
include_recipe 'postgresql::client'

data_bag('pg_users').each do |user|
  password = data_bag_item('pg_users', user)['password']
  pg_user user do
    password password
  end
end

data_bag('pg_dbs').each do |db|
  owner = data_bag_item('pg_dbs', db)['admin']
  pg_database db do
    owner owner
  end
end

What am I doing wrong? Version 0.13.0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.