Compare commits
9 Commits
5755e3160d
...
4c541fb79d
Author | SHA1 | Date | |
---|---|---|---|
4c541fb79d | |||
bff5cce7e9 | |||
2edb0eae52 | |||
7c2f8277a7 | |||
96de942f51 | |||
6625557bfa | |||
9b3af2f6d4 | |||
f2aa516b13 | |||
39fed04d33 |
@ -11,6 +11,9 @@
|
|||||||
- [`mariadb`](roles/mariadb/README.md): deploy mariadb
|
- [`mariadb`](roles/mariadb/README.md): deploy mariadb
|
||||||
in a docker container
|
in a docker container
|
||||||
|
|
||||||
|
- [`postgresql`](roles/postgresql/README.md): deploy postgresql,
|
||||||
|
the worlds most advances open-source relational database
|
||||||
|
|
||||||
- [`valkey`](roles/valkey/README.md): deploy and configure valkey,
|
- [`valkey`](roles/valkey/README.md): deploy and configure valkey,
|
||||||
an open source in-memory data store under BSD license, forked
|
an open source in-memory data store under BSD license, forked
|
||||||
from redis.
|
from redis.
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
namespace: finallycoffee
|
namespace: finallycoffee
|
||||||
name: databases
|
name: databases
|
||||||
version: 0.1.0
|
version: 0.1.1
|
||||||
readme: README.md
|
readme: README.md
|
||||||
authors:
|
authors:
|
||||||
- transcaffeine <transcaffeine@finally.coffee>
|
- transcaffeine <transcaffeine@finally.coffee>
|
||||||
@ -16,5 +16,7 @@ tags:
|
|||||||
- elasticsearch
|
- elasticsearch
|
||||||
- redis
|
- redis
|
||||||
- mariadb
|
- mariadb
|
||||||
|
- postgresql
|
||||||
|
- postgres
|
||||||
- valkey
|
- valkey
|
||||||
- docker
|
- docker
|
||||||
|
6
playbooks/postgresql.yml
Normal file
6
playbooks/postgresql.yml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
- name: Deploy and configure PostgreSQL
|
||||||
|
hosts: "{{ postgresql_hosts | default('postgresql', true) }}"
|
||||||
|
become: "{{ postgresql_become | default(true, true) }}"
|
||||||
|
roles:
|
||||||
|
- role: finallycoffee.databases.postgresql
|
@ -1,5 +1,5 @@
|
|||||||
---
|
---
|
||||||
elasticsearch_version: 8.15.3
|
elasticsearch_version: "8.17.0"
|
||||||
elasticsearch_state: present
|
elasticsearch_state: present
|
||||||
|
|
||||||
elasticsearch_base_path: /opt/elasticsearch
|
elasticsearch_base_path: /opt/elasticsearch
|
||||||
|
@ -34,6 +34,5 @@
|
|||||||
volumes: "{{ elasticsearch_container_volumes }}"
|
volumes: "{{ elasticsearch_container_volumes }}"
|
||||||
ulimits: "{{ elasticsearch_container_ulimits }}"
|
ulimits: "{{ elasticsearch_container_ulimits }}"
|
||||||
networks: "{{ elasticsearch_container_networks | default(omit, True) }}"
|
networks: "{{ elasticsearch_container_networks | default(omit, True) }}"
|
||||||
purge_networks: "{{ elasticsearch_container_purge_networks | default(omit, True) }}"
|
|
||||||
restart_policy: "{{ elasticsearch_container_restart_policy }}"
|
restart_policy: "{{ elasticsearch_container_restart_policy }}"
|
||||||
state: "{{ elasticsearch_container_state }}"
|
state: "{{ elasticsearch_container_state }}"
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
---
|
---
|
||||||
mariadb_version: "10.11.9"
|
mariadb_version: "10.11.10"
|
||||||
mariadb_base_path: /var/lib/mariadb
|
mariadb_base_path: /var/lib/mariadb
|
||||||
mariadb_data_path: >-2
|
mariadb_data_path: >-2
|
||||||
{{ mariadb_base_path }}/{{ mariadb_version | split('.') | first }}
|
{{ mariadb_base_path }}/{{ mariadb_version | split('.') | first }}
|
||||||
|
@ -16,6 +16,5 @@
|
|||||||
volumes: "{{ mariadb_container_volumes }}"
|
volumes: "{{ mariadb_container_volumes }}"
|
||||||
networks: "{{ mariadb_container_networks | default(omit, true) }}"
|
networks: "{{ mariadb_container_networks | default(omit, true) }}"
|
||||||
etc_hosts: "{{ mariadb_container_etc_hosts | default(omit, true) }}"
|
etc_hosts: "{{ mariadb_container_etc_hosts | default(omit, true) }}"
|
||||||
purge_networks: "{{ mariadb_container_purge_networks | default(omit, true) }}"
|
|
||||||
restart_policy: "{{ mariadb_container_restart_policy }}"
|
restart_policy: "{{ mariadb_container_restart_policy }}"
|
||||||
state: "{{ mariadb_container_state }}"
|
state: "{{ mariadb_container_state }}"
|
||||||
|
4
roles/postgresql/README.md
Normal file
4
roles/postgresql/README.md
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
# `finallycoffee.databases.postgresql` ansible role
|
||||||
|
|
||||||
|
PostgreSQL is the self proclaimed "world's most advanced" open source relational
|
||||||
|
database. This ansible role can deploy and configure postgresql.
|
39
roles/postgresql/defaults/main/container.yml
Normal file
39
roles/postgresql/defaults/main/container.yml
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
---
|
||||||
|
postgresql_container_image_registry: docker.io
|
||||||
|
postgresql_container_image_namespace: ~
|
||||||
|
postgresql_container_image_name: postgres
|
||||||
|
postgresql_container_image_tag: ~
|
||||||
|
postgresql_container_image_source: pull
|
||||||
|
postgresql_container_image_force_source: >-2
|
||||||
|
{{ postgresql_container_image_tag | default(false, true) | bool }}
|
||||||
|
postgresql_container_image: >-2
|
||||||
|
{{
|
||||||
|
([
|
||||||
|
postgresql_container_image_registry | default([], true),
|
||||||
|
postgresql_container_image_namespace | default([], true),
|
||||||
|
postgresql_container_image_name
|
||||||
|
] | flatten | join('/'))
|
||||||
|
+ ':' + postgresql_container_image_tag | default(
|
||||||
|
postgresql_version + (
|
||||||
|
((postgresql_container_image_flavour is string)
|
||||||
|
and (postgresql_container_image_flavour | length > 0))
|
||||||
|
| ternary(
|
||||||
|
'_' + postgresql_container_image_flavour | default('', true),
|
||||||
|
'',
|
||||||
|
)
|
||||||
|
),
|
||||||
|
true
|
||||||
|
)
|
||||||
|
}}
|
||||||
|
|
||||||
|
postgresql_container_name: postgresql
|
||||||
|
postgresql_container_env: ~
|
||||||
|
postgresql_container_user: >-2
|
||||||
|
{{ postgresql_user_id }}:{{ postgresql_user_group_id }}
|
||||||
|
postgresql_container_ports: ~
|
||||||
|
postgresql_container_labels: ~
|
||||||
|
postgresql_container_networks: ~
|
||||||
|
postgresql_container_recreate: ~
|
||||||
|
postgresql_container_restart_policy: "on-failure"
|
||||||
|
postgresql_container_state: >-2
|
||||||
|
{{ (postgresql_state == 'present') | ternary('started', 'absent') }}
|
18
roles/postgresql/defaults/main/main.yml
Normal file
18
roles/postgresql/defaults/main/main.yml
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
---
|
||||||
|
postgresql_user: postgresql
|
||||||
|
postgresql_version: >-2
|
||||||
|
{{ postgresql_version[postgres_major_version | string] }}
|
||||||
|
postgresql_major_version: 16
|
||||||
|
postgresql_versions:
|
||||||
|
"17": "17.2"
|
||||||
|
"16": "16.6"
|
||||||
|
"15": "15.10"
|
||||||
|
"14": "14.15"
|
||||||
|
|
||||||
|
postgresql_config_path: >-2
|
||||||
|
/etc/postgresql/{{ postgresql_major_version }}
|
||||||
|
postgresql_data_path: >-2
|
||||||
|
/var/lib/postgresql/{{ postgresql_major_version }}
|
||||||
|
|
||||||
|
postgresql_state: present
|
||||||
|
postgresql_deployment_method: docker
|
10
roles/postgresql/defaults/main/user.yml
Normal file
10
roles/postgresql/defaults/main/user.yml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
---
|
||||||
|
postgresql_user_system: true
|
||||||
|
postgresql_user_create_home: false
|
||||||
|
postgresql_user_groups: ~
|
||||||
|
postgresql_user_append: ~
|
||||||
|
|
||||||
|
postgresql_user_id: >-2
|
||||||
|
{{ postgresql_user_info.uid | default(postgresql_user, true) }}
|
||||||
|
postgresql_user_group_id: >-2
|
||||||
|
{{ postgresql_user_info.group | default(postgresql_user, true) }}
|
12
roles/postgresql/meta/main.yml
Normal file
12
roles/postgresql/meta/main.yml
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
---
|
||||||
|
allow_duplicates: true
|
||||||
|
dependencies: []
|
||||||
|
galaxy_info:
|
||||||
|
role_name: postgresql
|
||||||
|
description: >-2
|
||||||
|
PostgreSQL is the self-proclaimed 'worlds most advanced' open source relational database
|
||||||
|
galaxy_tags:
|
||||||
|
- postgresql
|
||||||
|
- postgres
|
||||||
|
- database
|
||||||
|
- docker
|
23
roles/postgresql/tasks/deploy-docker.yml
Normal file
23
roles/postgresql/tasks/deploy-docker.yml
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
---
|
||||||
|
- name: Ensure postgresql container image '{{ postgresql_container_image }}' is {{ postgresql_state }}
|
||||||
|
community.docker.docker_image:
|
||||||
|
name: "{{ postgresql_container_image }}"
|
||||||
|
state: "{{ postgresql_state }}"
|
||||||
|
source: "{{ postgresql_container_image_source }}"
|
||||||
|
force_source: "{{ postgresql_container_image_force_source }}"
|
||||||
|
register: postgresql_container_image_info
|
||||||
|
until: postgresql_container_image_info is success
|
||||||
|
retries: 5
|
||||||
|
delay: 4
|
||||||
|
|
||||||
|
- name: Ensure postgresql container '{{ postgresql_container_name }}' is {{ postgresql_container_state }}
|
||||||
|
community.docker.docker_container:
|
||||||
|
name: "{{ postgresql_container_name }}"
|
||||||
|
image: "{{ postgresql_container_image }}"
|
||||||
|
env: "{{ postgresql_container_env | default(omit, true) }}"
|
||||||
|
user: "{{ postgresql_container_user | default(omit, true) }}"
|
||||||
|
ports: "{{ postgresql_container_ports | default(omit, true) }}"
|
||||||
|
labels: "{{ postgresql_container_labels | default(omit, true) }}"
|
||||||
|
networks: "{{ postgresql_container_networks | default(omit, true) }}"
|
||||||
|
restart_policy: "{{ postgresql_container_restart_policy | default(omit, true) }}"
|
||||||
|
state: "{{ postgresql_container_state }}"
|
63
roles/postgresql/tasks/main.yml
Normal file
63
roles/postgresql/tasks/main.yml
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
---
|
||||||
|
- name: Ensure state is valid
|
||||||
|
ansible.builtin.fail:
|
||||||
|
msg: >-2
|
||||||
|
Invalid state '{{ postgresql_state }}'! Supported
|
||||||
|
states are {{ postgresql_states | join(', ') }}.
|
||||||
|
when: postgresql_state not in postgresql_states
|
||||||
|
|
||||||
|
- name: Ensure deployment method is valid
|
||||||
|
ansible.builtin.fail:
|
||||||
|
msg: >-2
|
||||||
|
Unsupported deployment method '{{ postgresql_deployment_method }}!
|
||||||
|
Supported deployment methods are {{ postgresql_deployment_methods | join(', ') }}.
|
||||||
|
when: postgresql_deployment_method not in postgresql_deployment_methods
|
||||||
|
|
||||||
|
- name: Ensure postgresql user '{{ postgresql_user }}' is {{ postgresql_state }}
|
||||||
|
ansible.builtin.user:
|
||||||
|
name: "{{ postgresql_user }}"
|
||||||
|
state: "{{ postgresql_state }}"
|
||||||
|
system: "{{ postgresql_user_system | default(omit, true) }}"
|
||||||
|
create_home: "{{ postgresql_user_create_home | default(omit, true) }}"
|
||||||
|
groups: "{{ postgresql_user_groups | default(omit, true) }}"
|
||||||
|
append: "{{ postgresql_user_append | default(omit, true) }}"
|
||||||
|
register: postgresql_user_info
|
||||||
|
|
||||||
|
- name: Ensure directories are {{ postgresql_state }}
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: "{{ path.name }}"
|
||||||
|
state: "{{ (postgresql_state == 'present') | ternary('directory', 'absent') }}"
|
||||||
|
owner: "{{ path.owner | default(postgresql_user_id, true) }}"
|
||||||
|
group: "{{ path.group | default(postgresql_user_group_id, true) }}"
|
||||||
|
mode: "{{ path.mode | default('0755', true) }}"
|
||||||
|
loop:
|
||||||
|
- name: "{{ postgresql_config_path }}"
|
||||||
|
- name: "{{ postgresql_data_path }}"
|
||||||
|
loop_control:
|
||||||
|
loop_var: path
|
||||||
|
label: "{{ path.name }}"
|
||||||
|
|
||||||
|
- name: Check for existing PG_VERSION file
|
||||||
|
ansible.builtin.stat:
|
||||||
|
path: "{{ postgresql_data_path }}/PG_VERSION"
|
||||||
|
register: postgresql_data_dir_version_info
|
||||||
|
|
||||||
|
- name: Read existing PG_VERSION file
|
||||||
|
ansible.builtin.slurp:
|
||||||
|
path: "{{ postgresql_data_path }}/PG_VERSION"
|
||||||
|
register: postgresql_data_dir_version_content
|
||||||
|
when:
|
||||||
|
- postgresql_data_dir_version_info.stat.exists
|
||||||
|
|
||||||
|
- name: Prevent major version changes
|
||||||
|
ansible.builtin.fail:
|
||||||
|
msg: >-2
|
||||||
|
Mismatched postgresql version for the data directory!
|
||||||
|
Aborting...
|
||||||
|
when:
|
||||||
|
- postgresql_data_dir_version_info.stat.exists
|
||||||
|
- "(postgresql_data_dir_version_content | b64decode | int) != (postgresql_major_version | int)"
|
||||||
|
|
||||||
|
- name: Deploy postgresql using {{ postgresql_deployment_method }}
|
||||||
|
ansible.builtin.include_tasks:
|
||||||
|
file: "deploy-{{ postgresql_deployment_method }}.yml"
|
6
roles/postgresql/vars/main.yml
Normal file
6
roles/postgresql/vars/main.yml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
postgresql_states:
|
||||||
|
- present
|
||||||
|
- absent
|
||||||
|
postgresql_deployment_methods:
|
||||||
|
- docker
|
@ -23,4 +23,5 @@
|
|||||||
networks: "{{ redis_container_networks | default(omit, true) }}"
|
networks: "{{ redis_container_networks | default(omit, true) }}"
|
||||||
etc_hosts: "{{ redis_container_etc_hosts | default(omit, true) }}"
|
etc_hosts: "{{ redis_container_etc_hosts | default(omit, true) }}"
|
||||||
dns_servers: "{{ redis_container_dns_servers | default(omit, true) }}"
|
dns_servers: "{{ redis_container_dns_servers | default(omit, true) }}"
|
||||||
|
restart_policy: "{{ redis_container_restart_policy | default(omit, true) }}"
|
||||||
state: "{{ redis_container_state }}"
|
state: "{{ redis_container_state }}"
|
||||||
|
@ -23,4 +23,5 @@
|
|||||||
networks: "{{ valkey_container_networks | default(omit, true) }}"
|
networks: "{{ valkey_container_networks | default(omit, true) }}"
|
||||||
etc_hosts: "{{ valkey_container_etc_hosts | default(omit, true) }}"
|
etc_hosts: "{{ valkey_container_etc_hosts | default(omit, true) }}"
|
||||||
dns_servers: "{{ valkey_container_dns_servers | default(omit, true) }}"
|
dns_servers: "{{ valkey_container_dns_servers | default(omit, true) }}"
|
||||||
|
restart_policy: "{{ valkey_container_restart_policy | default(omit, true) }}"
|
||||||
state: "{{ valkey_container_state }}"
|
state: "{{ valkey_container_state }}"
|
||||||
|
Loading…
Reference in New Issue
Block a user