mirror of
https://github.com/famedly/ansible-collection-services
synced 2024-11-13 23:37:09 +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"
|
snipe_it_builtin_database_version: "10.6"
|
||||||
# generate a strong password based on the app key
|
# 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_root_pass: "{{ snipe_it_config_app_key | password_hash('sha512', 'snipeit.db.root') | to_uuid }}"
|
||||||
snipe_it_builtin_database_labels: {}
|
snipe_it_builtin_database_container_image_reference: >-
|
||||||
snipe_it_builtin_database_ports: []
|
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_builtin_database_data_path: "{{ snipe_it_base_path }}/mariadb"
|
||||||
snipe_it_config: {}
|
snipe_it_config: {}
|
||||||
|
|
||||||
|
@ -22,7 +33,7 @@ snipe_it_config: {}
|
||||||
snipe_it_config_app_key: ~
|
snipe_it_config_app_key: ~
|
||||||
snipe_it_config_app_url: ~
|
snipe_it_config_app_url: ~
|
||||||
# container image creates a "docker" user by default with uid=1000
|
# 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_timezone: 'Europe/London'
|
||||||
snipe_it_config_app_locale: en
|
snipe_it_config_app_locale: en
|
||||||
snipe_it_config_app_trusted_proxies: ~
|
snipe_it_config_app_trusted_proxies: ~
|
||||||
|
@ -38,11 +49,21 @@ snipe_it_config_db_port: ~
|
||||||
|
|
||||||
# container configuration
|
# container configuration
|
||||||
snipe_it_container_name: "snipe-it"
|
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_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_env: {}
|
||||||
snipe_it_container_labels: {}
|
snipe_it_container_labels: {}
|
||||||
|
snipe_it_container_etc_hosts:
|
||||||
|
"snipe-mysql": "{{ snipe_mysql_container_info.container.NetworkSettings.Networks.bridge.IPAddress }}"
|
||||||
snipe_it_container_ports:
|
snipe_it_container_ports:
|
||||||
- 80:80
|
- 80:80
|
||||||
snipe_it_container_volumes: []
|
snipe_it_container_volumes: []
|
||||||
|
|
|
@ -1,14 +1,15 @@
|
||||||
---
|
---
|
||||||
|
|
||||||
- name: Ensure user for snipe-it is created
|
- name: Ensure user for snipe-it is created
|
||||||
user:
|
ansible.builtin.user:
|
||||||
name: "{{ snipe_it_user }}"
|
name: "{{ snipe_it_user }}"
|
||||||
state: present
|
state: present
|
||||||
system: true
|
system: true
|
||||||
|
create_home: false
|
||||||
register: snipe_it_user_res
|
register: snipe_it_user_res
|
||||||
|
|
||||||
- name: Ensure directories are created
|
- name: Ensure directories are created
|
||||||
file:
|
ansible.builtin.file:
|
||||||
path: "{{ item.path }}"
|
path: "{{ item.path }}"
|
||||||
mode: "{{ item.mode | default('0750') }}"
|
mode: "{{ item.mode | default('0750') }}"
|
||||||
state: directory
|
state: directory
|
||||||
|
@ -22,7 +23,7 @@
|
||||||
only: "{{ snipe_it_builtin_database_enable | bool }}"
|
only: "{{ snipe_it_builtin_database_enable | bool }}"
|
||||||
|
|
||||||
- name: Template laravel env
|
- name: Template laravel env
|
||||||
copy:
|
ansible.builtin.copy:
|
||||||
dest: "{{ snipe_it_config_file }}"
|
dest: "{{ snipe_it_config_file }}"
|
||||||
mode: "0664"
|
mode: "0664"
|
||||||
content: |
|
content: |
|
||||||
|
@ -30,35 +31,39 @@
|
||||||
{{ kv.key }}="{{ kv.value }}"
|
{{ kv.key }}="{{ kv.value }}"
|
||||||
{% endfor %}
|
{% 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
|
- name: Ensure built-in MariaDB for snipe-it is started
|
||||||
docker_container:
|
community.docker.docker_container:
|
||||||
name: "{{ snipe_it_config_db_host | default('snipe-mysql', True) }}"
|
name: "{{ snipe_it_builtin_database_container_name }}"
|
||||||
image: "docker.io/mariadb:{{ snipe_it_builtin_database_version }}"
|
image: "{{ snipe_it_builtin_database_container_image_reference }}"
|
||||||
volumes: ["{{ snipe_it_builtin_database_data_path }}:/var/lib/mysql:z"]
|
env: "{{ snipe_it_builtin_database_container_env }}"
|
||||||
ports: "{{ snipe_it_builtin_database_ports }}"
|
ports: "{{ snipe_it_builtin_database_container_ports }}"
|
||||||
labels: "{{ snipe_it_builtin_database_labels }}"
|
labels: "{{ snipe_it_builtin_database_container_labels | default(omit) }}"
|
||||||
env:
|
volumes: "{{ snipe_it_builtin_database_container_volumes }}"
|
||||||
MARIADB_ROOT_PASSWORD: "{{ snipe_it_builtin_database_root_pass }}"
|
networks: "{{ snipe_it_builtin_database_container_networks | default(omit, true) }}"
|
||||||
MARIADB_DATABASE: "{{ snipe_it_config_db_database }}"
|
|
||||||
MARIADB_USER: "{{ snipe_it_config_db_username }}"
|
|
||||||
MARIADB_PASSWORD: "{{ snipe_it_config_db_password }}"
|
|
||||||
MARIADB_ROOT_HOST: '%'
|
|
||||||
restart_policy: unless-stopped
|
restart_policy: unless-stopped
|
||||||
state: started
|
state: started
|
||||||
register: snipe_mysql_container
|
register: snipe_mysql_container_info
|
||||||
when: snipe_it_builtin_database_enable|bool
|
when: snipe_it_builtin_database_enable | bool
|
||||||
|
|
||||||
- name: Ensure snipe-it container is started
|
- name: Ensure snipe-it container is started
|
||||||
docker_container:
|
community.docker.docker_container:
|
||||||
image: "{{ snipe_it_container_image_ref }}"
|
image: "{{ snipe_it_container_image_ref }}"
|
||||||
name: "{{ snipe_it_container_name }}"
|
name: "{{ snipe_it_container_name }}"
|
||||||
# user: "{{ snipe_it_user_res.uid }}:{{ snipe_it_user_res.group }}"
|
# user: "{{ snipe_it_user_res.uid }}:{{ snipe_it_user_res.group }}"
|
||||||
volumes: "{{ snipe_it_container_volumes_merged }}"
|
|
||||||
ports: "{{ snipe_it_container_ports }}"
|
ports: "{{ snipe_it_container_ports }}"
|
||||||
env: "{{ snipe_it_config_merged | combine(snipe_it_container_env, recursive=True) }}"
|
env: "{{ snipe_it_config_merged | combine(snipe_it_container_env, recursive=True) }}"
|
||||||
labels: "{{ snipe_it_container_labels_merged }}"
|
labels: "{{ snipe_it_container_labels_merged }}"
|
||||||
etc_hosts:
|
volumes: "{{ snipe_it_container_volumes_merged }}"
|
||||||
snipe-mysql: "{{ snipe_mysql_container.container.NetworkSettings.Networks.bridge.IPAddress }}"
|
networks: "{{ snipe_it_container_networks | default(omit, true) }}"
|
||||||
|
etc_hosts: "{{ snipe_it_container_etc_hosts | default(omit, true) }}"
|
||||||
restart_policy: unless-stopped
|
restart_policy: unless-stopped
|
||||||
state: started
|
state: started
|
||||||
pull: true
|
|
||||||
|
|
|
@ -40,3 +40,4 @@ snipe_it_config_base:
|
||||||
DB_PASSWORD: "{{ snipe_it_config_db_password }}"
|
DB_PASSWORD: "{{ snipe_it_config_db_password }}"
|
||||||
DB_DUMP_PATH: "{{ snipe_it_config_db_dump_path }}"
|
DB_DUMP_PATH: "{{ snipe_it_config_db_dump_path }}"
|
||||||
IMAGE_LIB: gd
|
IMAGE_LIB: gd
|
||||||
|
PHP_UPLOAD_LIMIT: "32"
|
||||||
|
|
Loading…
Reference in a new issue