ansible-role-postgresql/README.md

128 lines
4.4 KiB
Markdown
Raw Normal View History

2021-09-10 12:09:38 +00:00
# Ansible role: Postgresql
2021-09-10 12:14:32 +00:00
[![Version](https://img.shields.io/badge/latest_version-1.0.0-green.svg)](https://git.yaegashi.fr/nishiki/ansible-role-postgresql/releases)
2021-09-10 12:09:38 +00:00
[![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](https://git.yaegashi.fr/nishiki/ansible-role-postgresql/src/branch/master/LICENSE)
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 to true if you want official postgresql repository |
| 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_config
See all options on [postgresql documentation](https://www.postgresql.org/docs/current/runtime-config.html)
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
```
## 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](https://docs.docker.com/engine/installation/)
* install `python3` and `python3-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.
```