Skip to content

Commit

Permalink
Extend docker compose service role to handle extra files/templates
Browse files Browse the repository at this point in the history
  • Loading branch information
claha committed Oct 26, 2023
1 parent 36f5d2a commit d8e70c7
Show file tree
Hide file tree
Showing 17 changed files with 82 additions and 189 deletions.
2 changes: 2 additions & 0 deletions roles/docker_compose_service/defaults/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
docker_compose_service_file: false
docker_compose_service_template: false
docker_compose_service_sub_directories: []
docker_compose_service_extra_files: []
docker_compose_service_extra_templates: []
18 changes: 18 additions & 0 deletions roles/docker_compose_service/tasks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,23 @@
notify: "Recreate {{ docker_compose_service_name }}"
when: docker_compose_service_file

- name: "Copy extra files for {{ docker_compose_service_name }}"
ansible.builtin.copy:
src: "files/{{ item | ansible.builtin.basename }}"
dest: "{{ services_path }}/{{ docker_compose_service_name }}/{{ item }}"
mode: "0644"
loop: "{{ docker_compose_service_extra_files }}"
notify: "Recreate {{ docker_compose_service_name }}"
when: docker_compose_service_extra_files | length > 0

- name: "Template extra files for {{ docker_compose_service_name }}"
ansible.builtin.template:
src: "templates/{{ item | ansible.builtin.basename }}.j2"
dest: "{{ services_path }}/{{ docker_compose_service_name }}/{{ item }}"
mode: "0644"
loop: "{{ docker_compose_service_extra_templates }}"
notify: "Recreate {{ docker_compose_service_name }}"
when: docker_compose_service_extra_templates | length > 0

- name: "Flush handlers"
ansible.builtin.meta: flush_handlers
2 changes: 0 additions & 2 deletions roles/gatus/defaults/main.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
---
service_name: "{{ ansible_role_name }}"
service_path: "{{ services_path }}/{{ service_name }}"
gatus_icmp_endpoints: []
gatus_dns_endpoints: []
gatus_healthcheck_endpoints: []
6 changes: 0 additions & 6 deletions roles/gatus/handlers/main.yaml

This file was deleted.

29 changes: 8 additions & 21 deletions roles/gatus/tasks/main.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,9 @@
---
- name: Create directories
ansible.builtin.file:
path: "{{ item }}"
state: directory
mode: "0775"
loop:
- "{{ service_path }}"

- name: Create compose file
ansible.builtin.template:
src: "templates/compose.yaml.j2"
dest: "{{ service_path }}/compose.yaml"
mode: "0640"
notify: "Recreate {{ service_name }}"

- name: Create config
ansible.builtin.template:
src: "templates/config.yaml.j2"
dest: "{{ service_path }}/config.yaml"
mode: "0640"
notify: "Recreate {{ service_name }}"
- name: Create docker compose service
ansible.builtin.include_role:
name: docker_compose_service
vars:
docker_compose_service_name: gatus
docker_compose_service_template: true
docker_compose_service_extra_templates:
- config.yaml
3 changes: 0 additions & 3 deletions roles/homepage/defaults/main.yaml

This file was deleted.

6 changes: 0 additions & 6 deletions roles/homepage/handlers/main.yaml

This file was deleted.

50 changes: 16 additions & 34 deletions roles/homepage/tasks/main.yaml
Original file line number Diff line number Diff line change
@@ -1,35 +1,17 @@
---
- name: Create directories
ansible.builtin.file:
path: "{{ item }}"
state: directory
mode: "0775"
loop:
- "{{ service_path }}"
- "{{ service_path }}/config"

- name: Create compose file
ansible.builtin.template:
src: "templates/compose.yaml.j2"
dest: "{{ service_path }}/compose.yaml"
mode: "0640"
notify: "Recreate {{ service_name }}"

- name: Create config
ansible.builtin.copy:
src: "files/{{ item }}"
dest: "{{ service_path }}/config/{{ item }}"
mode: "0640"
loop:
- bookmarks.yaml
- docker.yaml
- kubernetes.yaml
- settings.yaml
- widgets.yaml
notify: "Recreate {{ service_name }}"

- name: Create config
ansible.builtin.template:
src: "templates/services.yaml.j2"
dest: "{{ service_path }}/config/services.yaml"
mode: "0640"
- name: Create docker compose service
ansible.builtin.include_role:
name: docker_compose_service
vars:
docker_compose_service_name: homepage
docker_compose_service_sub_directories:
- config
docker_compose_service_template: true
docker_compose_service_extra_files:
- config/bookmarks.yaml
- config/docker.yaml
- config/kubernetes.yaml
- config/settings.yaml
- config/widgets.yaml
docker_compose_service_extra_templates:
- config/services.yaml
3 changes: 0 additions & 3 deletions roles/mosquitto/defaults/main.yaml

This file was deleted.

6 changes: 0 additions & 6 deletions roles/mosquitto/handlers/main.yaml

This file was deleted.

36 changes: 12 additions & 24 deletions roles/mosquitto/tasks/main.yaml
Original file line number Diff line number Diff line change
@@ -1,25 +1,13 @@
---
- name: Create directories
ansible.builtin.file:
path: "{{ item }}"
state: directory
mode: "0775"
loop:
- "{{ service_path }}"
- "{{ service_path }}/config"
- "{{ service_path }}/data"
- "{{ service_path }}/log"

- name: Create compose file
ansible.builtin.copy:
src: "files/compose.yaml"
dest: "{{ service_path }}/compose.yaml"
mode: "0640"
notify: "Recreate {{ service_name }}"

- name: Create config file
ansible.builtin.copy:
src: "files/mosquitto.conf"
dest: "{{ service_path }}/config/mosquitto.conf"
mode: "0640"
notify: "Recreate {{ service_name }}"
- name: Create docker compose service
ansible.builtin.include_role:
name: docker_compose_service
vars:
docker_compose_service_name: mosquitto
docker_compose_service_sub_directories:
- config
- data
- log
docker_compose_service_file: true
docker_compose_service_extra_files:
- config/mosquitto.conf
3 changes: 0 additions & 3 deletions roles/pihole/defaults/main.yaml

This file was deleted.

6 changes: 0 additions & 6 deletions roles/pihole/handlers/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,3 @@
ansible.builtin.command: resolvconf -u
changed_when: true
become: true

- name: Recreate {{ service_name }}
ansible.builtin.command:
chdir: "{{ service_path }}"
cmd: docker compose up -d --force-recreate
changed_when: true
47 changes: 13 additions & 34 deletions roles/pihole/tasks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,16 @@
notify: Update resolvconf
when: pihole_which_resolvconf.rc == 0

- name: Create directories
ansible.builtin.file:
path: "{{ item }}"
state: directory
mode: "0775"
loop:
- "{{ service_path }}"
- "{{ service_path }}/etc-pihole"
- "{{ service_path }}/etc-dnsmasq.d"

- name: Create compose file
ansible.builtin.copy:
src: "files/{{ item }}"
dest: "{{ service_path }}/{{ item }}"
mode: "0640"
loop:
- compose.yaml
notify: "Recreate {{ service_name }}"

- name: Create adlists
ansible.builtin.copy:
src: "files/{{ item }}"
dest: "{{ service_path }}/etc-pihole/{{ item }}"
mode: "0640"
loop:
- adlists.list
notify: "Recreate {{ service_name }}"

- name: Create dns overrides
ansible.builtin.template:
src: "templates/03-dns-overrides.conf.j2"
dest: "{{ service_path }}/etc-dnsmasq.d/03-dns-overrides.conf"
mode: "0640"
notify: "Recreate {{ service_name }}"
- name: Create docker compose service
ansible.builtin.include_role:
name: docker_compose_service
vars:
docker_compose_service_name: pihole
docker_compose_service_sub_directories:
- etc-pihole
- etc-dnsmasq.d
docker_compose_service_file: true
docker_compose_service_extra_files:
- etc-pihole/adlists.list
docker_compose_service_extra_templates:
- etc-dnsmasq.d/03-dns-overrides.conf
3 changes: 0 additions & 3 deletions roles/zigbee2mqtt/defaults/main.yaml

This file was deleted.

6 changes: 0 additions & 6 deletions roles/zigbee2mqtt/handlers/main.yaml

This file was deleted.

45 changes: 13 additions & 32 deletions roles/zigbee2mqtt/tasks/main.yaml
Original file line number Diff line number Diff line change
@@ -1,36 +1,17 @@
---
- name: Create directories
ansible.builtin.file:
path: "{{ item }}"
state: directory
mode: "0775"
loop:
- "{{ service_path }}"
- "{{ service_path }}/data"

- name: Create compose file
ansible.builtin.copy:
src: "files/compose.yaml"
dest: "{{ service_path }}/compose.yaml"
mode: "0640"
notify: "Recreate {{ service_name }}"

- name: Create config
ansible.builtin.template:
src: "templates/configuration.yaml.j2"
dest: "{{ service_path }}/data/configuration.yaml"
mode: "0640"
notify: "Recreate {{ service_name }}"

- name: Create devices and groups
ansible.builtin.copy:
src: "files/{{ item }}"
dest: "{{ service_path }}/data/{{ item }}"
mode: "0400"
loop:
- devices.yaml
- groups.yaml
notify: "Recreate {{ service_name }}"
- name: Create docker compose service
ansible.builtin.include_role:
name: docker_compose_service
vars:
docker_compose_service_name: zigbee2mqtt
docker_compose_service_sub_directories:
- data
docker_compose_service_file: true
docker_compose_service_extra_files:
- data/devices.yaml
- data/groups.yaml
docker_compose_service_extra_templates:
- data/configuration.yaml

- name: Create backups with autorestic
ansible.builtin.include_role:
Expand Down

0 comments on commit d8e70c7

Please sign in to comment.