You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
2.2 KiB
YAML

---
# handlers file for compose-kimai
- name: install required packages
ansible.builtin.package:
name:
- docker
- docker-compose
- mysql-default-client
- name: Create users
meta: "noop"
- name: Restarting services
block:
- name: restart kimais mysql
docker_compose:
project_src: "{{ kimai.general.base_path }}"
restarted: true
services:
- "{{ kimai.services.mysql.service_name }}"
timeout: 30
listen: kimai_services_restart
- name: gather mysql ip
shell: docker inspect -f {% raw %}'{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}'{% endraw %} $(docker-compose ps -q {{ kimai.services.mysql.service_name }} )
args:
chdir: "{{ kimai.general.base_path }}"
register: kimai_db
listen: kimai_services_restart
- name: Wait for kimai db become ready
ansible.builtin.wait_for:
host: "{{ kimai_db.stdout }}"
port: 3306
delay: 10
listen: kimai_services_restart
- name: restart kimais normal services
docker_compose:
project_src: "{{ kimai.general.base_path }}"
restarted: true
services:
- "{{ kimai.services.nginx.service_name }}"
- "{{ kimai.services.postfix.service_name }}"
- "{{ kimai.main.service_name }}"
timeout: 10
listen: kimai_services_restart
- name: User-Setup
block:
- name: Create non-existent users
shell: >
docker-compose exec {{ kimai.main.service_name }} bash -c '/opt/kimai/bin/console kimai:user:create {{ item.key }} {{ item.value.mail }} {{ item.value.role }} {{ item.value.password }}'
args:
chdir: "{{ kimai.general.base_path }}"
loop: "{{ kimai_users | dict2items | selectattr('value._changed', 'equalto', True) }}"
changed_when: item.value._changed
listen: create_non_existing_users
notify: post_create_non_existing_users
- name: Set changed-Flag on admin users to False
set_fact:
kimai_users: "{{ kimai_users | combine({ item.key: {'mail': item.value.mail, 'password': item.value.password, 'role': item.value.role, '_changed': False} }) }}"
loop: "{{ kimai_users | dict2items | selectattr('value._changed', 'equalto', True) }}"
listen: post_create_non_existing_users