Compare commits

...

4 Commits

@ -12,19 +12,16 @@ kimai:
service_name: "kimai"
trusted_hosts: ",0.0.0.0"
admin:
mail: "admin@kimai.local"
password: "changemeplease"
users:
# default super admin - name not changeable!
superadmin:
roles:
ROLE_SUPER_ADMIN: true
mail: "admin@kimai.local"
password: "changemeplease"
role: ROLE_SUPER_ADMIN
dark:
mail: "dark@kimai.local"
password: "changemeplease"
roles:
ROLE_SUPER_ADMIN:
role: ROLE_SUPER_ADMIN
services:

@ -9,3 +9,58 @@
- 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

@ -1,7 +1,7 @@
galaxy_info:
author: your name
description: your role description
company: your company (optional)
author: dark
description: A role for managing a Kimai docker-compose installation which is solely interacting with the given docker-compose
company:
# If the issue tracker for your role is not on github, uncomment the
# next line and provide a value
@ -14,9 +14,9 @@ galaxy_info:
# - GPL-3.0-only
# - Apache-2.0
# - CC-BY-4.0
license: license (GPL-2.0-or-later, MIT, etc)
license: MTI
min_ansible_version: 2.1
min_ansible_version: 2.9
# If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version:
@ -39,7 +39,10 @@ galaxy_info:
# - 7
# - 99.99
galaxy_tags: []
galaxy_tags:
- kimai
- timetracking
- docker-compose
# List tags for your role here, one per line. A tag is a keyword that describes
# and categorizes the role. Users find roles by searching for tags. Be sure to
# remove the '[]' above, if you add tags to this list.

@ -11,73 +11,44 @@
template:
src: "docker-compose.yml.j2"
dest: "{{ kimai.general.base_path }}/docker-compose.yml"
notify: kimai_services_restart
# notify:
# - restart kimai
# - fixup var
# - fixup kimai install
- name: restart kimais mysql
docker_compose:
project_src: "{{ kimai.general.base_path }}"
restarted: true
services:
- "{{ kimai.services.mysql.service_name }}"
timeout: 30
- 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
- name: Wait for kimai db become ready
ansible.builtin.wait_for:
host: "{{ kimai_db.stdout }}"
port: 3306
delay: 10
- 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
- name: Flush handlers
meta: flush_handlers
- name: fixup var
shell: 'cd {{ kimai.general.base_path }}; docker-compose exec -u root {{ kimai.main.service_name }} bash -c "chmod 777 -R /opt/kimai/var";'
- name: Create admins
block:
- name: Register existing users as facts
- name: Gather existing users
shell: >
docker-compose exec {{ kimai.services.mysql.service_name }} mysql -u{{ kimai.services.mysql.user }} -p{{ kimai.services.mysql.password}} --execute "SELECT username,roles FROM {{ kimai.services.mysql.db }}.kimai2_users;" -sN 2>/dev/null | awk '{ gsub(/^[ \t]+|[ \t]+$/, ""); gsub(/[ ]+/," "); print $1,"|",$2}' > /kimai_users.txt
docker-compose exec {{ kimai.services.mysql.service_name }} mysql -u{{ kimai.services.mysql.user }} -p{{ kimai.services.mysql.password}} --execute "SELECT username,roles FROM {{ kimai.services.mysql.db }}.kimai2_users;" -sN 2>/dev/null | awk '{ gsub(/^[ \t]+|[ \t]+$/, ""); gsub(/[ ]+/," "); print $1,"|",$2}' > ./kimai_users.txt
args:
chdir: "{{ kimai.general.base_path }}"
- name: Check existing kimai_users
command: grep -Fqe "{{ item.key }}" /kimai_users.txt
command: grep -Fqe "{{ item.key }}" ./kimai_users.txt
args:
chdir: "{{ kimai.general.base_path }}"
check_mode: 'no'
ignore_errors: 'yes'
ignore_errors: 'no'
register: admin_lines
loop: "{{ kimai.main.users | dict2items | selectattr('value.roles', 'search', 'ROLE_SUPER_ADMIN')}}"
loop: "{{ kimai.main.users | dict2items | selectattr('value.role', 'search', 'ROLE_SUPER_ADMIN')}}"
changed_when: admin_lines.rc != 0
failed_when: admin_lines is not defined or admin_lines.rc > 1
- name: Debug admin_lines
debug:
msg: "Creating user: {{ result.item.key }}"
loop: "{{ admin_lines.results | selectattr('changed', 'equalto', True) | rejectattr('failed', 'equalto', True) }}"
loop_control:
loop_var: result
- name: Init fact
set_fact:
kimai_users:
# TODO: NOT WORKING YET! Missing parts for mail, password and such. But it's triggered just with absent users already!
- name: Create non-existent admins
shell: >
docker-compose exec {{ kimai.main.service_name }} bash -c '/opt/kimai/bin/console kimai:user:create {{ result.item.key }}'
loop: "{{ admin_lines.results | selectattr('changed', 'equalto', True) | rejectattr('failed', 'equalto', True) }}"
- name: Make existing admins a fact and model that fact as it is expected
set_fact:
kimai_users: "{{ kimai_users | combine({ result.item.key: {'mail': result.item.value.mail, 'password': result.item.value.password, 'role': result.item.value.role, '_changed': result.changed} }) }}"
loop: "{{ admin_lines.results | rejectattr('failed', 'equalto', True) }}"
loop_control:
loop_var: result
changed_when: result.changed
notify:
- create_non_existing_users

@ -65,8 +65,8 @@ services:
{{ kimai.main.service_name }}: # This is the latest FPM image of kimai
image: kimai/kimai2:fpm
environment:
- ADMINMAIL=admin@kimai.local
- ADMINPASS=changemeplease
- ADMINMAIL={{ kimai.main.users.superadmin.mail }}
- ADMINPASS={{ kimai.main.users.superadmin.password }}
- DATABASE_URL=mysql://{{ kimai.services.mysql.user }}:{{ kimai.services.mysql.password }}@{{ kimai.services.mysql.service_name }}/{{ kimai.services.mysql.db }}
- TRUSTED_HOSTS={{ kimai.services.nginx.service_name }},localhost,127.0.0.1,{{ kimai.main.trusted_hosts}}
volumes:

Loading…
Cancel
Save