Skip to content

Allow more fine-grained control over yum repo config. Fixes #716. #784

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ This file is used to list changes made in the last 3 major versions of the postg
## Unreleased

- Cast `server_config` keys to strings in `postgresql_config` to avoid unnecessary converges
- Add `setup_pgdg_*` properties to `postgresql_install` to allow more fine grained control over derived `yum_repository` resources

## 12.0.3 - *2024-12-30*

Expand Down
43 changes: 24 additions & 19 deletions documentation/postgresql_install.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,30 @@

## Properties

| Name | Name? | Type | Default | Description | Allowed Values |
| ---------------------------------- | ----- | --------------- | ------- | ------------------------------------------------ | -------------- |
| `sensitive` | | true, false | | | |
| `version` | | String, Integer | | Version to install | |
| `source` | | String, Symbol | | Installation source | repo, os |
| `client_packages` | | String, Array | | Client packages to install | |
| `server_packages` | | String, Array | | Server packages to install | |
| `repo_pgdg` | | true, false | | Create pgdg repo | |
| `repo_pgdg_common` | | true, false | | Create pgdg-common repo | |
| `repo_pgdg_source` | | true, false | | Create pgdg-source repo | |
| `repo_pgdg_updates_testing` | | true, false | | Create pgdg-updates-testing repo | |
| `repo_pgdg_source_updates_testing` | | true, false | | Create pgdg-source-updates-testing repo | |
| `yum_gpg_key_uri` | | String | | YUM/DNF GPG key URL | |
| `apt_repository_uri` | | String | | apt repository URL | |
| `apt_gpg_key_uri` | | String | | apt GPG key URL | |
| `initdb_additional_options` | | String | | Additional options to pass to the initdb command | |
| `initdb_locale` | | String | | Locale to use for the initdb command | |
| `initdb_encoding` | | String | | Encoding to use for the initdb command | |
| `initdb_user` | | String | | User to run the initdb command as | |
| Name | Name? | Type | Default | Description | Allowed Values |
| ---------------------------------- | ----- | --------------- | ----------------- | ------------------------------------------------ | -------------- |
| `sensitive` | | true, false | `true` | | |
| `version` | | String, Integer | `'17'` | Version to install | |
| `source` | | String, Symbol | `:repo` | Installation source | repo, os |
| `client_packages` | | String, Array | platform specific | Client packages to install | |
| `server_packages` | | String, Array | platform specific | Server packages to install | |
| `repo_pgdg` | | true, false | `true` | Create pgdg repo | |
| `setup_repo_pgdg` | | true, false | value of previous | Whether or not to manage the pgdg repo | |
| `repo_pgdg_common` | | true, false | `true` | Create pgdg-common repo | |
| `setup_repo_pgdg_common` | | true, false | value of previous | Whether or not to manage the pgdg_common repo | |
| `repo_pgdg_source` | | true, false | `false` | Create pgdg-source repo | |
| `setup_repo_pgdg_source` | | true, false | value of previous | Whether or not to manage the pgdg_source repo | |
| `repo_pgdg_updates_testing` | | true, false | `false` | Create pgdg-updates-testing repo | |
| `setup_repo_pgdg_updates_testing` | | true, false | value of previous | Whether or not to manage the pgdg_updates_testing repo | |
| `repo_pgdg_source_updates_testing` | | true, false | `false` | Create pgdg-source-updates-testing repo | |
| `setup_repo_pgdg_source_updates_testing` | | true, false | value of previous | Whether or not to manage the pgdg_source_updates_testing repo | |
| `yum_gpg_key_uri` | | String | platform specific | YUM/DNF GPG key URL | |
| `apt_repository_uri` | | String | https://download.postgresql.org/pub/repos/apt/ | apt repository URL | |

Check failure on line 38 in documentation/postgresql_install.md

View workflow job for this annotation

GitHub Actions / lint-unit / markdownlint-cli2

Bare URL used

documentation/postgresql_install.md:38:66 MD034/no-bare-urls Bare URL used [Context: "https://download.postgresql.or..."] https://github.com/DavidAnson/markdownlint/blob/v0.34.0/doc/md034.md
| `apt_gpg_key_uri` | | String | https://download.postgresql.org/pub/repos/apt/ACCC4CF8.asc | apt GPG key URL | |

Check failure on line 39 in documentation/postgresql_install.md

View workflow job for this annotation

GitHub Actions / lint-unit / markdownlint-cli2

Bare URL used

documentation/postgresql_install.md:39:66 MD034/no-bare-urls Bare URL used [Context: "https://download.postgresql.or..."] https://github.com/DavidAnson/markdownlint/blob/v0.34.0/doc/md034.md
| `initdb_additional_options` | | String | | Additional options to pass to the initdb command | |
| `initdb_locale` | | String | | Locale to use for the initdb command | |
| `initdb_encoding` | | String | | Encoding to use for the initdb command | |
| `initdb_user` | | String | `'postgres'` | User to run the initdb command as | |

## Libraries

Expand Down
22 changes: 22 additions & 0 deletions kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -246,3 +246,25 @@ suites:
pg_ver: "15"
run_list:
- recipe[test::server_install]
- name: all_repos_install_15
attributes:
test:
pg_ver: "15"
verifier:
inspec_tests:
- path: test/integration/all_repos_install/
inputs:
pg_ver: "15"
run_list:
- recipe[test::all_repos_install]
- name: no_repos_install_15
attributes:
test:
pg_ver: "15"
verifier:
inspec_tests:
- path: test/integration/no_repos_install/
inputs:
pg_ver: "15"
run_list:
- recipe[test::no_repos_install]
35 changes: 30 additions & 5 deletions resources/install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,43 @@

property :repo_pgdg, [true, false],
default: true,
description: 'Create pgdg repo'
description: 'Enable pgdg repo'

property :setup_repo_pgdg, [true, false],
default: lazy { |r| r.repo_pgdg },
description: 'Setup pgdg repo. Defaults to value of `:repo_pgdg`.'

property :repo_pgdg_common, [true, false],
default: true,
description: 'Create pgdg-common repo'
description: 'Enable pgdg-common repo'

property :setup_repo_pgdg_common, [true, false],
default: lazy { |r| r.repo_pgdg_common },
description: 'Setup pgdg-common repo. Defaults to value of `:repo_pgdg_common`.'

property :repo_pgdg_source, [true, false],
default: false,
description: 'Create pgdg-source repo'
description: 'Enable pgdg-source repo'

property :setup_repo_pgdg_source, [true, false],
default: lazy { |r| r.repo_pgdg_source },
description: 'Setup pgdg-source repo. Defaults to value of `:repo_pgdg_source`.'

property :repo_pgdg_updates_testing, [true, false],
default: false,
description: 'Create pgdg-updates-testing repo'
description: 'Enable pgdg-updates-testing repo'

property :setup_repo_pgdg_updates_testing, [true, false],
default: lazy { |r| r.repo_pgdg_updates_testing },
description: 'Setup pgdg-updates-testing repo. Defaults to value of `:repo_pgdg_updates_testing`.'

property :repo_pgdg_source_updates_testing, [true, false],
default: false,
description: 'Create pgdg-source-updates-testing repo'
description: 'Enable pgdg-source-updates-testing repo'

property :setup_repo_pgdg_source_updates_testing, [true, false],
default: lazy { |r| r.repo_pgdg_source_updates_testing },
description: 'Setup pgdg-source-updates-testing repo. Defaults to value of `:repo_pgdg_source_updates_testing`.'

property :yum_gpg_key_uri, String,
default: lazy { default_yum_gpg_key_uri },
Expand Down Expand Up @@ -116,6 +136,7 @@ def do_repository_action(repo_action)
gpgcheck true
gpgkey 'file:///etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY'
action repo_action
only_if { new_resource.repo_pgdg || new_resource.setup_repo_pgdg }
end

yum_repository 'PostgreSQL - common' do
Expand All @@ -126,6 +147,7 @@ def do_repository_action(repo_action)
gpgcheck true
gpgkey 'file:///etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY'
action repo_action
only_if { new_resource.repo_pgdg_common || new_resource.setup_repo_pgdg_common }
end

yum_repository "PostgreSQL #{new_resource.version} - source " do
Expand All @@ -137,6 +159,7 @@ def do_repository_action(repo_action)
gpgcheck true
gpgkey 'file:///etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY'
action repo_action
only_if { new_resource.repo_pgdg_source || new_resource.setup_repo_pgdg_source }
end

yum_repository "PostgreSQL #{new_resource.version} - updates testing" do
Expand All @@ -148,6 +171,7 @@ def do_repository_action(repo_action)
gpgcheck true
gpgkey 'file:///etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY'
action repo_action
only_if { new_resource.repo_pgdg_updates_testing || new_resource.setup_repo_pgdg_updates_testing }
end

yum_repository "PostgreSQL #{new_resource.version} - source - updates testing" do
Expand All @@ -159,6 +183,7 @@ def do_repository_action(repo_action)
gpgcheck true
gpgkey 'file:///etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY'
action repo_action
only_if { new_resource.repo_pgdg_source_updates_testing || new_resource.setup_repo_pgdg_source_updates_testing }
end

when 'debian'
Expand Down
42 changes: 42 additions & 0 deletions test/cookbooks/test/recipes/all_repos_install.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
postgresql_install 'postgresql' do
version node['test']['pg_ver']
setup_repo_pgdg_source true
setup_repo_pgdg_updates_testing true
setup_repo_pgdg_source_updates_testing true
action %i(install init_server)
end

postgresql_config 'postgresql-server' do
version '15'

server_config({
'max_connections' => 110,
'shared_buffers' => '128MB',
'dynamic_shared_memory_type' => 'posix',
'max_wal_size' => '1GB',
'min_wal_size' => '80MB',
'log_destination' => 'stderr',
'logging_collector' => true,
'log_directory' => 'log',
'log_filename' => 'postgresql-%a.log',
'log_rotation_age' => '1d',
'log_rotation_size' => 0,
'log_truncate_on_rotation' => true,
'log_line_prefix' => '%m [%p]',
'log_timezone' => 'Etc/UTC',
'datestyle' => 'iso, mdy',
'timezone' => 'Etc/UTC',
'lc_messages' => 'C',
'lc_monetary' => 'C',
'lc_numeric' => 'C',
'lc_time' => 'C',
'default_text_search_config' => 'pg_catalog.english',
})

notifies :restart, 'postgresql_service[postgresql]', :delayed
action :create
end

postgresql_service 'postgresql' do
action %i(enable start)
end
52 changes: 52 additions & 0 deletions test/cookbooks/test/recipes/no_repos_install.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# I can do it myself!
yum_repository 'postgresql-15' do
baseurl 'https://download.postgresql.org/pub/repos/yum/15/redhat/rhel-$releasever-$basearch'
gpgkey "https://download.postgresql.org/pub/repos/yum/keys/PGDG-RPM-GPG-KEY-RHEL#{node['platform_version'].to_i.eql?(7) ? '7' : ''}"
end

yum_repository 'postgresql-common' do
baseurl 'https://download.postgresql.org/pub/repos/yum/common/redhat/rhel-$releasever-$basearch'
gpgkey "https://download.postgresql.org/pub/repos/yum/keys/PGDG-RPM-GPG-KEY-RHEL#{node['platform_version'].to_i.eql?(7) ? '7' : ''}"
end

postgresql_install 'postgresql' do
version node['test']['pg_ver']
repo_pgdg false
repo_pgdg_common false
action %i(install init_server)
end

postgresql_config 'postgresql-server' do
version '15'

server_config({
'max_connections' => 110,
'shared_buffers' => '128MB',
'dynamic_shared_memory_type' => 'posix',
'max_wal_size' => '1GB',
'min_wal_size' => '80MB',
'log_destination' => 'stderr',
'logging_collector' => true,
'log_directory' => 'log',
'log_filename' => 'postgresql-%a.log',
'log_rotation_age' => '1d',
'log_rotation_size' => 0,
'log_truncate_on_rotation' => true,
'log_line_prefix' => '%m [%p]',
'log_timezone' => 'Etc/UTC',
'datestyle' => 'iso, mdy',
'timezone' => 'Etc/UTC',
'lc_messages' => 'C',
'lc_monetary' => 'C',
'lc_numeric' => 'C',
'lc_time' => 'C',
'default_text_search_config' => 'pg_catalog.english',
})

notifies :restart, 'postgresql_service[postgresql]', :delayed
action :create
end

postgresql_service 'postgresql' do
action %i(enable start)
end
28 changes: 28 additions & 0 deletions test/integration/all_repos_install/controls/all_repos_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true
pg_ver = input('pg_ver')

if os[:family] == 'redhat'
describe service("postgresql-#{pg_ver}") do
it { should be_installed }
it { should be_enabled }
it { should be_running }
end
%W(pgdg#{pg_ver} pgdg-common).each do |r|
describe yum.repo(r) do
it { should exist }
it { should be_enabled }
end
end
%W(pgdg#{pg_ver}-source pgdg#{pg_ver}-updates-testing pgdg#{pg_ver}-source-updates-testing).each do |r|
describe yum.repo(r) do
it { should exist }
it { should_not be_enabled }
end
end
else
describe service('postgresql') do
it { should be_installed }
it { should be_enabled }
it { should be_running }
end
end
13 changes: 13 additions & 0 deletions test/integration/all_repos_install/inspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
name: all_repos_install
title: PostgreSQL server with all repos setup but only pgdg and pgdg-common enabled
maintainer: Sous Chefs
copyright_email: help@sous-chefs.org
license: Apache
summary: Verify the correct installation of the postgresql server including correct repos setup and enabled
version: 0.0.1
supports:
- os-family: unix
depends:
- name: client
path: ./test/integration/client_install
28 changes: 28 additions & 0 deletions test/integration/no_repos_install/controls/no_repos_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true
pg_ver = input('pg_ver')

if os[:family] == 'redhat'
describe service("postgresql-#{pg_ver}") do
it { should be_installed }
it { should be_enabled }
it { should be_running }
end
%W(pgdg#{pg_ver} pgdg-common).each do |r|
describe yum.repo(r) do
it { should_not exist }
it { should_not be_enabled }
end
end
%W(pgdg#{pg_ver}-source pgdg#{pg_ver}-updates-testing pgdg#{pg_ver}-source-updates-testing).each do |r|
describe yum.repo(r) do
it { should_not exist }
it { should_not be_enabled }
end
end
else
describe service('postgresql') do
it { should be_installed }
it { should be_enabled }
it { should be_running }
end
end
13 changes: 13 additions & 0 deletions test/integration/no_repos_install/inspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
name: no_repos_install
title: PostgreSQL no_repos_install
maintainer: Sous Chefs
copyright_email: help@sous-chefs.org
license: Apache
summary: Verify the correct installation of the postgresql server with cookbook provided yum repos instead of resource
version: 0.0.1
supports:
- os-family: unix
depends:
- name: client
path: ./test/integration/client_install
28 changes: 28 additions & 0 deletions test/integration/no_repos_install/no_repos_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true
pg_ver = input('pg_ver')

if os[:family] == 'redhat'
describe service("postgresql-#{pg_ver}") do
it { should be_installed }
it { should be_enabled }
it { should be_running }
end
%W(pgdg#{pg_ver} pgdg-common).each do |r|
describe yum.repo(r) do
it { should exist }
it { should be_enabled }
end
end
%W(pgdg#{pg_ver}-source pgdg#{pg_ver}-updates-testing pgdg#{pg_ver}-source-updates-testing).each do |r|
describe yum.repo(r) do
it { should exist }
it { should_not be_enabled }
end
end
else
describe service('postgresql') do
it { should be_installed }
it { should be_enabled }
it { should be_running }
end
end
Loading
Loading