Compare commits

...

19 Commits

Author SHA1 Message Date
Jeff Geerling 6e339edaff
Merge pull request #257 from brendon-stephens/patch-1
set the default postgres version to "13" for RHEL9 (fixes #252)
2024-05-06 20:27:06 -05:00
Brendon Stephens cd816ac737
set the default postgres version to "13" for RHEL9 2024-05-07 11:16:50 +10:00
Jeff Geerling 15b1eca56b
Merge pull request #253 from C0rn3j/master
Color Readme.md YAML blocks
2024-05-03 21:17:05 -05:00
Jeff Geerling 156d056c8f Make local dev with molecule a little easier. 2024-01-24 22:00:25 -06:00
Martin Rys 67640e5018 Color Readme.md YAML blocks 2023-12-31 18:40:29 +01:00
Jeff Geerling 4d95a289cb Stale bot is now Stale GitHub Action. 2023-07-10 17:48:43 -05:00
Jeff Geerling 28ef0ad021 Remove official support for RHEL. Rocky/Alma/Stream support is best-effort. 2023-06-23 10:57:28 -05:00
Jeff Geerling a7723eb017 Fedora support time for 37 and 38. 2023-06-15 22:19:02 -05:00
Jeff Geerling 3b721b124d Adjustments for Debian versions. 2023-06-15 22:15:50 -05:00
Jeff Geerling 01ccdb0907
Merge pull request #244 from aanazaretyan/patch-1
Correct wrong variable name
2023-06-15 22:15:47 -05:00
Jeff Geerling e08acbf93c
Merge pull request #248 from anxjok/master
add support for debian 12
2023-06-15 22:12:07 -05:00
jkress 7b81446625 fixed lint error 2023-06-13 07:59:36 +02:00
jkress 7d7e2a26d8 add support for debian 12 2023-06-13 07:59:36 +02:00
Albert Nazaretyan 35d176c8e3
Update Debian-11.yml 2023-05-06 18:01:53 +03:00
Jeff Geerling 8861048695 Fix Molecule CI workflow since docker plugin has moved. 2023-04-20 17:28:16 -05:00
Jeff Geerling e8db6bb5c8
Merge pull request #231 from C0rn3j/archinstall
Add support for installing packages on Arch Linux
2023-02-17 15:53:56 -06:00
Jeff Geerling dda4cbf1a0 Remove CentOS 7 from tests. 2022-12-06 19:16:34 -06:00
Jeff Geerling 42835bf112 Fix Molecule CI workflow for Ubuntu 22.04 GitHub Actions. 2022-12-06 18:24:36 -06:00
Martin Rys 204b6725f8 Add support for installing packages on Arch Linux 2022-12-04 17:01:50 +01:00
19 changed files with 191 additions and 204 deletions

57
.github/stale.yml vendored
View File

@ -1,57 +0,0 @@
# Configuration for probot-stale - https://github.com/probot/stale
# Number of days of inactivity before an Issue or Pull Request becomes stale
daysUntilStale: 90
# Number of days of inactivity before an Issue or Pull Request with the stale label is closed.
# Set to false to disable. If disabled, issues still need to be closed manually, but will remain marked as stale.
daysUntilClose: 30
# Only issues or pull requests with all of these labels are check if stale. Defaults to `[]` (disabled)
onlyLabels: []
# Issues or Pull Requests with these labels will never be considered stale. Set to `[]` to disable
exemptLabels:
- bug
- pinned
- security
- planned
# Set to true to ignore issues in a project (defaults to false)
exemptProjects: false
# Set to true to ignore issues in a milestone (defaults to false)
exemptMilestones: false
# Set to true to ignore issues with an assignee (defaults to false)
exemptAssignees: false
# Label to use when marking as stale
staleLabel: stale
# Limit the number of actions per hour, from 1-30. Default is 30
limitPerRun: 30
pulls:
markComment: |-
This pull request has been marked 'stale' due to lack of recent activity. If there is no further activity, the PR will be closed in another 30 days. Thank you for your contribution!
Please read [this blog post](https://www.jeffgeerling.com/blog/2020/enabling-stale-issue-bot-on-my-github-repositories) to see the reasons why I mark pull requests as stale.
unmarkComment: >-
This pull request is no longer marked for closure.
closeComment: >-
This pull request has been closed due to inactivity. If you feel this is in error, please reopen the pull request or file a new PR with the relevant details.
issues:
markComment: |-
This issue has been marked 'stale' due to lack of recent activity. If there is no further activity, the issue will be closed in another 30 days. Thank you for your contribution!
Please read [this blog post](https://www.jeffgeerling.com/blog/2020/enabling-stale-issue-bot-on-my-github-repositories) to see the reasons why I mark issues as stale.
unmarkComment: >-
This issue is no longer marked for closure.
closeComment: >-
This issue has been closed due to inactivity. If you feel this is in error, please reopen the issue or file a new issue with the relevant details.

View File

@ -19,12 +19,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out the codebase.
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
path: 'geerlingguy.postgresql'
- name: Set up Python 3.
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: '3.x'
@ -44,28 +44,25 @@ jobs:
distro:
- rockylinux8
- rockylinux9
- centos7
- fedora36
- fedora38
- ubuntu2204
- ubuntu2004
- ubuntu1804
- debian10
- debian11
# - amazonlinux2
- debian12
steps:
- name: Check out the codebase.
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
path: 'geerlingguy.postgresql'
- name: Set up Python 3.
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install test dependencies.
run: pip3 install ansible molecule[docker] docker
run: pip3 install ansible molecule molecule-plugins[docker] docker
- name: Run Molecule tests.
run: molecule test

View File

@ -22,12 +22,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out the codebase.
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
path: 'geerlingguy.postgresql'
- name: Set up Python 3.
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: '3.x'

34
.github/workflows/stale.yml vendored Normal file
View File

@ -0,0 +1,34 @@
---
name: Close inactive issues
'on':
schedule:
- cron: "55 19 * * 5" # semi-random time
jobs:
close-issues:
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
steps:
- uses: actions/stale@v8
with:
days-before-stale: 120
days-before-close: 60
exempt-issue-labels: bug,pinned,security,planned
exempt-pr-labels: bug,pinned,security,planned
stale-issue-label: "stale"
stale-pr-label: "stale"
stale-issue-message: |
This issue has been marked 'stale' due to lack of recent activity. If there is no further activity, the issue will be closed in another 30 days. Thank you for your contribution!
Please read [this blog post](https://www.jeffgeerling.com/blog/2020/enabling-stale-issue-bot-on-my-github-repositories) to see the reasons why I mark issues as stale.
close-issue-message: |
This issue has been closed due to inactivity. If you feel this is in error, please reopen the issue or file a new issue with the relevant details.
stale-pr-message: |
This pr has been marked 'stale' due to lack of recent activity. If there is no further activity, the issue will be closed in another 30 days. Thank you for your contribution!
Please read [this blog post](https://www.jeffgeerling.com/blog/2020/enabling-stale-issue-bot-on-my-github-repositories) to see the reasons why I mark issues as stale.
close-pr-message: |
This pr has been closed due to inactivity. If you feel this is in error, please reopen the issue or file a new issue with the relevant details.
repo-token: ${{ secrets.GITHUB_TOKEN }}

View File

@ -7,5 +7,4 @@ rules:
level: warning
ignore: |
.github/stale.yml
.travis.yml
.github/workflows/stale.yml

174
README.md
View File

@ -8,56 +8,72 @@ Installs and configures PostgreSQL server on RHEL/CentOS or Debian/Ubuntu server
No special requirements; note that this role requires root access, so either run it in a playbook with a global `become: yes`, or invoke the role in your playbook like:
- hosts: database
roles:
- role: geerlingguy.postgresql
become: yes
```yaml
- hosts: database
roles:
- role: geerlingguy.postgresql
become: yes
```
## Role Variables
Available variables are listed below, along with default values (see `defaults/main.yml`):
postgresql_enablerepo: ""
```yaml
postgresql_enablerepo: ""
```
(RHEL/CentOS only) You can set a repo to use for the PostgreSQL installation by passing it in here.
postgresql_restarted_state: "restarted"
```yaml
postgresql_restarted_state: "restarted"
```
Set the state of the service when configuration changes are made. Recommended values are `restarted` or `reloaded`.
postgresql_python_library: python-psycopg2
```yaml
postgresql_python_library: python-psycopg2
```
Library used by Ansible to communicate with PostgreSQL. If you are using Python 3 (e.g. set via `ansible_python_interpreter`), you should change this to `python3-psycopg2`.
postgresql_user: postgres
postgresql_group: postgres
```yaml
postgresql_user: postgres
postgresql_group: postgres
```
The user and group under which PostgreSQL will run.
postgresql_unix_socket_directories:
- /var/run/postgresql
```yaml
postgresql_unix_socket_directories:
- /var/run/postgresql
```
The directories (usually one, but can be multiple) where PostgreSQL's socket will be created.
postgresql_service_state: started
postgresql_service_enabled: true
```yaml
postgresql_service_state: started
postgresql_service_enabled: true
```
Control the state of the postgresql service and whether it should start at boot time.
postgresql_global_config_options:
- option: unix_socket_directories
value: '{{ postgresql_unix_socket_directories | join(",") }}'
- option: log_directory
value: 'log'
```yaml
postgresql_global_config_options:
- option: unix_socket_directories
value: '{{ postgresql_unix_socket_directories | join(",") }}'
- option: log_directory
value: 'log'
```
Global configuration options that will be set in `postgresql.conf`.
For PostgreSQL versions older than 9.3 you need to at least override this variable and set the `option` to `unix_socket_directory`.
If you override the value of `option: log_directory` with another path, relative or absolute, then this role will create it for you.
If you override the value of `option: log_directory` with another path, relative or absolute, then this role will create it for you.
postgresql_hba_entries:
- { type: local, database: all, user: postgres, auth_method: peer }
- { type: local, database: all, user: all, auth_method: peer }
- { type: host, database: all, user: all, address: '127.0.0.1/32', auth_method: md5 }
- { type: host, database: all, user: all, address: '::1/128', auth_method: md5 }
```yaml
postgresql_hba_entries:
- { type: local, database: all, user: postgres, auth_method: peer }
- { type: local, database: all, user: all, auth_method: peer }
- { type: host, database: all, user: all, address: '127.0.0.1/32', auth_method: md5 }
- { type: host, database: all, user: all, address: '::1/128', auth_method: md5 }
```
Configure [host based authentication](https://www.postgresql.org/docs/current/static/auth-pg-hba-conf.html) entries to be set in the `pg_hba.conf`. Options for entries include:
@ -72,53 +88,63 @@ Configure [host based authentication](https://www.postgresql.org/docs/current/st
If overriding, make sure you copy all of the existing entries from `defaults/main.yml` if you need to preserve existing entries.
postgresql_locales:
- 'en_US.UTF-8'
```yaml
postgresql_locales:
- 'en_US.UTF-8'
```
(Debian/Ubuntu only) Used to generate the locales used by PostgreSQL databases.
postgresql_databases:
- name: exampledb # required; the rest are optional
lc_collate: # defaults to 'en_US.UTF-8'
lc_ctype: # defaults to 'en_US.UTF-8'
encoding: # defaults to 'UTF-8'
template: # defaults to 'template0'
login_host: # defaults to 'localhost'
login_password: # defaults to not set
login_user: # defaults to 'postgresql_user'
login_unix_socket: # defaults to 1st of postgresql_unix_socket_directories
port: # defaults to not set
owner: # defaults to postgresql_user
state: # defaults to 'present'
```yaml
postgresql_databases:
- name: exampledb # required; the rest are optional
lc_collate: # defaults to 'en_US.UTF-8'
lc_ctype: # defaults to 'en_US.UTF-8'
encoding: # defaults to 'UTF-8'
template: # defaults to 'template0'
login_host: # defaults to 'localhost'
login_password: # defaults to not set
login_user: # defaults to 'postgresql_user'
login_unix_socket: # defaults to 1st of postgresql_unix_socket_directories
port: # defaults to not set
owner: # defaults to postgresql_user
state: # defaults to 'present'
```
A list of databases to ensure exist on the server. Only the `name` is required; all other properties are optional.
postgresql_users:
- name: jdoe #required; the rest are optional
password: # defaults to not set
encrypted: # defaults to not set
priv: # defaults to not set
role_attr_flags: # defaults to not set
db: # defaults to not set
login_host: # defaults to 'localhost'
login_password: # defaults to not set
login_user: # defaults to '{{ postgresql_user }}'
login_unix_socket: # defaults to 1st of postgresql_unix_socket_directories
port: # defaults to not set
state: # defaults to 'present'
```yaml
postgresql_users:
- name: jdoe #required; the rest are optional
password: # defaults to not set
encrypted: # defaults to not set
priv: # defaults to not set
role_attr_flags: # defaults to not set
db: # defaults to not set
login_host: # defaults to 'localhost'
login_password: # defaults to not set
login_user: # defaults to '{{ postgresql_user }}'
login_unix_socket: # defaults to 1st of postgresql_unix_socket_directories
port: # defaults to not set
state: # defaults to 'present'
```
A list of users to ensure exist on the server. Only the `name` is required; all other properties are optional.
postgres_users_no_log: true
```yaml
postgres_users_no_log: true
```
Whether to output user data (which may contain sensitive information, like passwords) when managing users.
postgresql_version: [OS-specific]
postgresql_data_dir: [OS-specific]
postgresql_bin_path: [OS-specific]
postgresql_config_path: [OS-specific]
postgresql_daemon: [OS-specific]
postgresql_packages: [OS-specific]
```yaml
postgresql_version: [OS-specific]
postgresql_data_dir: [OS-specific]
postgresql_bin_path: [OS-specific]
postgresql_config_path: [OS-specific]
postgresql_daemon: [OS-specific]
postgresql_packages: [OS-specific]
```
OS-specific variables that are set by include files in this role's `vars` directory. These shouldn't be overridden unless you're using a version of PostgreSQL that wasn't installed using system packages.
@ -128,20 +154,24 @@ None.
## Example Playbook
- hosts: database
become: yes
vars_files:
- vars/main.yml
roles:
- geerlingguy.postgresql
```yaml
- hosts: database
become: yes
vars_files:
- vars/main.yml
roles:
- geerlingguy.postgresql
```
*Inside `vars/main.yml`*:
postgresql_databases:
- name: example_db
postgresql_users:
- name: example_user
password: supersecure
```yaml
postgresql_databases:
- name: example_db
postgresql_users:
- name: example_user
password: supersecure
```
## License

View File

@ -7,25 +7,18 @@ galaxy_info:
description: PostgreSQL server for Linux.
company: "Midwestern Mac, LLC"
license: "license (BSD, MIT)"
min_ansible_version: 2.8
min_ansible_version: 2.10
platforms:
- name: ArchLinux
versions:
- all
- name: EL
versions:
- 7
- 8
- 9
- name: Fedora
versions:
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- name: Ubuntu
versions:
- xenial
@ -34,11 +27,9 @@ galaxy_info:
- jammy
- name: Debian
versions:
- wheezy
- jessie
- stretch
- buster
- bullseye
- bookworm
galaxy_tags:
- database
- postgresql

View File

@ -2,14 +2,17 @@
role_name_check: 1
dependency:
name: galaxy
options:
ignore-errors: true
driver:
name: docker
platforms:
- name: instance
image: "geerlingguy/docker-${MOLECULE_DISTRO:-centos7}-ansible:latest"
image: "geerlingguy/docker-${MOLECULE_DISTRO:-rockylinux8}-ansible:latest"
command: ${MOLECULE_DOCKER_COMMAND:-""}
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
- /sys/fs/cgroup:/sys/fs/cgroup:rw
cgroupns_mode: host
privileged: true
pre_build_image: true
provisioner:

View File

@ -3,12 +3,15 @@
- include_tasks: variables.yml
# Setup/install tasks.
- include_tasks: setup-RedHat.yml
when: ansible_os_family == 'RedHat'
- include_tasks: setup-Archlinux.yml
when: ansible_os_family == 'Archlinux'
- include_tasks: setup-Debian.yml
when: ansible_os_family == 'Debian'
- include_tasks: setup-RedHat.yml
when: ansible_os_family == 'RedHat'
- include_tasks: initialize.yml
- include_tasks: configure.yml

21
tasks/setup-Archlinux.yml Normal file
View File

@ -0,0 +1,21 @@
---
- name: Ensure PostgreSQL Python libraries are installed.
pacman:
name: "{{ postgresql_python_library }}"
state: present
- name: Ensure PostgreSQL packages are installed.
pacman:
name: "{{ postgresql_packages }}"
state: present
- name: Ensure all configured locales are present.
locale_gen: "name={{ item }} state=present"
with_items: "{{ postgresql_locales }}"
register: locale_gen_result
- name: Force-restart PostgreSQL after new locales are generated.
systemd:
name: "{{ postgresql_daemon }}"
state: restarted
when: locale_gen_result.changed

View File

@ -7,9 +7,9 @@
- name: Include OS-specific variables (RedHat).
include_vars: "{{ ansible_os_family }}-{{ ansible_distribution_version.split('.')[0] }}.yml"
when:
- ansible_os_family == 'RedHat'
- ansible_distribution != 'Fedora'
- ansible_distribution != 'Amazon'
- ansible_os_family == 'RedHat'
- ansible_distribution != 'Fedora'
- ansible_distribution != 'Amazon'
- name: Include OS-specific variables (Amazon).
include_vars: "{{ ansible_distribution }}-{{ ansible_distribution_major_version }}.yml"

View File

@ -3,7 +3,7 @@ __postgresql_version: "13"
__postgresql_data_dir: "/var/lib/postgresql/{{ __postgresql_version }}/main"
__postgresql_bin_path: "/usr/lib/postgresql/{{ __postgresql_version }}/bin"
__postgresql_config_path: "/etc/postgresql/{{ __postgresql_version }}/main"
__postgresql_daemon: "postgresql@{{ postgresql_version }}-main"
__postgresql_daemon: "postgresql@{{ __postgresql_version }}-main"
__postgresql_packages:
- postgresql
- postgresql-contrib

View File

@ -1,5 +1,5 @@
---
__postgresql_version: "9.4"
__postgresql_version: "15"
__postgresql_data_dir: "/var/lib/postgresql/{{ __postgresql_version }}/main"
__postgresql_bin_path: "/usr/lib/postgresql/{{ __postgresql_version }}/bin"
__postgresql_config_path: "/etc/postgresql/{{ __postgresql_version }}/main"
@ -8,3 +8,4 @@ __postgresql_packages:
- postgresql
- postgresql-contrib
- libpq-dev
postgresql_python_library: python3-psycopg2

View File

@ -1,10 +0,0 @@
---
__postgresql_version: "9.1"
__postgresql_data_dir: "/var/lib/postgresql/{{ __postgresql_version }}/main"
__postgresql_bin_path: "/usr/lib/postgresql/{{ __postgresql_version }}/bin"
__postgresql_config_path: "/etc/postgresql/{{ __postgresql_version }}/main"
__postgresql_daemon: postgresql
__postgresql_packages:
- postgresql
- postgresql-contrib
- libpq-dev

View File

@ -1,12 +0,0 @@
---
__postgresql_version: "10.5"
__postgresql_data_dir: "/var/lib/pgsql/data"
__postgresql_bin_path: "/usr/bin"
__postgresql_config_path: "/var/lib/pgsql/data"
__postgresql_daemon: postgresql
__postgresql_packages:
- postgresql
- postgresql-server
- postgresql-contrib
- postgresql-libs
postgresql_python_library: python2-psycopg2

View File

@ -1,13 +0,0 @@
---
__postgresql_version: "11.2"
__postgresql_data_dir: "/var/lib/pgsql/data"
__postgresql_bin_path: "/usr/bin"
__postgresql_config_path: "/var/lib/pgsql/data"
__postgresql_daemon: postgresql
__postgresql_packages:
- postgresql
- postgresql-server
- postgresql-contrib
- postgresql-libs
# Fedora 30 containers only have python3 by default
postgresql_python_library: python3-psycopg2

View File

@ -1,5 +1,5 @@
---
__postgresql_version: "12.2"
__postgresql_version: "14.3"
__postgresql_data_dir: "/var/lib/pgsql/data"
__postgresql_bin_path: "/usr/bin"
__postgresql_config_path: "/var/lib/pgsql/data"

View File

@ -1,5 +1,5 @@
---
__postgresql_version: "11.5"
__postgresql_version: "15.1"
__postgresql_data_dir: "/var/lib/pgsql/data"
__postgresql_bin_path: "/usr/bin"
__postgresql_config_path: "/var/lib/pgsql/data"
@ -10,5 +10,5 @@ __postgresql_packages:
- postgresql-contrib
- postgresql-libs
__postgresql_unix_socket_directories_mode: '0755'
# Fedora 31 containers only have python3 by default
# Fedora 32 containers only have python3 by default
postgresql_python_library: python3-psycopg2

View File

@ -1,5 +1,5 @@
---
__postgresql_version: "10"
__postgresql_version: "13"
__postgresql_data_dir: "/var/lib/pgsql/data"
__postgresql_bin_path: "/usr/bin"
__postgresql_config_path: "/var/lib/pgsql/data"