init postgres role
This commit is contained in:
commit
0b36532711
4
.ansible-lint
Normal file
4
.ansible-lint
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
skip_list:
|
||||||
|
- '405'
|
||||||
|
- '503'
|
||||||
|
- '106'
|
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
*.retry
|
||||||
|
*/__pycache__
|
||||||
|
*.pyc
|
11
.yamllint
Normal file
11
.yamllint
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
---
|
||||||
|
extends: default
|
||||||
|
|
||||||
|
rules:
|
||||||
|
line-length:
|
||||||
|
max: 120
|
||||||
|
level: warning
|
||||||
|
|
||||||
|
ignore: |
|
||||||
|
.github/stale.yml
|
||||||
|
.travis.yml
|
20
LICENSE
Normal file
20
LICENSE
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2017 Jeff Geerling
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
the Software without restriction, including without limitation the rights to
|
||||||
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||||
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
|
subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||||
|
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
|
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
149
README.md
Normal file
149
README.md
Normal file
@ -0,0 +1,149 @@
|
|||||||
|
# Ansible Role: PostgreSQL
|
||||||
|
|
||||||
|
[![Build Status](https://travis-ci.org/geerlingguy/ansible-role-postgresql.svg?branch=master)](https://travis-ci.org/geerlingguy/ansible-role-postgresql)
|
||||||
|
|
||||||
|
Installs and configures PostgreSQL server on RHEL/CentOS or Debian/Ubuntu servers.
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
## Role Variables
|
||||||
|
|
||||||
|
Available variables are listed below, along with default values (see `defaults/main.yml`):
|
||||||
|
|
||||||
|
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"
|
||||||
|
|
||||||
|
Set the state of the service when configuration changes are made. Recommended values are `restarted` or `reloaded`.
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
The user and group under which PostgreSQL will run.
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
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(",") }}'
|
||||||
|
|
||||||
|
Global configuration options that will be set in `postgresql.conf`. Note that for RHEL/CentOS 6 (or very old versions of PostgreSQL), you need to at least override this variable and set the `option` to `unix_socket_directory`.
|
||||||
|
|
||||||
|
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:
|
||||||
|
|
||||||
|
- `type` (required)
|
||||||
|
- `database` (required)
|
||||||
|
- `user` (required)
|
||||||
|
- `address` (one of this or the following two are required)
|
||||||
|
- `ip_address`
|
||||||
|
- `ip_mask`
|
||||||
|
- `auth_method` (required)
|
||||||
|
- `auth_options` (optional)
|
||||||
|
|
||||||
|
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'
|
||||||
|
|
||||||
|
(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'
|
||||||
|
|
||||||
|
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'
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
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]
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
## Dependencies
|
||||||
|
|
||||||
|
None.
|
||||||
|
|
||||||
|
## Example Playbook
|
||||||
|
|
||||||
|
- 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
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
MIT / BSD
|
||||||
|
|
||||||
|
## Author Information
|
||||||
|
|
||||||
|
This role was created in 2016 by [Jeff Geerling](https://www.jeffgeerling.com/), author of [Ansible for DevOps](https://www.ansiblefordevops.com/).
|
69
defaults/main.yml
Normal file
69
defaults/main.yml
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
---
|
||||||
|
# RHEL/CentOS only. Set a repository to use for PostgreSQL installation.
|
||||||
|
postgresql_enablerepo: ""
|
||||||
|
|
||||||
|
# Set postgresql state when configuration changes are made. Recommended values:
|
||||||
|
# `restarted` or `reloaded`
|
||||||
|
postgresql_restarted_state: "restarted"
|
||||||
|
|
||||||
|
postgresql_python_library: python-psycopg2
|
||||||
|
postgresql_user: postgres
|
||||||
|
postgresql_group: postgres
|
||||||
|
|
||||||
|
postgresql_unix_socket_directories:
|
||||||
|
- /var/run/postgresql
|
||||||
|
|
||||||
|
postgresql_service_state: started
|
||||||
|
postgresql_service_enabled: true
|
||||||
|
|
||||||
|
# Global configuration options that will be set in postgresql.conf.
|
||||||
|
postgresql_global_config_options:
|
||||||
|
- option: unix_socket_directories
|
||||||
|
value: '{{ postgresql_unix_socket_directories | join(",") }}'
|
||||||
|
|
||||||
|
# Host based authentication (hba) entries to be added to the pg_hba.conf. This
|
||||||
|
# variable's defaults reflect the defaults that come with a fresh installation.
|
||||||
|
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}
|
||||||
|
|
||||||
|
# Debian only. Used to generate the locales used by PostgreSQL databases.
|
||||||
|
postgresql_locales:
|
||||||
|
- 'fr_FR.UTF-8'
|
||||||
|
|
||||||
|
# Databases to ensure exist.
|
||||||
|
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'
|
||||||
|
|
||||||
|
# Users to ensure exist.
|
||||||
|
postgresql_users:
|
||||||
|
- name: root
|
||||||
|
role_attr_flags: CREATEDB
|
||||||
|
# - 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'
|
||||||
|
|
||||||
|
# Whether to output user data when managing users.
|
||||||
|
postgres_users_no_log: true
|
6
handlers/main.yml
Normal file
6
handlers/main.yml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
- name: restart postgresql
|
||||||
|
service:
|
||||||
|
name: "{{ postgresql_daemon }}"
|
||||||
|
state: "{{ postgresql_restarted_state }}"
|
||||||
|
sleep: 5
|
15
meta/main.yml
Normal file
15
meta/main.yml
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
---
|
||||||
|
dependencies: []
|
||||||
|
|
||||||
|
galaxy_info:
|
||||||
|
role_name: postgresql
|
||||||
|
author: geerlingguy
|
||||||
|
description: PostgreSQL server for Linux.
|
||||||
|
company: "Midwestern Mac, LLC"
|
||||||
|
license: "license (BSD, MIT)"
|
||||||
|
min_ansible_version: 2.8
|
||||||
|
galaxy_tags:
|
||||||
|
- database
|
||||||
|
- postgresql
|
||||||
|
- postgres
|
||||||
|
- rdbms
|
29
tasks/configure.yml
Normal file
29
tasks/configure.yml
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
---
|
||||||
|
- name: Configure global settings.
|
||||||
|
lineinfile:
|
||||||
|
dest: "{{ postgresql_config_path }}/postgresql.conf"
|
||||||
|
regexp: "^#?{{ item.option }}.+$"
|
||||||
|
line: "{{ item.option }} = '{{ item.value }}'"
|
||||||
|
state: "{{ item.state | default('present') }}"
|
||||||
|
mode: 0644
|
||||||
|
with_items: "{{ postgresql_global_config_options }}"
|
||||||
|
notify: restart postgresql
|
||||||
|
|
||||||
|
- name: Configure host based authentication (if entries are configured).
|
||||||
|
template:
|
||||||
|
src: "pg_hba.conf.j2"
|
||||||
|
dest: "{{ postgresql_config_path }}/pg_hba.conf"
|
||||||
|
owner: "{{ postgresql_user }}"
|
||||||
|
group: "{{ postgresql_group }}"
|
||||||
|
mode: 0600
|
||||||
|
notify: restart postgresql
|
||||||
|
when: postgresql_hba_entries | length > 0
|
||||||
|
|
||||||
|
- name: Ensure PostgreSQL unix socket dirs exist.
|
||||||
|
file:
|
||||||
|
path: "{{ item }}"
|
||||||
|
state: directory
|
||||||
|
owner: "{{ postgresql_user }}"
|
||||||
|
group: "{{ postgresql_group }}"
|
||||||
|
mode: "{{ postgresql_unix_socket_directories_mode }}"
|
||||||
|
with_items: "{{ postgresql_unix_socket_directories }}"
|
21
tasks/databases.yml
Normal file
21
tasks/databases.yml
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
---
|
||||||
|
- name: Ensure PostgreSQL databases are present.
|
||||||
|
postgresql_db:
|
||||||
|
name: "{{ item.name }}"
|
||||||
|
lc_collate: "{{ item.lc_collate | default('en_US.UTF-8') }}"
|
||||||
|
lc_ctype: "{{ item.lc_ctype | default('en_US.UTF-8') }}"
|
||||||
|
encoding: "{{ item.encoding | default('UTF-8') }}"
|
||||||
|
template: "{{ item.template | default('template0') }}"
|
||||||
|
login_host: "{{ item.login_host | default('localhost') }}"
|
||||||
|
login_password: "{{ item.login_password | default(omit) }}"
|
||||||
|
login_user: "{{ item.login_user | default(postgresql_user) }}"
|
||||||
|
login_unix_socket: "{{ item.login_unix_socket | default(postgresql_unix_socket_directories[0]) }}"
|
||||||
|
port: "{{ item.port | default(omit) }}"
|
||||||
|
owner: "{{ item.owner | default(postgresql_user) }}"
|
||||||
|
state: "{{ item.state | default('present') }}"
|
||||||
|
with_items: "{{ postgresql_databases }}"
|
||||||
|
become: true
|
||||||
|
become_user: "{{ postgresql_user }}"
|
||||||
|
# See: https://github.com/ansible/ansible/issues/16048#issuecomment-229012509
|
||||||
|
vars:
|
||||||
|
ansible_ssh_pipelining: true
|
29
tasks/initialize.yml
Normal file
29
tasks/initialize.yml
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
---
|
||||||
|
- name: Set PostgreSQL environment variables.
|
||||||
|
template:
|
||||||
|
src: postgres.sh.j2
|
||||||
|
dest: /etc/profile.d/postgres.sh
|
||||||
|
mode: 0644
|
||||||
|
notify: restart postgresql
|
||||||
|
|
||||||
|
- name: Ensure PostgreSQL data directory exists.
|
||||||
|
file:
|
||||||
|
path: "{{ postgresql_data_dir }}"
|
||||||
|
owner: "{{ postgresql_user }}"
|
||||||
|
group: "{{ postgresql_group }}"
|
||||||
|
state: directory
|
||||||
|
mode: 0700
|
||||||
|
|
||||||
|
- name: Check if PostgreSQL database is initialized.
|
||||||
|
stat:
|
||||||
|
path: "{{ postgresql_data_dir }}/PG_VERSION"
|
||||||
|
register: pgdata_dir_version
|
||||||
|
|
||||||
|
- name: Ensure PostgreSQL database is initialized.
|
||||||
|
command: "{{ postgresql_bin_path }}/initdb -D {{ postgresql_data_dir }}"
|
||||||
|
when: not pgdata_dir_version.stat.exists
|
||||||
|
become: true
|
||||||
|
become_user: "{{ postgresql_user }}"
|
||||||
|
# See: https://github.com/ansible/ansible/issues/16048#issuecomment-229012509
|
||||||
|
vars:
|
||||||
|
ansible_ssh_pipelining: true
|
26
tasks/main.yml
Normal file
26
tasks/main.yml
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
---
|
||||||
|
# Variable configuration.
|
||||||
|
- include_tasks: variables.yml
|
||||||
|
|
||||||
|
# Setup/install tasks.
|
||||||
|
- include_tasks: setup-RedHat.yml
|
||||||
|
when: ansible_os_family == 'RedHat'
|
||||||
|
|
||||||
|
- include_tasks: setup-Debian.yml
|
||||||
|
when: ansible_os_family == 'Debian'
|
||||||
|
|
||||||
|
- include_tasks: setup-Arch.yml
|
||||||
|
when: ansible_os_family == 'Archlinux'
|
||||||
|
|
||||||
|
- include_tasks: initialize.yml
|
||||||
|
- include_tasks: configure.yml
|
||||||
|
|
||||||
|
- name: Ensure PostgreSQL is started and enabled on boot.
|
||||||
|
service:
|
||||||
|
name: "{{ postgresql_daemon }}"
|
||||||
|
state: "{{ postgresql_service_state }}"
|
||||||
|
enabled: "{{ postgresql_service_enabled }}"
|
||||||
|
|
||||||
|
# Configure PostgreSQL.
|
||||||
|
- import_tasks: users.yml
|
||||||
|
- import_tasks: databases.yml
|
21
tasks/setup-Arch.yml
Normal file
21
tasks/setup-Arch.yml
Normal 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.
|
||||||
|
service:
|
||||||
|
name: "{{ postgresql_daemon }}"
|
||||||
|
state: restarted
|
||||||
|
when: locale_gen_result.changed
|
21
tasks/setup-Debian.yml
Normal file
21
tasks/setup-Debian.yml
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
---
|
||||||
|
- name: Ensure PostgreSQL Python libraries are installed.
|
||||||
|
apt:
|
||||||
|
name: "{{ postgresql_python_library }}"
|
||||||
|
state: present
|
||||||
|
|
||||||
|
- name: Ensure PostgreSQL packages are installed.
|
||||||
|
apt:
|
||||||
|
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.
|
||||||
|
service:
|
||||||
|
name: "{{ postgresql_daemon }}"
|
||||||
|
state: restarted
|
||||||
|
when: locale_gen_result.changed
|
16
tasks/setup-RedHat.yml
Normal file
16
tasks/setup-RedHat.yml
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
---
|
||||||
|
- name: Ensure PostgreSQL packages are installed.
|
||||||
|
yum:
|
||||||
|
name: "{{ postgresql_packages }}"
|
||||||
|
state: present
|
||||||
|
enablerepo: "{{ postgresql_enablerepo | default(omit, true) }}"
|
||||||
|
# Don't let postgresql-contrib cause the /usr/bin/python symlink
|
||||||
|
# to be installed, which breaks later Ansible runs on Fedora 30,
|
||||||
|
# and affects system behavior in multiple ways.
|
||||||
|
exclude: python-unversioned-command
|
||||||
|
|
||||||
|
- name: Ensure PostgreSQL Python libraries are installed.
|
||||||
|
yum:
|
||||||
|
name: "{{ postgresql_python_library }}"
|
||||||
|
state: present
|
||||||
|
enablerepo: "{{ postgresql_enablerepo | default(omit, true) }}"
|
22
tasks/users.yml
Normal file
22
tasks/users.yml
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
---
|
||||||
|
- name: Ensure PostgreSQL users are present.
|
||||||
|
postgresql_user:
|
||||||
|
name: "{{ item.name }}"
|
||||||
|
password: "{{ item.password | default(omit) }}"
|
||||||
|
encrypted: "{{ item.encrypted | default(omit) }}"
|
||||||
|
priv: "{{ item.priv | default(omit) }}"
|
||||||
|
role_attr_flags: "{{ item.role_attr_flags | default(omit) }}"
|
||||||
|
db: "{{ item.db | default(omit) }}"
|
||||||
|
login_host: "{{ item.login_host | default('localhost') }}"
|
||||||
|
login_password: "{{ item.login_password | default(omit) }}"
|
||||||
|
login_user: "{{ item.login_user | default(postgresql_user) }}"
|
||||||
|
login_unix_socket: "{{ item.login_unix_socket | default(postgresql_unix_socket_directories[0]) }}"
|
||||||
|
port: "{{ item.port | default(omit) }}"
|
||||||
|
state: "{{ item.state | default('present') }}"
|
||||||
|
with_items: "{{ postgresql_users }}"
|
||||||
|
no_log: "{{ postgres_users_no_log }}"
|
||||||
|
become: true
|
||||||
|
become_user: "{{ postgresql_user }}"
|
||||||
|
# See: https://github.com/ansible/ansible/issues/16048#issuecomment-229012509
|
||||||
|
vars:
|
||||||
|
ansible_ssh_pipelining: true
|
56
tasks/variables.yml
Normal file
56
tasks/variables.yml
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
---
|
||||||
|
# Variable configuration.
|
||||||
|
- name: Include OS-specific variables (Debian).
|
||||||
|
include_vars: "{{ ansible_distribution }}-{{ ansible_distribution_version.split('.')[0] }}.yml"
|
||||||
|
when: ansible_os_family == 'Debian'
|
||||||
|
|
||||||
|
- 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'
|
||||||
|
|
||||||
|
- name: Include OS-specific variables (Fedora).
|
||||||
|
include_vars: "{{ ansible_distribution }}-{{ ansible_distribution_version.split('.')[0] }}.yml"
|
||||||
|
when: ansible_distribution == 'Fedora'
|
||||||
|
|
||||||
|
- name: Include OS-specific variables (arch).
|
||||||
|
include_vars: "{{ ansible_os_family }}.yml"
|
||||||
|
when: ansible_facts['os_family'] == "Archlinux"
|
||||||
|
|
||||||
|
|
||||||
|
- name: Define postgresql_packages.
|
||||||
|
set_fact:
|
||||||
|
postgresql_packages: "{{ __postgresql_packages | list }}"
|
||||||
|
when: postgresql_packages is not defined
|
||||||
|
|
||||||
|
- name: Define postgresql_version.
|
||||||
|
set_fact:
|
||||||
|
postgresql_version: "{{ __postgresql_version }}"
|
||||||
|
when: postgresql_version is not defined
|
||||||
|
|
||||||
|
- name: Define postgresql_daemon.
|
||||||
|
set_fact:
|
||||||
|
postgresql_daemon: "{{ __postgresql_daemon }}"
|
||||||
|
when: postgresql_daemon is not defined
|
||||||
|
|
||||||
|
- name: Define postgresql_data_dir.
|
||||||
|
set_fact:
|
||||||
|
postgresql_data_dir: "{{ __postgresql_data_dir }}"
|
||||||
|
when: postgresql_data_dir is not defined
|
||||||
|
|
||||||
|
- name: Define postgresql_bin_path.
|
||||||
|
set_fact:
|
||||||
|
postgresql_bin_path: "{{ __postgresql_bin_path }}"
|
||||||
|
when: postgresql_bin_path is not defined
|
||||||
|
|
||||||
|
- name: Define postgresql_config_path.
|
||||||
|
set_fact:
|
||||||
|
postgresql_config_path: "{{ __postgresql_config_path }}"
|
||||||
|
when: postgresql_config_path is not defined
|
||||||
|
|
||||||
|
- name: Define postgresql_unix_socket_directories_mode.
|
||||||
|
set_fact:
|
||||||
|
postgresql_unix_socket_directories_mode: >-
|
||||||
|
{{ __postgresql_unix_socket_directories_mode | default('02775') }}
|
||||||
|
when: postgresql_unix_socket_directories_mode is not defined
|
9
templates/pg_hba.conf.j2
Normal file
9
templates/pg_hba.conf.j2
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
{{ ansible_managed | comment }}
|
||||||
|
# PostgreSQL Client Authentication Configuration File
|
||||||
|
# ===================================================
|
||||||
|
#
|
||||||
|
# See: https://www.postgresql.org/docs/current/static/auth-pg-hba-conf.html
|
||||||
|
|
||||||
|
{% for client in postgresql_hba_entries %}
|
||||||
|
{{ client.type }} {{ client.database }} {{ client.user }} {{ client.address|default('') }} {{ client.ip_address|default('') }} {{ client.ip_mask|default('') }} {{ client.auth_method }} {{ client.auth_options|default("") }}
|
||||||
|
{% endfor %}
|
2
templates/postgres.sh.j2
Normal file
2
templates/postgres.sh.j2
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
export PGDATA={{ postgresql_data_dir }}
|
||||||
|
export PATH=$PATH:{{ postgresql_bin_path }}
|
9
vars/Archlinux.yml
Normal file
9
vars/Archlinux.yml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
---
|
||||||
|
__postgresql_version: "NC"
|
||||||
|
__postgresql_data_dir: "/var/lib/postgres/data"
|
||||||
|
__postgresql_bin_path: "/usr/bin"
|
||||||
|
__postgresql_config_path: "/var/lib/postgres/data"
|
||||||
|
__postgresql_daemon: "postgresql"
|
||||||
|
__postgresql_packages:
|
||||||
|
- postgresql
|
||||||
|
|
12
vars/Debian-10.yml
Normal file
12
vars/Debian-10.yml
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
---
|
||||||
|
__postgresql_version: "11"
|
||||||
|
__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_packages:
|
||||||
|
- postgresql
|
||||||
|
- postgresql-contrib
|
||||||
|
- libpq-dev
|
||||||
|
# Debian 10 uses Python 3 by default.
|
||||||
|
postgresql_python_library: python3-psycopg2
|
10
vars/Debian-7.yml
Normal file
10
vars/Debian-7.yml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
---
|
||||||
|
__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
|
10
vars/Debian-8.yml
Normal file
10
vars/Debian-8.yml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
---
|
||||||
|
__postgresql_version: "9.4"
|
||||||
|
__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_packages:
|
||||||
|
- postgresql
|
||||||
|
- postgresql-contrib
|
||||||
|
- libpq-dev
|
10
vars/Debian-9.yml
Normal file
10
vars/Debian-9.yml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
---
|
||||||
|
__postgresql_version: "9.6"
|
||||||
|
__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_packages:
|
||||||
|
- postgresql
|
||||||
|
- postgresql-contrib
|
||||||
|
- libpq-dev
|
12
vars/Fedora-29.yml
Normal file
12
vars/Fedora-29.yml
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
---
|
||||||
|
__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
|
13
vars/Fedora-30.yml
Normal file
13
vars/Fedora-30.yml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
---
|
||||||
|
__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
|
14
vars/Fedora-31.yml
Normal file
14
vars/Fedora-31.yml
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
---
|
||||||
|
__postgresql_version: "11.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_unix_socket_directories_mode: '0755'
|
||||||
|
# Fedora 31 containers only have python3 by default
|
||||||
|
postgresql_python_library: python3-psycopg2
|
14
vars/Fedora-32.yml
Normal file
14
vars/Fedora-32.yml
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
---
|
||||||
|
__postgresql_version: "12.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
|
||||||
|
__postgresql_unix_socket_directories_mode: '0755'
|
||||||
|
# Fedora 32 containers only have python3 by default
|
||||||
|
postgresql_python_library: python3-psycopg2
|
11
vars/RedHat-6.yml
Normal file
11
vars/RedHat-6.yml
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
---
|
||||||
|
__postgresql_version: "8.4"
|
||||||
|
__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
|
11
vars/RedHat-7.yml
Normal file
11
vars/RedHat-7.yml
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
---
|
||||||
|
__postgresql_version: "9.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
|
12
vars/RedHat-8.yml
Normal file
12
vars/RedHat-8.yml
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
---
|
||||||
|
__postgresql_version: "10"
|
||||||
|
__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_unix_socket_directories_mode: '0755'
|
||||||
|
postgresql_python_library: python3-psycopg2
|
10
vars/Ubuntu-16.yml
Normal file
10
vars/Ubuntu-16.yml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
---
|
||||||
|
__postgresql_version: "9.5"
|
||||||
|
__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
|
11
vars/Ubuntu-18.yml
Normal file
11
vars/Ubuntu-18.yml
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
---
|
||||||
|
__postgresql_version: "10"
|
||||||
|
__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
|
||||||
|
postgresql_python_library: python3-psycopg2
|
11
vars/Ubuntu-20.yml
Normal file
11
vars/Ubuntu-20.yml
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
---
|
||||||
|
__postgresql_version: "12"
|
||||||
|
__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
|
||||||
|
postgresql_python_library: python3-psycopg2
|
Loading…
Reference in New Issue
Block a user