mirror of
https://github.com/famedly/ansible-collection-services
synced 2024-11-12 23:07:07 +00:00
chore(snipe-it): refactor role to allow more fine-granular control of built-in database
This commit is contained in:
parent
f832c40607
commit
30c82a7ff6
3 changed files with 54 additions and 27 deletions
|
@ -13,8 +13,19 @@ snipe_it_builtin_database_enable: true
|
|||
snipe_it_builtin_database_version: "10.6"
|
||||
# generate a strong password based on the app key
|
||||
snipe_it_builtin_database_root_pass: "{{ snipe_it_config_app_key | password_hash('sha512', 'snipeit.db.root') | to_uuid }}"
|
||||
snipe_it_builtin_database_labels: {}
|
||||
snipe_it_builtin_database_ports: []
|
||||
snipe_it_builtin_database_container_image_reference: >-
|
||||
docker.io/mariadb:{{ snipe_it_builtin_database_version }}
|
||||
snipe_it_builtin_database_container_name: "{{ snipe_it_config_db_host | default('snipe-mysql', true) }}"
|
||||
snipe_it_builtin_database_container_volumes:
|
||||
- "{{ snipe_it_builtin_database_data_path }}:/var/lib/mysql:z"
|
||||
snipe_it_builtin_database_container_env:
|
||||
MARIADB_ROOT_PASSWORD: "{{ snipe_it_builtin_database_root_pass }}"
|
||||
MARIADB_DATABASE: "{{ snipe_it_config_db_database }}"
|
||||
MARIADB_USER: "{{ snipe_it_config_db_username }}"
|
||||
MARIADB_PASSWORD: "{{ snipe_it_config_db_password }}"
|
||||
MARIADB_ROOT_HOST: "%"
|
||||
snipe_it_builtin_database_container_labels: {}
|
||||
snipe_it_builtin_database_container_ports: []
|
||||
snipe_it_builtin_database_data_path: "{{ snipe_it_base_path }}/mariadb"
|
||||
snipe_it_config: {}
|
||||
|
||||
|
@ -22,7 +33,7 @@ snipe_it_config: {}
|
|||
snipe_it_config_app_key: ~
|
||||
snipe_it_config_app_url: ~
|
||||
# container image creates a "docker" user by default with uid=1000
|
||||
snipe_it_config_app_user: "docker"
|
||||
snipe_it_config_app_user: "snipe-it"
|
||||
snipe_it_config_app_timezone: 'Europe/London'
|
||||
snipe_it_config_app_locale: en
|
||||
snipe_it_config_app_trusted_proxies: ~
|
||||
|
@ -38,11 +49,21 @@ snipe_it_config_db_port: ~
|
|||
|
||||
# container configuration
|
||||
snipe_it_container_name: "snipe-it"
|
||||
snipe_it_container_image: "docker.io/snipe/snipe-it"
|
||||
snipe_it_container_image_registry: "docker.io"
|
||||
snipe_it_container_image_namespace: "snipe"
|
||||
snipe_it_container_image_name: "snipe-it"
|
||||
snipe_it_container_image: >-
|
||||
{{ snipe_it_container_image_registry ~ "/" ~
|
||||
((snipe_it_container_image_namespace is string and snipe_it_container_image_namespace | length > 0)
|
||||
| ternary(snipe_it_container_image_namespace ~ "/", ""))
|
||||
~ snipe_it_container_image_name }}
|
||||
snipe_it_container_image_tag: ~
|
||||
snipe_it_container_image_ref: "{{ snipe_it_container_image }}:{{ snipe_it_container_image_tag | default('v' + snipe_it_version, True) }}"
|
||||
snipe_it_container_image_ref: >-
|
||||
{{ snipe_it_container_image }}:{{ snipe_it_container_image_tag | default('v' + snipe_it_version, true) }}
|
||||
snipe_it_container_env: {}
|
||||
snipe_it_container_labels: {}
|
||||
snipe_it_container_etc_hosts:
|
||||
"snipe-mysql": "{{ snipe_mysql_container_info.container.NetworkSettings.Networks.bridge.IPAddress }}"
|
||||
snipe_it_container_ports:
|
||||
- 80:80
|
||||
snipe_it_container_volumes: []
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
---
|
||||
|
||||
- name: Ensure user for snipe-it is created
|
||||
user:
|
||||
ansible.builtin.user:
|
||||
name: "{{ snipe_it_user }}"
|
||||
state: present
|
||||
system: true
|
||||
create_home: false
|
||||
register: snipe_it_user_res
|
||||
|
||||
- name: Ensure directories are created
|
||||
file:
|
||||
ansible.builtin.file:
|
||||
path: "{{ item.path }}"
|
||||
mode: "{{ item.mode | default('0750') }}"
|
||||
state: directory
|
||||
|
@ -22,7 +23,7 @@
|
|||
only: "{{ snipe_it_builtin_database_enable | bool }}"
|
||||
|
||||
- name: Template laravel env
|
||||
copy:
|
||||
ansible.builtin.copy:
|
||||
dest: "{{ snipe_it_config_file }}"
|
||||
mode: "0664"
|
||||
content: |
|
||||
|
@ -30,35 +31,39 @@
|
|||
{{ kv.key }}="{{ kv.value }}"
|
||||
{% endfor %}
|
||||
|
||||
- name: Ensure container images are present on host
|
||||
community.docker.docker_image:
|
||||
name: "{{ item }}"
|
||||
state: present
|
||||
source: pull
|
||||
loop:
|
||||
- "{{ snipe_it_builtin_database_container_image_reference }}"
|
||||
- "{{ snipe_it_container_image_ref }}"
|
||||
|
||||
- name: Ensure built-in MariaDB for snipe-it is started
|
||||
docker_container:
|
||||
name: "{{ snipe_it_config_db_host | default('snipe-mysql', True) }}"
|
||||
image: "docker.io/mariadb:{{ snipe_it_builtin_database_version }}"
|
||||
volumes: ["{{ snipe_it_builtin_database_data_path }}:/var/lib/mysql:z"]
|
||||
ports: "{{ snipe_it_builtin_database_ports }}"
|
||||
labels: "{{ snipe_it_builtin_database_labels }}"
|
||||
env:
|
||||
MARIADB_ROOT_PASSWORD: "{{ snipe_it_builtin_database_root_pass }}"
|
||||
MARIADB_DATABASE: "{{ snipe_it_config_db_database }}"
|
||||
MARIADB_USER: "{{ snipe_it_config_db_username }}"
|
||||
MARIADB_PASSWORD: "{{ snipe_it_config_db_password }}"
|
||||
MARIADB_ROOT_HOST: '%'
|
||||
community.docker.docker_container:
|
||||
name: "{{ snipe_it_builtin_database_container_name }}"
|
||||
image: "{{ snipe_it_builtin_database_container_image_reference }}"
|
||||
env: "{{ snipe_it_builtin_database_container_env }}"
|
||||
ports: "{{ snipe_it_builtin_database_container_ports }}"
|
||||
labels: "{{ snipe_it_builtin_database_container_labels | default(omit) }}"
|
||||
volumes: "{{ snipe_it_builtin_database_container_volumes }}"
|
||||
networks: "{{ snipe_it_builtin_database_container_networks | default(omit, true) }}"
|
||||
restart_policy: unless-stopped
|
||||
state: started
|
||||
register: snipe_mysql_container
|
||||
when: snipe_it_builtin_database_enable|bool
|
||||
register: snipe_mysql_container_info
|
||||
when: snipe_it_builtin_database_enable | bool
|
||||
|
||||
- name: Ensure snipe-it container is started
|
||||
docker_container:
|
||||
community.docker.docker_container:
|
||||
image: "{{ snipe_it_container_image_ref }}"
|
||||
name: "{{ snipe_it_container_name }}"
|
||||
# user: "{{ snipe_it_user_res.uid }}:{{ snipe_it_user_res.group }}"
|
||||
volumes: "{{ snipe_it_container_volumes_merged }}"
|
||||
ports: "{{ snipe_it_container_ports }}"
|
||||
env: "{{ snipe_it_config_merged | combine(snipe_it_container_env, recursive=True) }}"
|
||||
labels: "{{ snipe_it_container_labels_merged }}"
|
||||
etc_hosts:
|
||||
snipe-mysql: "{{ snipe_mysql_container.container.NetworkSettings.Networks.bridge.IPAddress }}"
|
||||
volumes: "{{ snipe_it_container_volumes_merged }}"
|
||||
networks: "{{ snipe_it_container_networks | default(omit, true) }}"
|
||||
etc_hosts: "{{ snipe_it_container_etc_hosts | default(omit, true) }}"
|
||||
restart_policy: unless-stopped
|
||||
state: started
|
||||
pull: true
|
||||
|
|
|
@ -40,3 +40,4 @@ snipe_it_config_base:
|
|||
DB_PASSWORD: "{{ snipe_it_config_db_password }}"
|
||||
DB_DUMP_PATH: "{{ snipe_it_config_db_dump_path }}"
|
||||
IMAGE_LIB: gd
|
||||
PHP_UPLOAD_LIMIT: "32"
|
||||
|
|
Loading…
Reference in a new issue