Update the postgresql upstream cookbook

This commit is contained in:
Greg Karékinian 2020-05-11 18:26:35 +02:00
parent 21119fff08
commit b22a7e3c0f
14 changed files with 145 additions and 59 deletions

View File

@ -30,7 +30,7 @@ cookbook 'nginx', '= 9.0.0'
# part of Chef 14 (https://docs.chef.io/resource_build_essential.html) # part of Chef 14 (https://docs.chef.io/resource_build_essential.html)
cookbook 'build-essential', '~> 8.2.1' cookbook 'build-essential', '~> 8.2.1'
cookbook 'mysql', '~> 8.5.1' cookbook 'mysql', '~> 8.5.1'
cookbook 'postgresql', '= 7.1.4' cookbook 'postgresql', '= 7.1.8'
cookbook 'apt', '~> 7.0.0' cookbook 'apt', '~> 7.0.0'
cookbook 'git', '= 6.0.0' cookbook 'git', '= 6.0.0'
cookbook 'hostsfile', '= 2.4.5' cookbook 'hostsfile', '= 2.4.5'

View File

@ -44,7 +44,7 @@ DEPENDENCIES
poise-ruby-build (~> 1.1.0) poise-ruby-build (~> 1.1.0)
poise-service (~> 1.5.2) poise-service (~> 1.5.2)
postfix (= 5.0.2) postfix (= 5.0.2)
postgresql (= 7.1.4) postgresql (= 7.1.8)
redis redis
git: https://github.com/phlipper/chef-redis.git git: https://github.com/phlipper/chef-redis.git
revision: 7476279fc9c8727f082b8d77b5e1922dc2ef437b revision: 7476279fc9c8727f082b8d77b5e1922dc2ef437b
@ -154,7 +154,7 @@ GRAPH
poise-service (1.5.2) poise-service (1.5.2)
poise (~> 2.0) poise (~> 2.0)
postfix (5.0.2) postfix (5.0.2)
postgresql (7.1.4) postgresql (7.1.8)
redis (0.5.6) redis (0.5.6)
apt (>= 0.0.0) apt (>= 0.0.0)
seven_zip (3.1.1) seven_zip (3.1.1)

View File

@ -2,34 +2,52 @@
This file is used to list changes made in the last 3 major versions of the postgresql cookbook. This file is used to list changes made in the last 3 major versions of the postgresql cookbook.
## Unreleased ## v7.1.8 (2020-02-22)
## v7.1.4 (28-03-2019) - Fix incorrect ubuntu platform family value in `postgresql_server_install`
- Re-add unit tests that were skipped
## v7.1.7 (2020-02-21)
- Correctly configure postgres-common on Ubuntu hosts (fixes #596)
## v7.1.6 (2020-02-20)
- Remove unnecessary nil default in resource properties
- Migrate to GitHub Actions for testing
## v7.1.5 (2019-11-18)
- Allow to install extensions with hyphens, ex: `postgresql_extension '"uuid-ossp"'`
- Update Circle CI config to match sous-chefs defaults #617
- Remove Fedora testing from CI, not an official supported OS by sous-chefs, PR welcome #617
## v7.1.4 (2019-03-28)
- Fix installation of extensions. - Fix installation of extensions.
## v7.1.3 (15-01-2019) ## v7.1.3 (2019-01-15)
- Added support for dash in database role name. - Added support for dash in database role name.
## v7.1.2 (06-01-2019) ## v7.1.2 (2019-06-01)
- Cleanup and update the user resource documentation and code. Removed extraneous 'sensitive' property which is a common property in all Chef resources. - Cleanup and update the user resource documentation and code. Removed extraneous 'sensitive' property which is a common property in all Chef resources.
- Change default permissions on the postgres.conf to be world readable so that psql can work. - Change default permissions on the postgres.conf to be world readable so that psql can work.
## v7.1.1 (26-09-2018) ## v7.1.1 (2018-09-26)
- Rename slave to follower - Rename slave to follower
- Use CircleCI for testing - Use CircleCI for testing
- Simplyfy extension resource - Simplyfy extension resource
## v7.1.0 (22-06-2018) ## v7.1.0 (2018-06-22)
- Update the `initdb` script to use initdb rather than a service. #542 - Update the `initdb` script to use initdb rather than a service. #542
- Refactor database commands to use the common connect method. #535 - Refactor database commands to use the common connect method. #535
- Increase the unit test coverage. - Increase the unit test coverage.
## v7.0.0 (25-05-2018) ## v7.0.0 (2018-05-25)
_Breaking Change_ Please see UPGRADING.md and the README.md for information how to use. _Breaking Change_ Please see UPGRADING.md and the README.md for information how to use.
@ -57,7 +75,7 @@ _Breaking Change_ Please see UPGRADING.md and the README.md for information how
## v6.1.2 (2018-04-16) ## v6.1.2 (2018-04-16)
**this will be the last release of the 6.0 series before all recipes are removed from the cookbook** this will be the last release of the 6.0 series before all recipes are removed from the cookbook
- Deprecate all recipes - Deprecate all recipes

View File

@ -2,10 +2,16 @@
[![Cookbook Version](https://img.shields.io/cookbook/v/postgresql.svg)](https://supermarket.chef.io/cookbooks/postgresql) [![Cookbook Version](https://img.shields.io/cookbook/v/postgresql.svg)](https://supermarket.chef.io/cookbooks/postgresql)
[![Build Status](https://img.shields.io/circleci/project/github/sous-chefs/postgresql/master.svg)](https://circleci.com/gh/sous-chefs/postgresql) [![Build Status](https://img.shields.io/circleci/project/github/sous-chefs/postgresql/master.svg)](https://circleci.com/gh/sous-chefs/postgresql)
[![pullreminders](https://pullreminders.com/badge.svg)](https://pullreminders.com?ref=badge) [![OpenCollective](https://opencollective.com/sous-chefs/backers/badge.svg)](#backers)
[![OpenCollective](https://opencollective.com/sous-chefs/sponsors/badge.svg)](#sponsors)
[![License](https://img.shields.io/badge/License-Apache%202.0-green.svg)](https://opensource.org/licenses/Apache-2.0)
Installs and configures PostgreSQL as a client or a server. Installs and configures PostgreSQL as a client or a server.
## Maintainers
This cookbook is maintained by the Sous Chefs. The Sous Chefs are a community of Chef cookbook maintainers working together to maintain important cookbooks. If youd like to know more please visit [sous-chefs.org](https://sous-chefs.org/) or come chat with us on the Chef Community Slack in [#sous-chefs](https://chefcommunity.slack.com/messages/C2V7B88SF).
## Upgrading ## Upgrading
If you are wondering where all the recipes went in v7.0+, or how on earth I use this new cookbook please see upgrading.md for a full description. If you are wondering where all the recipes went in v7.0+, or how on earth I use this new cookbook please see upgrading.md for a full description.
@ -18,7 +24,6 @@ If you are wondering where all the recipes went in v7.0+, or how on earth I use
- Debian 7+ - Debian 7+
- Ubuntu 14.04+ - Ubuntu 14.04+
- Red Hat/CentOS/Scientific 6+ - Red Hat/CentOS/Scientific 6+
- Fedora
### PostgreSQL version ### PostgreSQL version
@ -51,7 +56,7 @@ Name | Types | Description
`hba_file` | String | | `#{conf_dir}/main/pg_hba.conf` | no `hba_file` | String | | `#{conf_dir}/main/pg_hba.conf` | no
`ident_file` | String | | `#{conf_dir}/main/pg_ident.conf` | no `ident_file` | String | | `#{conf_dir}/main/pg_ident.conf` | no
`external_pid_file` | String | | `/var/run/postgresql/#{version}-main.pid` | no `external_pid_file` | String | | `/var/run/postgresql/#{version}-main.pid` | no
`password` | String, nil | Pass in a password, or have the cookbook generate one for you | <random string> | no `password` | String, nil | Pass in a password, or have the cookbook generate one for you | random string | no
#### Examples #### Examples
@ -211,14 +216,14 @@ end
This generates the following line in the `pg_hba.conf`: This generates the following line in the `pg_hba.conf`:
``` ```config
# Local postgres superuser access # Local postgres superuser access
local all postgres ident local all postgres ident
``` ```
**Note**: The template by default generates a local access for Unix domain sockets only to support running the SQL execute resources. In Postgres version 9.1 and higher, the method is 'peer' instead of 'ident' which is identical. It looks like this: **Note**: The template by default generates a local access for Unix domain sockets only to support running the SQL execute resources. In Postgres version 9.1 and higher, the method is 'peer' instead of 'ident' which is identical. It looks like this:
``` ```config
# "local" is for Unix domain socket connections only # "local" is for Unix domain socket connections only
local all all peer local all all peer
``` ```
@ -257,7 +262,7 @@ end
This generates the following line in the `pg_ident.conf`: This generates the following line in the `pg_ident.conf`:
``` ```config
# MAPNAME SYSTEM-USERNAME PG-USERNAME # MAPNAME SYSTEM-USERNAME PG-USERNAME
# John Mapping # John Mapping
@ -279,7 +284,7 @@ end
This generates the following line in the `pg_hba.conf`: This generates the following line in the `pg_hba.conf`:
``` ```config
# Local postgres superuser access # Local postgres superuser access
host all foo 127.0.0.1/32 ident host all foo 127.0.0.1/32 ident
``` ```
@ -400,34 +405,27 @@ postgresql_server_conf 'PostgreSQL Config' do
end end
``` ```
## Contributing ## Contributors
Please refer to each project's style guidelines and guidelines for submitting patches and additions. In general, we follow the "fork-and-pull" Git workflow. This project exists thanks to all the people who [contribute.](https://opencollective.com/sous-chefs/contributors.svg?width=890&button=false)
1. **Fork** the repo on GitHub ### Backers
2. **Clone** the project to your own machine
3. **Commit** changes to your own branch
4. **Push** your work back up to your fork
5. Submit a **Pull request** so that we can review your changes
NOTE: Be sure to merge the latest from "upstream" before making a pull request! Thank you to all our backers!
[Contribution informations for this project](CONTRIBUTING.md) ![https://opencollective.com/sous-chefs#backers](https://opencollective.com/sous-chefs/backers.svg?width=600&avatarHeight=40)
## License ### Sponsors
Copyright 2010-2017, Chef Software, Inc. Support this project by becoming a sponsor. Your logo will show up here with a link to your website.
```text ![https://opencollective.com/sous-chefs/sponsor/0/website](https://opencollective.com/sous-chefs/sponsor/0/avatar.svg?avatarHeight=100)
Licensed under the Apache License, Version 2.0 (the "License"); ![https://opencollective.com/sous-chefs/sponsor/1/website](https://opencollective.com/sous-chefs/sponsor/1/avatar.svg?avatarHeight=100)
you may not use this file except in compliance with the License. ![https://opencollective.com/sous-chefs/sponsor/2/website](https://opencollective.com/sous-chefs/sponsor/2/avatar.svg?avatarHeight=100)
You may obtain a copy of the License at ![https://opencollective.com/sous-chefs/sponsor/3/website](https://opencollective.com/sous-chefs/sponsor/3/avatar.svg?avatarHeight=100)
![https://opencollective.com/sous-chefs/sponsor/4/website](https://opencollective.com/sous-chefs/sponsor/4/avatar.svg?avatarHeight=100)
http://www.apache.org/licenses/LICENSE-2.0 ![https://opencollective.com/sous-chefs/sponsor/5/website](https://opencollective.com/sous-chefs/sponsor/5/avatar.svg?avatarHeight=100)
![https://opencollective.com/sous-chefs/sponsor/6/website](https://opencollective.com/sous-chefs/sponsor/6/avatar.svg?avatarHeight=100)
Unless required by applicable law or agreed to in writing, software ![https://opencollective.com/sous-chefs/sponsor/7/website](https://opencollective.com/sous-chefs/sponsor/7/avatar.svg?avatarHeight=100)
distributed under the License is distributed on an "AS IS" BASIS, ![https://opencollective.com/sous-chefs/sponsor/8/website](https://opencollective.com/sous-chefs/sponsor/8/avatar.svg?avatarHeight=100)
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ![https://opencollective.com/sous-chefs/sponsor/9/website](https://opencollective.com/sous-chefs/sponsor/9/avatar.svg?avatarHeight=100)
See the License for the specific language governing permissions and
limitations under the License.
```

View File

@ -22,7 +22,7 @@ module PostgresqlCookbook
require 'securerandom' require 'securerandom'
def psql_command_string(new_resource, query, grep_for: nil, value_only: false) def psql_command_string(new_resource, query, grep_for: nil, value_only: false)
cmd = "/usr/bin/psql -c \"#{query}\"" cmd = %(/usr/bin/psql -c "#{query}")
cmd << " -d #{new_resource.database}" if new_resource.database cmd << " -d #{new_resource.database}" if new_resource.database
cmd << " -U #{new_resource.user}" if new_resource.user cmd << " -U #{new_resource.user}" if new_resource.user
cmd << " --host #{new_resource.host}" if new_resource.host cmd << " --host #{new_resource.host}" if new_resource.host
@ -35,12 +35,12 @@ module PostgresqlCookbook
def execute_sql(new_resource, query) def execute_sql(new_resource, query)
# If we don't pass in a user to the resource # If we don't pass in a user to the resource
# default to the postgres user # default to the postgres user
user = new_resource.user ? new_resource.user : 'postgres' user = new_resource.user || 'postgres'
# Query could be a String or an Array of Strings # Query could be a String or an Array of Strings
statement = query.is_a?(String) ? query : query.join("\n") statement = query.is_a?(String) ? query : query.join("\n")
cmd = shell_out(statement, user: user) cmd = shell_out(statement, user: user, environment: psql_environment)
# Pass back cmd so we can decide what to do with it in the calling method. # Pass back cmd so we can decide what to do with it in the calling method.
cmd cmd
@ -81,7 +81,7 @@ module PostgresqlCookbook
end end
def create_extension_sql(new_resource) def create_extension_sql(new_resource)
sql = "CREATE EXTENSION IF NOT EXISTS #{new_resource.extension}" sql = %(CREATE EXTENSION IF NOT EXISTS #{new_resource.extension})
sql << " FROM \"#{new_resource.old_version}\"" if new_resource.old_version sql << " FROM \"#{new_resource.old_version}\"" if new_resource.old_version
psql_command_string(new_resource, sql) psql_command_string(new_resource, sql)
@ -213,6 +213,7 @@ module PostgresqlCookbook
"/usr/pgsql-#{new_resource.version}/bin/initdb" "/usr/pgsql-#{new_resource.version}/bin/initdb"
end end
cmd << " --locale '#{new_resource.initdb_locale}'" if new_resource.initdb_locale cmd << " --locale '#{new_resource.initdb_locale}'" if new_resource.initdb_locale
cmd << " -E '#{new_resource.initdb_encoding}'" if new_resource.initdb_encoding
cmd << " -D '#{data_dir(new_resource.version)}'" cmd << " -D '#{data_dir(new_resource.version)}'"
end end
@ -239,6 +240,12 @@ module PostgresqlCookbook
platform?('amazon') ? '6' : '$releasever' platform?('amazon') ? '6' : '$releasever'
end end
# Fedora doesn't seem to know the right symbols for psql
def psql_environment
return {} unless platform?('fedora')
{ LD_LIBRARY_PATH: '/usr/lib64' }
end
# Generate a password if the value is set to generate. # Generate a password if the value is set to generate.
def postgres_password(new_resource) def postgres_password(new_resource)
new_resource.password == 'generate' ? secure_random : new_resource.password new_resource.password == 'generate' ? secure_random : new_resource.password

File diff suppressed because one or more lines are too long

View File

@ -4,8 +4,7 @@ maintainer 'Sous Chefs'
maintainer_email 'help@sous-chefs.org' maintainer_email 'help@sous-chefs.org'
license 'Apache-2.0' license 'Apache-2.0'
description 'Installs and configures postgresql for clients or servers' description 'Installs and configures postgresql for clients or servers'
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) version '7.1.8'
version '7.1.4'
source_url 'https://github.com/sous-chefs/postgresql' source_url 'https://github.com/sous-chefs/postgresql'
issues_url 'https://github.com/sous-chefs/postgresql/issues' issues_url 'https://github.com/sous-chefs/postgresql/issues'
chef_version '>= 13.8' chef_version '>= 13.8'

View File

@ -16,12 +16,12 @@
# limitations under the License. # limitations under the License.
# #
property :access_type, String, required: true, default: 'local' property :access_type, String, default: 'local'
property :access_db, String, required: true, default: 'all' property :access_db, String, default: 'all'
property :access_user, String, required: true, default: 'postgres' property :access_user, String, default: 'postgres'
property :access_method, String, required: true, default: 'ident' property :access_method, String, default: 'ident'
property :cookbook, String, default: 'postgresql' property :cookbook, String, default: 'postgresql'
property :source, String, default: 'pg_hba.conf.erb' property :source, String, default: 'pg_hba.conf.erb'
property :access_addr, String property :access_addr, String
property :comment, String property :comment, String

View File

@ -23,7 +23,7 @@ property :owner, String
# Connection prefernces # Connection prefernces
property :user, String, default: 'postgres' property :user, String, default: 'postgres'
property :database, String, name_property: true property :database, String, name_property: true
property :host, [String, nil], default: nil property :host, String
property :port, Integer, default: 5432 property :port, Integer, default: 5432
action :create do action :create do

View File

@ -30,6 +30,7 @@ action :create do
code create_extension_sql(new_resource) code create_extension_sql(new_resource)
user 'postgres' user 'postgres'
action :run action :run
environment(psql_environment)
not_if { follower? || extension_installed?(new_resource) } not_if { follower? || extension_installed?(new_resource) }
end end
end end
@ -39,6 +40,7 @@ action :drop do
code psql_command_string(new_resource, "DROP EXTENSION IF EXISTS \"#{new_resource.extension}\"") code psql_command_string(new_resource, "DROP EXTENSION IF EXISTS \"#{new_resource.extension}\"")
user 'postgres' user 'postgres'
action :run action :run
environment(psql_environment)
not_if { follower? } not_if { follower? }
only_if { extension_installed?(new_resource) } only_if { extension_installed?(new_resource) }
end end

View File

@ -21,11 +21,11 @@ property :source, String, default: 'pg_ident.conf.erb'
property :cookbook, String, default: 'postgresql' property :cookbook, String, default: 'postgresql'
property :system_user, String, required: true property :system_user, String, required: true
property :pg_user, String, required: true property :pg_user, String, required: true
property :comment, [String, nil], default: nil property :comment, String
action :create do action :create do
ident_resource = new_resource ident_resource = new_resource
with_run_context :root do # ~FC037 with_run_context :root do
edit_resource(:template, "#{conf_dir}/pg_ident.conf") do |new_resource| edit_resource(:template, "#{conf_dir}/pg_ident.conf") do |new_resource|
source new_resource.source source new_resource.source
cookbook new_resource.cookbook cookbook new_resource.cookbook

View File

@ -1,4 +1,3 @@
# frozen_string_literal: true
# #
# Cookbook:: postgresql # Cookbook:: postgresql
# Resource:: server_install # Resource:: server_install
@ -26,6 +25,7 @@ property :external_pid_file, String, default: lazy { "/var/run/postgresql/#{vers
property :password, [String, nil], default: 'generate' # Set to nil if we do not want to set a password property :password, [String, nil], default: 'generate' # Set to nil if we do not want to set a password
property :port, Integer, default: 5432 property :port, Integer, default: 5432
property :initdb_locale, String property :initdb_locale, String
property :initdb_encoding, String
# Connection preferences # Connection preferences
property :user, String, default: 'postgres' property :user, String, default: 'postgres'
@ -41,6 +41,23 @@ action :install do
setup_repo new_resource.setup_repo setup_repo new_resource.setup_repo
end end
# First install the postgresql-common package
if platform_family?('debian')
package 'postgresql-common'
initdb_options = ''
initdb_options << "--locale #{new_resource.initdb_locale}" if new_resource.initdb_locale
initdb_options << " -E #{new_resource.initdb_encoding}" if new_resource.initdb_encoding
template '/etc/postgresql-common/createcluster.conf' do
source 'createcluster.conf.erb'
cookbook 'postgresql'
variables(
initdb_options: initdb_options
)
end
end
package server_pkg_name package server_pkg_name
end end

View File

@ -40,6 +40,7 @@ action :create do
user 'postgres' user 'postgres'
command create_user_sql(new_resource) command create_user_sql(new_resource)
sensitive new_resource.sensitive sensitive new_resource.sensitive
environment(psql_environment)
not_if { follower? || user_exists?(new_resource) } not_if { follower? || user_exists?(new_resource) }
end end
end end
@ -49,6 +50,7 @@ action :update do
execute "update postgresql user #{new_resource.create_user}" do execute "update postgresql user #{new_resource.create_user}" do
user 'postgres' user 'postgres'
command update_user_sql(new_resource) command update_user_sql(new_resource)
environment(psql_environment)
sensitive true sensitive true
not_if { follower? } not_if { follower? }
only_if { user_exists?(new_resource) } only_if { user_exists?(new_resource) }
@ -64,6 +66,7 @@ action :update do
execute "Update postgresql user #{new_resource.create_user} to set #{attr}" do execute "Update postgresql user #{new_resource.create_user} to set #{attr}" do
user 'postgres' user 'postgres'
command update_user_with_attributes_sql(new_resource, v) command update_user_with_attributes_sql(new_resource, v)
environment(psql_environment)
sensitive true sensitive true
not_if { follower? } not_if { follower? }
only_if { user_exists?(new_resource) } only_if { user_exists?(new_resource) }
@ -76,6 +79,7 @@ action :drop do
execute "drop postgresql user #{new_resource.create_user}" do execute "drop postgresql user #{new_resource.create_user}" do
user 'postgres' user 'postgres'
command drop_user_sql(new_resource) command drop_user_sql(new_resource)
environment(psql_environment)
sensitive true sensitive true
not_if { follower? } not_if { follower? }
only_if { user_exists?(new_resource) } only_if { user_exists?(new_resource) }

View File

@ -0,0 +1,41 @@
# Default values for pg_createcluster(8)
# Occurrences of '%v' are replaced by the major version number,
# and '%c' by the cluster name. Use '%%' for a literal '%'.
# Create a "main" cluster when a new postgresql-x.y server package is installed
#create_main_cluster = true
# Default start.conf value, must be one of "auto", "manual", and "disabled".
# See pg_createcluster(8) for more documentation.
#start_conf = 'auto'
# Default data directory.
#data_directory = '/var/lib/postgresql/%v/%c'
# Default directory for transaction logs
# Unset by default, i.e. transaction logs remain in the data directory.
#waldir = '/var/lib/postgresql/wal/%v/%c/pg_wal'
# Options to pass to initdb.
initdb_options = '<%= @initdb_options %>'
# The following options are copied into the new cluster's postgresql.conf:
# Enable SSL by default (using the "snakeoil" certificates installed by the
# ssl-cert package, unless configured otherwise here)
ssl = on
# Show cluster name in process title
cluster_name = '%v/%c'
# Put stats_temp_directory on tmpfs
stats_temp_directory = '/var/run/postgresql/%v-%c.pg_stat_tmp'
# Add prefix to log lines
log_line_prefix = '%%m [%%p] %%q%%u@%%d '
# Add "include_dir" in postgresql.conf
add_include_dir = 'conf.d'
# Directory for additional createcluster config
include_dir '/etc/postgresql-common/createcluster.d'