General Optimations

This commit is contained in:
2025-05-28 02:42:39 +02:00
parent 70bf9ad3fb
commit aacc6877cb
12 changed files with 106 additions and 66 deletions

View File

@@ -19,4 +19,5 @@ galaxy_info:
documentation: "https://s.veen.world/cymais"
logo:
class: "fa-solid fa-envelope"
dependencies: []
run_after:
- docker-keycloak

View File

@@ -1,7 +1,7 @@
- name: "Ensure Mailu user {{ mailu_user }}@{{ mailu_domain }} exists"
- name: "Ensure Mailu user '{{ mailu_user_key }};{{ mailu_user_name }}@{{ mailu_domain }}'' exists"
command: >
docker compose exec admin flask mailu {{ mailu_action }}
{{ mailu_user }} {{ mailu_domain }} '{{ mailu_password }}'
{{ mailu_user_name }} {{ mailu_domain }} '{{ mailu_password }}'
args:
chdir: "{{ mailu_compose_dir }}"
register: mailu_user_result
@@ -13,10 +13,10 @@
)
changed_when: mailu_user_result.rc == 0
- name: "Change password for user {{ mailu_user }}@{{ mailu_domain }}"
- name: "Change password for user '{{ mailu_user_key }};{{ mailu_user_name }}@{{ mailu_domain }}'"
command: >
docker compose exec admin flask mailu password
{{ mailu_user }} {{ mailu_domain }} '{{ mailu_password }}'
{{ mailu_user_name }} {{ mailu_domain }} '{{ mailu_password }}'
args:
chdir: "{{ mailu_compose_dir }}"
@@ -30,18 +30,18 @@
register: mailu_tokens_cli
changed_when: false
- name: "Extract existing token info for {{ mailu_user }}"
- name: "Extract existing token info for '{{ mailu_user_key }};{{ mailu_user_name }}'"
set_fact:
mailu_user_existing_token: >-
{{ (
mailu_tokens_cli.stdout
| default('[]')
| from_json
| selectattr('comment','equalto', mailu_user ~ " - ansible.cymais")
| selectattr('comment','equalto', mailu_user_key ~ " - ansible.cymais")
| list
).0 | default(None) }}
- name: "Delete existing API token for {{ mailu_user }} if local token missing but remote exists"
- name: "Delete existing API token for '{{ mailu_user_key }};{{ mailu_user_name }}' if local token missing but remote exists"
command: >-
docker compose exec -T admin \
curl -s -X DELETE {{ mailu_api_base_url }}/token/{{ mailu_user_existing_token.id }} \
@@ -49,40 +49,40 @@
args:
chdir: "{{ mailu_compose_dir }}"
when:
- users[mailu_user].mailu_token is not defined
- users[mailu_user_key].mailu_token is not defined
- mailu_user_existing_token is not none
- mailu_user_existing_token.id is defined
register: mailu_token_delete
changed_when: mailu_token_delete.rc == 0
- name: "Create API token for {{ mailu_user }} if no local token defined"
- name: "Create API token for '{{ mailu_user_key }};{{ mailu_user_name }}' if no local token defined"
command: >-
docker compose exec -T admin \
curl -s -X POST {{ mailu_api_base_url }}/token \
-H "Authorization: Bearer {{ mailu_global_api_token }}" \
-H "Content-Type: application/json" \
-d '{{ {
"comment": mailu_user ~ " - ansible.cymais",
"email": users[mailu_user].email,
"comment": mailu_user_key ~ " - ansible.cymais",
"email": users[mailu_user_key].email,
"ip": mailu_token_ip
} | to_json }}'
args:
chdir: "{{ mailu_compose_dir }}"
when: users[mailu_user].mailu_token is not defined
when: users[mailu_user_key].mailu_token is not defined
register: mailu_token_creation
changed_when: mailu_token_creation.rc == 0
- name: "Set mailu_token for {{ mailu_user }} in users dict if newly created"
- name: "Set mailu_token for '{{ mailu_user_key }};{{ mailu_user_name }}' in users dict if newly created"
set_fact:
users: >-
{{ users
| combine({
mailu_user: (
users[mailu_user]
mailu_user_key: (
users[mailu_user_key]
| combine({
'mailu_token': (mailu_token_creation.stdout | from_json).token
})
)
}, recursive=True)
}}
when: users[mailu_user].mailu_token is not defined
when: users[mailu_user_key].mailu_token is not defined

View File

@@ -33,7 +33,8 @@
mailu_api_base_url: "http://127.0.0.1:8080/api/v1"
mailu_global_api_token: "{{ applications.mailu.credentials.api_token }}"
mailu_action: "{{ item.value.is_admin | default(false) | ternary('admin','user') }}"
mailu_user: "{{ item.key }}"
mailu_user_key: "{{ item.key }}"
mailu_user_name: "{{ item.value.username }}"
mailu_password: "{{ item.value.password }}"
mailu_token_ip: "{{ item.value.ip | default('') }}"
loop: "{{ users | dict2items }}"

View File

@@ -15,4 +15,9 @@ features:
central_database: false # Deactivate central database for mailu, I don't know why the database deactivation is necessary
domains:
canonical:
- "mail.{{ primary_domain }}"
- "mail.{{ primary_domain }}"
flags:
style-src:
unsafe-inline: true
script-src:
unsafe-inline: true