feat(sharkey): add ansible role for deployment
This commit is contained in:
14
roles/sharkey/tasks/check.yml
Normal file
14
roles/sharkey/tasks/check.yml
Normal file
@ -0,0 +1,14 @@
|
||||
---
|
||||
- name: Ensure 'sharkey_state' is valid
|
||||
ansible.builtin.fail:
|
||||
msg: >-2
|
||||
Unsupported sharkey_state '{{ sharkey_state }}'.
|
||||
Supported values are {{ sharkey_states | join(', ') }}
|
||||
when: sharkey_state not in sharkey_states
|
||||
|
||||
- name: Ensure 'sharkey_deployment_method' is valid
|
||||
ansible.builtin.fail:
|
||||
msg: >-2
|
||||
Unsupported sharkey_deployment_method '{{ sharkey_deployment_method }}.
|
||||
Supported values are {{ sharkey_deployment_methods | join(', ') }}
|
||||
when: sharkey_deployment_method not in sharkey_deployment_methods
|
35
roles/sharkey/tasks/configure-docker-compose.yml
Normal file
35
roles/sharkey/tasks/configure-docker-compose.yml
Normal file
@ -0,0 +1,35 @@
|
||||
---
|
||||
- name: Ensure directories for compose services are {{ sharkey_state }}
|
||||
ansible.builtin.file:
|
||||
name: "{{ file.path }}"
|
||||
state: "{{ (sharkey_state == 'present') | ternary('directory', 'absent') }}"
|
||||
owner: "{{ sharkey_user_uid }}"
|
||||
group: "{{ sharkey_user_gid }}"
|
||||
mode: "0750"
|
||||
loop:
|
||||
- path: "{{ sharkey_compose_redis_dir }}"
|
||||
- path: "{{ sharkey_compose_database_dir }}"
|
||||
loop_control:
|
||||
loop_var: file
|
||||
label: "{{ file.path }}"
|
||||
|
||||
- name: Ensure compose files are downloaded
|
||||
ansible.builtin.get_url:
|
||||
url: "{{ sharkey_compose_file_url }}"
|
||||
dest: "{{ sharkey_compose_upstream_file }}"
|
||||
owner: "{{ sharkey_user_uid }}"
|
||||
group: "{{ sharkey_user_gid }}"
|
||||
mode: "0444"
|
||||
|
||||
- name: Read compose file contents
|
||||
ansible.builtin.slurp:
|
||||
src: "{{ sharkey_compose_upstream_file }}"
|
||||
register: sharkey_compose_upstream_file_contents
|
||||
|
||||
- name: Ensure modified compose file is written
|
||||
ansible.builtin.copy:
|
||||
content: "{{ sharkey_compose_file_contents }}"
|
||||
dest: "{{ sharkey_compose_file }}"
|
||||
owner: "{{ sharkey_user_uid }}"
|
||||
group: "{{ sharkey_user_gid }}"
|
||||
mode: "0644"
|
8
roles/sharkey/tasks/configure-docker.yml
Normal file
8
roles/sharkey/tasks/configure-docker.yml
Normal file
@ -0,0 +1,8 @@
|
||||
---
|
||||
- name: Ensure sharkey docker environment is templated
|
||||
ansible.builtin.copy:
|
||||
content: "{{ sharkey_container_env_file_contents }}"
|
||||
dest: "{{ sharkey_container_env_file }}"
|
||||
owner: "{{ sharkey_user_uid }}"
|
||||
group: "{{ sharkey_user_gid }}"
|
||||
mode: "0640"
|
64
roles/sharkey/tasks/configure.yml
Normal file
64
roles/sharkey/tasks/configure.yml
Normal file
@ -0,0 +1,64 @@
|
||||
---
|
||||
- name: Ensure sharkey user '{{ sharkey_user }}' is {{ sharkey_state }}
|
||||
ansible.builtin.user:
|
||||
name: "{{ sharkey_user }}"
|
||||
state: "{{ sharkey_state }}"
|
||||
system: "{{ sharkey_user_system }}"
|
||||
create_home: "{{ sharkey_user_create_home }}"
|
||||
groups: "{{ sharkey_user_groups }}"
|
||||
append: "{{ sharkey_user_append_groups }}"
|
||||
register: sharkey_user_info
|
||||
|
||||
- name: Ensure sharkey config directory '{{ sharkey_config_dir }}' is {{ sharkey_state }}
|
||||
ansible.builtin.file:
|
||||
path: "{{ sharkey_config_dir }}"
|
||||
state: "{{ (sharkey_state == 'present') | ternary('directory', 'absent') }}"
|
||||
owner: "{{ sharkey_user_uid }}"
|
||||
group: "{{ sharkey_user_gid }}"
|
||||
mode: "0750"
|
||||
|
||||
- name: Ensure sharkey data directory '{{ sharkey_data_dir }}' is {{ sharkey_state }}
|
||||
ansible.builtin.file:
|
||||
path: "{{ sharkey_data_dir }}"
|
||||
state: "{{ (sharkey_state == 'present') | ternary('directory', 'absent') }}"
|
||||
owner: "{{ sharkey_user_uid }}"
|
||||
group: "{{ sharkey_user_gid }}"
|
||||
mode: "0750"
|
||||
|
||||
- name: Ensure sharkey file directory '{{ sharkey_file_dir }}' is {{ sharkey_state }}
|
||||
ansible.builtin.file:
|
||||
path: "{{ sharkey_file_dir }}"
|
||||
state: "{{ (sharkey_state == 'present') | ternary('directory', 'absent') }}"
|
||||
owner: "{{ sharkey_user_uid }}"
|
||||
group: "{{ sharkey_user_gid }}"
|
||||
mode: "0750"
|
||||
|
||||
- name: Ensure sharkey upstream config file is present
|
||||
ansible.builtin.get_url:
|
||||
url: "{{ sharkey_config_upstream_file_url }}"
|
||||
dest: "{{ sharkey_config_upstream_file }}"
|
||||
owner: "{{ sharkey_user_uid }}"
|
||||
group: "{{ sharkey_user_gid }}"
|
||||
mode: "0440"
|
||||
|
||||
- name: Read upstream sharkey config file
|
||||
ansible.builtin.slurp:
|
||||
src: "{{ sharkey_config_upstream_file }}"
|
||||
register: sharkey_config_upstream_file_contents
|
||||
|
||||
- name: Ensure sharkey configuration file is {{ sharkey_state }}
|
||||
ansible.builtin.copy:
|
||||
content: "{{ sharkey_config_file_contents }}"
|
||||
dest: "{{ sharkey_config_file }}"
|
||||
owner: "{{ sharkey_user_uid }}"
|
||||
group: "{{ sharkey_user_gid }}"
|
||||
mode: "0640"
|
||||
|
||||
- name: Run configure steps for deployment using containers
|
||||
ansible.builtin.include_tasks:
|
||||
file: "configure-docker.yml"
|
||||
when: sharkey_deployment_method in ['docker-compose']
|
||||
|
||||
- name: Configure for {{ sharkey_deployment_method }}
|
||||
ansible.builtin.include_tasks:
|
||||
file: "configure-{{ sharkey_deployment_method }}.yml"
|
14
roles/sharkey/tasks/deploy-docker-compose.yml
Normal file
14
roles/sharkey/tasks/deploy-docker-compose.yml
Normal file
@ -0,0 +1,14 @@
|
||||
---
|
||||
- name: Ensure sharkey container image '{{ sharkey_container_image }}' is {{ sharkey_state }}
|
||||
community.docker.docker_image:
|
||||
name: "{{ sharkey_container_image }}"
|
||||
state: "{{ sharkey_state }}"
|
||||
source: "{{ sharkey_container_image_source }}"
|
||||
force_source: "{{ sharkey_container_image_force_source }}"
|
||||
|
||||
- name: Ensure docker compose project is {{ sharkey_compose_state }}
|
||||
community.docker.docker_compose_v2:
|
||||
project_name: "{{ sharkey_compose_project_name }}"
|
||||
project_src: "{{ sharkey_compose_project_src }}"
|
||||
state: "{{ sharkey_compose_state }}"
|
||||
build: "{{ sharkey_compose_build }}"
|
12
roles/sharkey/tasks/main.yml
Normal file
12
roles/sharkey/tasks/main.yml
Normal file
@ -0,0 +1,12 @@
|
||||
---
|
||||
- name: Check role prerequisites
|
||||
ansible.builtin.include_tasks:
|
||||
file: check.yml
|
||||
|
||||
- name: Run common configuration tasks
|
||||
ansible.builtin.include_tasks:
|
||||
file: configure.yml
|
||||
|
||||
- name: Deploy using {{ sharkey_deployment_method }}
|
||||
ansible.builtin.include_tasks:
|
||||
file: "deploy-{{ sharkey_deployment_method }}.yml"
|
Reference in New Issue
Block a user