Files
k8scd/ansible/mailserver/roles/stalwart/tasks/prepare.yml
T
2026-03-14 22:24:53 +01:00

68 lines
2.2 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: 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