mirror of
https://github.com/rubenhensen/k8scd.git
synced 2026-09-17 02:12:55 +02:00
99 lines
3.0 KiB
YAML
99 lines
3.0 KiB
YAML
---
|
|
- name: Create Stalwart group
|
|
ansible.builtin.group:
|
|
name: "{{ stalwart_system_group }}"
|
|
system: true
|
|
|
|
- name: Create Stalwart user
|
|
ansible.builtin.user:
|
|
name: "{{ stalwart_system_user }}"
|
|
group: "{{ stalwart_system_group }}"
|
|
create_home: false
|
|
home: "{{ stalwart_install_path }}"
|
|
shell: "/usr/sbin/nologin"
|
|
system: true
|
|
|
|
- name: Create Ansible remote_tmp for stalwart user
|
|
ansible.builtin.file:
|
|
path: "{{ stalwart_install_path }}/.ansible/tmp"
|
|
state: directory
|
|
owner: "{{ stalwart_system_user }}"
|
|
group: "{{ stalwart_system_group }}"
|
|
mode: "0755"
|
|
|
|
- name: Create Stalwart database user
|
|
become: true
|
|
become_user: postgres
|
|
community.postgresql.postgresql_user:
|
|
name: "{{ stalwart_db_user }}"
|
|
password: "{{ stalwart_db_password }}"
|
|
when: stalwart_directory_type == "sql"
|
|
|
|
- name: Create Stalwart database
|
|
become: true
|
|
become_user: postgres
|
|
community.postgresql.postgresql_db:
|
|
name: "{{ stalwart_db_name }}"
|
|
owner: "{{ stalwart_db_user }}"
|
|
when: stalwart_directory_type == "sql"
|
|
|
|
- name: Deploy database schema
|
|
ansible.builtin.copy:
|
|
src: schema.sql
|
|
dest: /tmp/stalwart-schema.sql
|
|
mode: "0644"
|
|
when: stalwart_directory_type == "sql"
|
|
|
|
- name: Apply database schema
|
|
become: true
|
|
become_user: postgres
|
|
ansible.builtin.command:
|
|
cmd: psql -d {{ stalwart_db_name }} -f /tmp/stalwart-schema.sql
|
|
changed_when: false
|
|
when: stalwart_directory_type == "sql"
|
|
|
|
- name: Check if already installed
|
|
ansible.builtin.stat:
|
|
path: "{{ stalwart_executable_path }}"
|
|
register: stalwart_exec
|
|
|
|
- name: Get version if stalwart is installed
|
|
when: stalwart_exec.stat.exists
|
|
block:
|
|
- name: Get version
|
|
ansible.builtin.command: "{{ stalwart_executable_path }} -V"
|
|
failed_when: false
|
|
changed_when: false
|
|
check_mode: false
|
|
register: stalwart_output
|
|
|
|
- name: Set current installed version
|
|
ansible.builtin.set_fact:
|
|
stalwart_current_version: "{{ stalwart_output.stdout_lines[0] }}"
|
|
|
|
- name: Check if config exists
|
|
ansible.builtin.stat:
|
|
path: "{{ stalwart_config_file_path }}"
|
|
register: stalwart_config_file_st
|
|
|
|
- name: Preserve admin password salt from existing config
|
|
when: stalwart_config_file_st.stat.exists
|
|
block:
|
|
- name: Get config file content
|
|
ansible.builtin.slurp:
|
|
src: "{{ stalwart_config_file_path }}"
|
|
register: config_file_content
|
|
|
|
- name: Get existing password hash
|
|
ansible.builtin.set_fact:
|
|
hash_stored: "{{ config_file_content['content'] | b64decode | regex_search('(\\n|^)(secret|authentication\\.fallback-admin\\.secret) = \"(.*)\"\\n', '\\3') }}"
|
|
|
|
- name: Get existing salt
|
|
ansible.builtin.set_fact:
|
|
stalwart_fallback_admin_password_salt: "{{ (hash_stored[0] | split('$'))[2] }}"
|
|
|
|
- name: Create salt if it does not exist
|
|
ansible.builtin.set_fact:
|
|
stalwart_fallback_admin_password_salt: "{{ lookup('password', '/dev/null length=16 chars=ascii_letters,digits') }}"
|
|
when: stalwart_fallback_admin_password_salt is undefined
|