From 13cf7a05ee04e7e317f5c6d03462c0c61fd054bf Mon Sep 17 00:00:00 2001 From: Tobias Reisinger Date: Tue, 13 Jun 2023 22:36:13 +0200 Subject: [PATCH] Extract tasks to be included --- _ansible/roles/acme-dns/tasks/main.yml | 30 +++++++-------------- _ansible/roles/umami/tasks/main.yml | 29 +++----------------- _ansible/tasks/create-service-directory.yml | 9 +++++++ _ansible/tasks/template-docker-compose.yml | 5 ++++ _ansible/tasks/template-service-env.yml | 5 ++++ _ansible/tasks/template-site-config.yml | 5 ++++ 6 files changed, 37 insertions(+), 46 deletions(-) create mode 100644 _ansible/tasks/create-service-directory.yml create mode 100644 _ansible/tasks/template-docker-compose.yml create mode 100644 _ansible/tasks/template-service-env.yml create mode 100644 _ansible/tasks/template-site-config.yml diff --git a/_ansible/roles/acme-dns/tasks/main.yml b/_ansible/roles/acme-dns/tasks/main.yml index 89ae6a2..20ff8a0 100644 --- a/_ansible/roles/acme-dns/tasks/main.yml +++ b/_ansible/roles/acme-dns/tasks/main.yml @@ -1,36 +1,24 @@ --- - name: Deploy acme-dns tags: acme-dns - vars: - service_path: "{{ (services_path, svc.name) | path_join }}" - config_path: "{{ (service_path, 'config') | path_join }}" block: - - name: Create a service directory for {{ svc.name }} - ansible.builtin.file: - path: "{{ service_path }}" - state: directory - mode: "0755" + - import_tasks: create-service-directory.yml + - import_tasks: template-docker-compose.yml - - name: Create a service-config directory for {{ svc.name }} + - name: Setting the service config path + ansible.builtin.set_fact: + config_path: "{{ (service_path, 'config') | path_join }}" + + - name: Create a service-config directory ansible.builtin.file: path: "{{ config_path }}" state: directory mode: "0700" - - name: Template docker-compose for {{ svc.name }} - ansible.builtin.template: - src: docker-compose.yml.j2 - dest: "{{ (service_path, 'docker-compose.yml') | path_join }}" - mode: "0644" - - - name: Template config for {{ svc.name }} + - name: Template config ansible.builtin.template: src: config.cfg.j2 dest: "{{ (config_path, 'config.cfg') | path_join }}" mode: "0600" - - name: Template caddy config for {{ svc.name }} - ansible.builtin.template: - src: caddy_site.conf.j2 - dest: "{{ (caddy_config_path, svc.domain + '.conf') | path_join }}" - mode: "0644" + - import_tasks: template-site-config.yml diff --git a/_ansible/roles/umami/tasks/main.yml b/_ansible/roles/umami/tasks/main.yml index cf9ef6a..6964ac8 100644 --- a/_ansible/roles/umami/tasks/main.yml +++ b/_ansible/roles/umami/tasks/main.yml @@ -3,29 +3,8 @@ tags: - analytics - umami - vars: - service_path: "{{ (services_path, svc.name) | path_join }}" block: - - name: Create a service directory for {{ svc.name }} - ansible.builtin.file: - path: "{{ service_path }}" - state: directory - mode: "0755" - - - name: Template docker-compose for {{ svc.name }} - ansible.builtin.template: - src: docker-compose.yml.j2 - dest: "{{ (service_path, 'docker-compose.yml') | path_join }}" - mode: "0644" - - - name: Template service.env file for {{ svc.name }} - ansible.builtin.template: - src: service.env.j2 - dest: "{{ (service_path, 'service.env') | path_join }}" - mode: "0600" - - - name: Template caddy config for {{ svc.name }} - ansible.builtin.template: - src: caddy_site.conf.j2 - dest: "{{ (caddy_config_path, svc.domain + '.conf') | path_join }}" - mode: "0644" + - import_tasks: create-service-directory.yml + - import_tasks: template-docker-compose.yml + - import_tasks: template-service-env.yml + - import_tasks: template-site-config.yml diff --git a/_ansible/tasks/create-service-directory.yml b/_ansible/tasks/create-service-directory.yml new file mode 100644 index 0000000..663bdff --- /dev/null +++ b/_ansible/tasks/create-service-directory.yml @@ -0,0 +1,9 @@ +- name: Setting the service path + ansible.builtin.set_fact: + service_path: "{{ (services_path, svc.name) | path_join }}" + +- name: Create a service directory + ansible.builtin.file: + path: "{{ service_path }}" + state: directory + mode: "0755" diff --git a/_ansible/tasks/template-docker-compose.yml b/_ansible/tasks/template-docker-compose.yml new file mode 100644 index 0000000..1be7475 --- /dev/null +++ b/_ansible/tasks/template-docker-compose.yml @@ -0,0 +1,5 @@ +- name: Template docker-compose + ansible.builtin.template: + src: docker-compose.yml.j2 + dest: "{{ (service_path, 'docker-compose.yml') | path_join }}" + mode: "0644" diff --git a/_ansible/tasks/template-service-env.yml b/_ansible/tasks/template-service-env.yml new file mode 100644 index 0000000..1425ee2 --- /dev/null +++ b/_ansible/tasks/template-service-env.yml @@ -0,0 +1,5 @@ +- name: Template service.env file + ansible.builtin.template: + src: service.env.j2 + dest: "{{ (service_path, 'service.env') | path_join }}" + mode: "0600" diff --git a/_ansible/tasks/template-site-config.yml b/_ansible/tasks/template-site-config.yml new file mode 100644 index 0000000..90ebb35 --- /dev/null +++ b/_ansible/tasks/template-site-config.yml @@ -0,0 +1,5 @@ +- name: Template caddy config + ansible.builtin.template: + src: caddy_site.conf.j2 + dest: "{{ (caddy_config_path, svc.domain + '.conf') | path_join }}" + mode: "0644"