• Stars
    star
    854
  • Rank 53,369 (Top 2 %)
  • Language Jinja
  • License
    MIT License
  • Created over 10 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Fairly full featured Ansible role for Postgresql.

ANXS - PostgreSQL Build Status


Help Wanted! If you are able and willing to help maintain this Ansible role then please open a GitHub issue. A lot of people seem to use this role and we (quite obviously) need assistance! ๐Ÿ’–

Ansible role which installs and configures PostgreSQL, extensions, databases and users.

Installation

This has been tested on Ansible 2.4.0 and higher.

To install:

ansible-galaxy install anxs.postgresql

Example Playbook

An example how to include this role:

---
- hosts: postgresql-server
  roles:
    - role: ANXS.postgresql
      become: yes

An example how to include this role as a task:

---
- hosts: postgresql-server
  tasks:
    - block: # workaround, see https://stackoverflow.com/a/56558842
        - name: PSQL installation and configuration
          include_role:
            name: ANXS.postgresql
          vars:
            postgresql_users:
              - name: abc
                password: abc
      become: true

Dependencies

  • ANXS.monit (Galaxy/GH) if you want monit protection (in that case, you should set monit_protection: true)

Compatibility matrix

Distribution / PostgreSQL 9.6 10 11 12 13
CentOS 7.x โœ… โœ… โœ… โœ… โœ…
CentOS 8.x โœ… โœ… โœ… โœ… โœ…
Debian 9.x โœ… โœ… โœ… โœ… โœ…
Debian 10.x โ” โ” โ” โ” โ”
Ubuntu 16.04.x โœ… โœ… โœ… โœ… โœ…
Ubuntu 18.04.x โœ… โœ… โœ… โœ… โœ…
Ubuntu 20.04.x โœ… โœ… โœ… โœ… โœ…
Fedora 33 โ” โ” โ” โ” โ”
  • โœ… - tested, works fine
  • โš ๏ธ - Not for production use
  • โ” - will work in the future (help out if you can)
  • โ‰๏ธ - maybe works, not tested
  • โ›” - Has reached End of Life (EOL)

Variables

# Basic settings
postgresql_version: 13
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_service_enabled: false # should the service be enabled, default is true

postgresql_cluster_name: "main"
postgresql_cluster_reset: false

# List of databases to be created (optional)
# Note: for more flexibility with extensions use the postgresql_database_extensions setting.
postgresql_databases:
  - name: foobar
    owner: baz          # optional; specify the owner of the database
    hstore: yes         # flag to install the hstore extension on this database (yes/no)
    uuid_ossp: yes      # flag to install the uuid-ossp extension on this database (yes/no)
    citext: yes         # flag to install the citext extension on this database (yes/no)
    encoding: "UTF-8"   # override global {{ postgresql_encoding }} variable per database
    state: "present"    # optional; one of 'present', 'absent', 'dump', 'restore'
    lc_collate: "en_GB.UTF-8"   # override global {{ postgresql_locale }} variable per database
    lc_ctype: "en_GB.UTF-8"     # override global {{ postgresql_ctype }} variable per database

# List of database extensions to be created (optional)
postgresql_database_extensions:
  - db: foobar
    extensions:
      - hstore
      - citext

# List of users to be created (optional)
postgresql_users:
  - name: baz
    pass: pass
    encrypted: yes  # if password should be encrypted, postgresql >= 10 does only accepts encrypted passwords
    state: "present"    # optional; one of 'present', 'absent'

# List of schemas to be created (optional)
postgresql_database_schemas:
  - database: foobar           # database name
    schema: acme               # schema name
    state: present

  - database: foobar           # database name
    schema: acme_baz           # schema name
    owner: baz                 # owner name
    state: present

# List of user privileges to be applied (optional)
postgresql_user_privileges:
  - name: baz                   # user name
    db: foobar                  # database
    priv: "ALL"                 # privilege string format: example: INSERT,UPDATE/table:SELECT/anothertable:ALL
    role_attr_flags: "CREATEDB" # role attribute flags

There's a lot more knobs and bolts to set, which you can find in the defaults/main.yml

Testing - Molecule

This project comes with a molecule configuration. Please see ./molecule/README.md

Examples:

molecule test

Testing - Vagrant

This project comes with a Vagrantfile, this is a fast and easy way to test changes to the role, fire it up with vagrant up

See vagrant docs for getting setup with vagrant

Once your VM is up, you can reprovision it using either vagrant provision, or ansible-playbook tests/playbook.yml -i vagrant-inventory

If you want to toy with the test play, see tests/playbook.yml, and change the variables in tests/vars.yml

If you are contributing, please first test your changes within the vagrant environment, (using the targeted distribution), and if possible, ensure your change is covered in the tests found in .travis.yml

License

Licensed under the MIT License. See the LICENSE file for details.

Thanks

Creator:

Maintainers:

Top Contributors:

Feedback, bug-reports, requests, ...

Are welcome!

More Repositories

1

the-ansibles

One of the most extensive sets of ansible roles/examples, including a vagrant testbox and a setup to quickly run your full-featured and secured personal cloudbox.
Shell
396
star
2

nginx

A fairly flexible and feature full Ansible role for the NGINX web server.
Shell
150
star
3

mysql

Ansible role for MySQL
Shell
94
star
4

monit

Ansible role that configures monit. Will also setup baseline monitoring of SSH, NTP, and Cron.
37
star
5

fail2ban

Ansible role for fail2ban
Jinja
32
star
6

hostname

Ansible role to set/update the hostname
32
star
7

utilities

Ansible role for a series of useful, must-have utilities
31
star
8

generic-users

Ansible role for managing user accounts. Includes a module to help generate the user var structure.
Python
30
star
9

nodejs

Ansible role for nodejs
Shell
21
star
10

build-essential

Ansible role for packages required for compiling C software from source.
15
star
11

apt

Ansible role for apt
Jinja
14
star
12

ntp

Ansible role for ntp
Shell
12
star
13

openssh

Ansible role for openssh
11
star
14

git

Ansible role for git
9
star
15

erlang

Ansible role for erlang
9
star
16

python

Ansible role for python
7
star
17

cassandra

Ansible role for Cassandra
7
star
18

cron

Ansible role for cron
6
star
19

perl

Ansible role for perl
6
star
20

generic-directories

A simple Ansible role which will manage static directories on a host.
6
star
21

oracle-jdk

Ansible for Oracle JDK
5
star
22

timezone

Ansible role to set/update the timezone
5
star
23

logwatch

Ansible role for logwatch
5
star
24

tmpreaper

Ansible role for tmpreaper
3
star
25

vim

Ansible role for vim
3
star
26

scala

Ansible role for scala
2
star
27

bootstraps

Ansible role for running bootstrap scripts
2
star
28

clojure

Ansible role for clojure
Shell
1
star