No description
defaults | ||
handlers | ||
meta | ||
molecule/default | ||
tasks | ||
templates | ||
.gitignore | ||
.yamllint | ||
CHANGELOG.md | ||
LICENSE | ||
README.md |
Ansible role: Postgresql
Install and configure Postgresql
Requirements
- Ansible >= 2.9
- Debian
- Buster
- Bullseye
Role variables
Name | Type | Required | Default | Comment |
---|---|---|---|---|
postgresql_version | str | no | 13 | the major version to use |
postgresql_use_official_repository | bool | no | false | set true if you want official postgresql repository |
postgresql_primary | bool | no | false | set true to create user and database on this server |
postgresql_config | dict | no | add option config file | |
postgresql_databases | array | no | the database to manage | |
postgresql_users | array | no | the users to manage | |
postgresql_hba | array | no | the hba authorizations |
postgresql_config
See all options on postgresql documentation
Example:
listen_addresses: '*'
port: 5432
ssl: true
unix_socket_directories: /var/run/postgresql
postgresql_databases
Name | Type | Required | Default | Comment |
---|---|---|---|---|
name | str | yes | the database name | |
encoding | str | no | UTF-8 | encoding to use |
lc_collate | str | no | C.UTF-8 | lc_collate to use |
lc_ctype | str | no | C.UTF-8 | lc_ctype to use |
template | str | no | template0 | template to use |
state | str | no | present | if absent the database is deleted |
Example:
- name: test
encoding: UTF-8
state: present
postgresql_users
Name | Type | Required | Default | Comment |
---|---|---|---|---|
name | str | yes | the user name | |
password | str | yes | the password to logon | |
database | str | yes | the database where user's permissions will be granted | |
privileges | array | yes | list with the user's privileges | |
state | str | no | present | if absent the user is deleted |
Example:
- name: user1
password: secret
database: test
privileges:
- SELECT
- table1:INSERT
state: present
postgresql_hba
Name | Type | Required | Default | Comment |
---|---|---|---|---|
type | str | yes | connection type (host, hostssl, local) | |
databases | array | yes | array with the database names or all string | |
users | array | yes | array with the user names or all string | |
subnet | str | no | allow subnet, not require if type is local | |
method | str | yes | auth method (trust, md5, ...) |
Example:
- type: hostssl
databases:
- myappli
users: all
subnet: samenet
method: md5
How to use
- hosts: server
roles:
- postgresql
vars:
postgresql_use_official_repository: true
postgresql_config:
listen_addresses: '*'
postgresql_databases:
- name: test
postgresql_users
- name: user1
password: secret
database: test
privileges:
- SELECT
- table1:INSERT
Development
Test with molecule and docker
- install docker
- install
python3
andpython3-pip
- install molecule and dependencies
pip3 install molecule molecule-docker docker ansible-lint testinfra yamllint
- run
molecule test
License
Copyright (c) 2021 Adrien Waksberg
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.