ANXS.postgresql
ANXS - PostgreSQL 
Help Needed! If you can help maintain this Ansible role, please create an issue on GitHub. Many people use this role, and we really need support! 💖
This is an Ansible role that installs and sets up PostgreSQL along with its extensions, databases, and users.
Installation
Tested with Ansible version 2.4.0 and above.
To install, run:
ansible-galaxy install anxs.postgresql
Example Playbook
Here's how to use this role in a playbook:
---
- hosts: postgresql-server
roles:
- role: ANXS.postgresql
become: yes
And here's how to use this role as a task:
---
- hosts: postgresql-server
tasks:
- block:
- name: Install and configure PSQL
include_role:
name: ANXS.postgresql
vars:
postgresql_users:
- name: abc
password: abc
become: true
Dependencies
- If you want to use
monit
for protection, include ANXS.monit (Galaxy/GH) and setmonit_protection: true
.
Compatibility Matrix
Distribution / PostgreSQL | 11 | 12 | 13 | 14 | 15 | 16 |
---|---|---|---|---|---|---|
Debian 11.x | :no_entry: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
Debian 12.x | :no_entry: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
Rockylinux 8.x | :no_entry: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
Rockylinux 9.x | :no_entry: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
Ubuntu 20.04.x | :no_entry: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
Ubuntu 22.04.x | :no_entry: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
- :white_check_mark: - tested, works well
- :warning: - not suitable for production
- :grey_question: - will likely work in the future (please help if you can)
- :interrobang: - possibly works, untested
- :no_entry: - no longer supported (End of Life)
Variables
# Basic settings
postgresql_version: 16
postgresql_encoding: "UTF-8"
postgresql_locale: "en_US.UTF-8"
postgresql_ctype: "en_US.UTF-8"
postgresql_admin_user: "postgres"
postgresql_default_auth_method: "peer"
postgresql_cluster_name: main
postgresql_cluster_reset: false
# Optional: list of databases to create
postgresql_databases:
- name: foobar
owner: baz # optional; specify database owner
hstore: yes # install hstore extension? (yes/no)
uuid_ossp: yes # install uuid-ossp extension? (yes/no)
citext: yes # install citext extension? (yes/no)
encoding: "UTF-8" # override global encoding for this DB
state: "present" # optional; can be 'present', 'absent', 'dump', 'restore'
lc_collate: "en_GB.UTF-8" # override global locale for this DB
lc_ctype: "en_GB.UTF-8" # override global ctype for this DB
# Optional: list of database extensions to create
postgresql_database_extensions:
- db: foobar
extensions:
- hstore
- citext
# Optional: list of users to create
postgresql_users:
- name: baz
pass: pass
encrypted: yes # encrypt password? (PostgreSQL >= 10 needs encrypted passwords)
state: "present" # optional; can be 'present', 'absent'
# Optional: list of schemas to create
postgresql_database_schemas:
- database: foobar # database name
schema: acme # schema name
state: present
- database: foobar # database name
schema: acme_baz # schema name
owner: baz # schema owner
state: present
# Optional: list of user privileges to apply
postgresql_user_privileges:
- name: baz # user name
db: foobar # database
priv: "ALL" # privilege string format
role_attr_flags: "CREATEDB" # role attribute flags
There are many more settings available in the defaults/main.yml.
Testing - Molecule
This project includes a molecule configuration. See ./molecule/README.md.
To run tests:
molecule test
Testing - Vagrant
A Vagrantfile is included for easy testing of role changes. Start by running vagrant up
.
Check the Vagrant documentation for setup instructions.
Once your VM is running, you can reprovision it using either vagrant provision
or ansible-playbook tests/playbook.yml -i vagrant-inventory
.
Feel free to edit the test playbook in tests/playbook.yml and modify variables in tests/vars.yml.
If you're contributing, please test changes in the Vagrant environment and ensure they are included in tests defined in .travis.yml.
License
This project is licensed under the MIT License. See the LICENSE file for more information.
Thanks
Creator:
Maintainers:
- Jonathan Lozada D.
- Jonathan Freedman
- Sergei Antipov
- Greg Clough
- Magnus Lübeck
- Leo C.
- Laurent Lavaud
Top Contributors:
- David Farrington
- Jesse Lang
- Michael Conrad
- Sébastien Alix
- Copperfield
- T. Soulabail
- Ralph von der Heyden
Feedback, Bug Reports, Requests...
Your input is welcome!
Install and configure PostgreSQL, dependencies, extensions, databases and users.
ansible-galaxy install ANXS.postgresql