Compare commits

...

10 Commits

10 changed files with 186 additions and 13 deletions

18
galaxy.yml Normal file
View File

@ -0,0 +1,18 @@
namespace: finallycoffee
name: databases
version: 0.1.0
readme: README.md
authors:
- transcaffeine <transcaffeine@finally.coffee>
description: Collection for deploying and configuring databases
dependencies:
"community.docker": "^3.0.0"
license_file: LICENSE.md
build_ignore:
- '*.tar.gz'
repository: https://git.finally.coffee/finallycoffee/databases
issues: https://codeberg.org/finallycoffee/ansible-collection-databases/issues
tags:
- elasticsearch
- mariadb
- docker

2
meta/runtime.yml Normal file
View File

@ -0,0 +1,2 @@
---
requires_ansible: ">=2.15"

View File

@ -0,0 +1,22 @@
# `finallycoffee.base.elastiscsearch`
A simple ansible role which deploys a single-node elastic container to provide
an easy way to do some indexing.
## Usage
Per default, `/opt/elasticsearch/data` is used to persist data, it is
customizable by using either `elasticsearch_base_path` or `elasticsearch_data_path`.
As elasticsearch be can be quite memory heavy, the maximum amount of allowed RAM
can be configured using `elasticsearch_allocated_ram_mb`, defaulting to 512 (mb).
The cluster name and discovery type can be overridden using
`elasticsearch_config_cluster_name` (default: elastic) and
`elasticsearch_config_discovery_type` (default: single-node), should one
need a multi-node elasticsearch deployment.
Per default, no ports or networks are mapped, and explizit mapping using
either ports (`elasticsearch_container_ports`) or networks
(`elasticsearch_container_networks`) is required in order for other services
to use elastic.

View File

@ -0,0 +1,50 @@
---
elasticsearch_version: 8.15.3
elasticsearch_state: present
elasticsearch_base_path: /opt/elasticsearch
elasticsearch_data_path: "{{ elasticsearch_base_path }}/data"
elasticsearch_config_cluster_name: elastic
elasticsearch_config_discovery_type: single-node
elasticsearch_config_boostrap_memory_lock: true
elasticsearch_allocated_ram_mb: 512
elasticsearch_container_image_registry: docker.elastic.co
elasticsearch_container_image_namespace: elasticsearch
elasticsearch_container_image_name: elasticsearch-oss
elasticsearch_container_image_tag: ~
elasticsearch_container_image: >-2
{{
([
elasticsearch_container_image_registry | default([], true),
elasticsearch_container_image_namespace | default([], true),
elasticsearch_container_image_name,
] | flatten | join('/'))
+ ':' +
(elasticsearch_container_image_tag | default(elasticsearch_version, true))
}}
elasticsearch_container_image_source: pull
elasticsearch_container_image_force_source: >-2
{{ elasticsearch_container_image_tag | default(false, true) | bool }}
elasticsearch_container_name: elasticsearch
elasticsearch_container_env:
"ES_JAVA_OPTS": "-Xms{{ elasticsearch_allocated_ram_mb }}m -Xmx{{ elasticsearch_allocated_ram_mb }}m"
"cluster.name": "{{ elasticsearch_config_cluster_name }}"
"discovery.type": "{{ elasticsearch_config_discovery_type }}"
"bootstrap.memory_lock": "{{ 'true' if elasticsearch_config_boostrap_memory_lock else 'false' }}"
elasticsearch_container_user: ~
elasticsearch_container_ports: ~
elasticsearch_container_labels:
version: "{{ elasticsearch_version }}"
elasticsearch_container_ulimits:
# - "memlock:{{ (1.5 * 1024 * elasticsearch_allocated_ram_mb) | int }}:{{ (1.5 * 1024 * elasticsearch_allocated_ram_mb) | int }}"
- "memlock:-1:-1"
elasticsearch_container_volumes:
- "{{ elasticsearch_data_path }}:/usr/share/elasticsearch/data:z"
elasticsearch_container_networks: ~
elasticsearch_container_purge_networks: ~
elasticsearch_container_restart_policy: unless-stopped
elasticsearch_container_state: >-2
{{ (elasticsearch_state == 'present') | ternary('started', 'absent') }}

View File

@ -0,0 +1,10 @@
---
allow_duplicates: true
dependencies: []
galaxy_info:
role_name: elasticsearch
description: >-2
Deploy elasticsearch in a docker container
galaxy_tags:
- elasticsearch
- docker

View File

@ -0,0 +1,39 @@
---
- name: Check if state is valid
ansible.builtin.fail:
msg: >-2
Unsupported state '{{ elasticsearch_state }}'. Supported
states are {{ elasticsearch_states | join(', ') }}.
when: elasticsearch_state not in elasticsearch_states
- name: Ensure host directories are {{ elasticsearch_state }}
ansible.builtin.file:
path: "{{ item }}"
state: directory
mode: "0777"
loop:
- "{{ elasticsearch_base_path }}"
- "{{ elasticsearch_data_path }}"
- name: Ensure elasticsearch container image '{{ elasticsearch_container_image }}' is {{ elasticsearch_state }}
community.docker.docker_image:
name: "{{ elasticsearch_container_image }}"
state: "{{ elasticsearch_state }}"
source: "{{ elasticsearch_container_image_source }}"
force_source: "{{ elasticsearch_container_image_force_source }}"
force_source: "{{ elasticsearch_container_image_tag|default(false, true)|bool }}"
- name: Ensure elasticsearch container '{{ elasticsearch_container_name }}' is {{ elasticsearch_container_state }}
community.docker.docker_container:
name: "{{ elasticsearch_container_name }}"
image: "{{ elasticsearch_container_image }}"
env: "{{ elasticsearch_container_env | default(omit, True) }}"
user: "{{ elasticsearch_container_user | default(omit, True) }}"
ports: "{{ elasticsearch_container_ports | default(omit, True) }}"
labels: "{{ elasticsearch_container_labels | default(omit, True) }}"
volumes: "{{ elasticsearch_container_volumes }}"
ulimits: "{{ elasticsearch_container_ulimits }}"
networks: "{{ elasticsearch_container_networks | default(omit, True) }}"
purge_networks: "{{ elasticsearch_container_purge_networks | default(omit, True) }}"
restart_policy: "{{ elasticsearch_container_restart_policy }}"
state: "{{ elasticsearch_container_state }}"

View File

@ -0,0 +1,4 @@
---
elasticsearch_states:
- present
- absent

View File

@ -1,8 +1,9 @@
--- ---
mariadb_version: "10.11.9"
mariadb_version: "10.6.11"
mariadb_base_path: /var/lib/mariadb mariadb_base_path: /var/lib/mariadb
mariadb_data_path: "{{ mariadb_base_path }}/{{ mariadb_version }}" mariadb_data_path: >-2
{{ mariadb_base_path }}/{{ mariadb_version | split('.') | first }}
mariadb_state: present
mariadb_root_password: ~ mariadb_root_password: ~
mariadb_database: ~ mariadb_database: ~
@ -13,10 +14,24 @@ mariadb_container_base_environment:
MARIADB_ROOT_PASSWORD: "{{ mariadb_root_password }}" MARIADB_ROOT_PASSWORD: "{{ mariadb_root_password }}"
mariadb_container_extra_environment: {} mariadb_container_extra_environment: {}
mariadb_container_name: mariadb mariadb_container_image_registry: docker.io
mariadb_container_image_name: docker.io/mariadb mariadb_container_image_namespace: ~
mariadb_container_image_name: mariadb
mariadb_container_image_tag: ~ mariadb_container_image_tag: ~
mariadb_container_image: "{{ mariadb_container_image_name }}:{{ mariadb_container_image_tag | default(mariadb_version, true) }}" mariadb_container_image: >-2
{{
([
mariadb_container_image_registry | default([], true),
mariadb_container_image_namespace | default([], true),
mariadb_container_image_name,
] | flatten | join('/'))
+ ':' + mariadb_container_image_tag | default(mariadb_version, true)
}}
mariadb_container_image_source: pull
mariadb_container_image_force_source: >-2
{{ mariadb_container_image_tag | default(false, true) | bool }}
mariadb_container_name: mariadb
mariadb_container_base_volumes: mariadb_container_base_volumes:
- "{{ mariadb_data_path }}:{{ mariadb_container_data_path }}:z" - "{{ mariadb_data_path }}:{{ mariadb_container_data_path }}:z"
mariadb_container_extra_volumes: [] mariadb_container_extra_volumes: []
@ -30,3 +45,5 @@ mariadb_container_environment: >-2
if (mariadb_database and mariadb_username and mariadb_password) if (mariadb_database and mariadb_username and mariadb_password)
else {}, recursive=True) else {}, recursive=True)
| combine(mariadb_container_extra_environment) }} | combine(mariadb_container_extra_environment) }}
mariadb_container_state: >-2
{{ (mariadb_state == 'present') | ternary('started', 'absent') }}

View File

@ -0,0 +1,10 @@
---
allow_duplicates: true
dependencies: []
galaxy_info:
role_name: mariadb
description: >-2
Deploy mariadb using docker
galaxy_tags:
- mariadb
- docker

View File

@ -1,20 +1,21 @@
--- ---
- name: Ensure mariaDB container image is present on host - name: Ensure mariadb container image '{{ mariadb_container_image }}' is {{ mariadb_state }}
community.docker.docker_image: community.docker.docker_image:
name: "{{ mariadb_container_image }}" name: "{{ mariadb_container_image }}"
state: present state: "{{ mariadb_state }}"
source: pull source: "{{ mariadb_container_image_source }}"
force_source: "{{ mariadb_container_image_force_source }}"
- name: Ensure mariaDB {{ mariadb_version }} is running as '{{ mariadb_container_name }}' - name: Ensure mariadb container '{{ mariadb_container_name }}' is {{ mariadb_container_state }}
community.docker.docker_container: community.docker.docker_container:
name: "{{ mariadb_container_name }}" name: "{{ mariadb_container_name }}"
image: "{{ mariadb_container_image }}" image: "{{ mariadb_container_image }}"
env: "{{ mariadb_container_environment }}" env: "{{ mariadb_container_environment }}"
ports: "{{ mariadb_container_ports }}" ports: "{{ mariadb_container_ports | default(omit, true) }}"
labels: "{{ mariadb_container_labels }}" labels: "{{ mariadb_container_labels | default(omit, true) }}"
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) }}" purge_networks: "{{ mariadb_container_purge_networks | default(omit, true) }}"
restart_policy: "{{ mariadb_container_restart_policy }}" restart_policy: "{{ mariadb_container_restart_policy }}"
state: started state: "{{ mariadb_container_state }}"