diff --git a/confs/home_assistant/docker-compose.yml b/confs/home_assistant/docker-compose.yml deleted file mode 100644 index 20aa75b..0000000 --- a/confs/home_assistant/docker-compose.yml +++ /dev/null @@ -1,26 +0,0 @@ -version: '3' - -services: - home_assistant: - image: homeassistant/home-assistant - restart: always - container_name: home_assistant - environment: - - TZ=Europe/Paris - volumes: - - home_assistant_config:/config - - /etc/localtime:/etc/localtime:ro - network_mode: host - expose: - - 8123 - labels: - - "traefik.enable=true" - - "traefik.http.routers.homeassistant-secure.entrypoints=https" - - "traefik.http.routers.homeassistant-secure.rule=Host(`domo.mrdev023.fr`)" - - "traefik.http.routers.homeassistant-secure.tls=true" - - "traefik.http.routers.homeassistant-secure.tls.certresolver=sslResolver" - # - "traefik.http.routers.homeassistant-secure.service=homeassistant" - - "traefik.http.services.homeassistant.loadbalancer.server.port=8123" - -volumes: - home_assistant_config: diff --git a/group_vars/all.yml b/group_vars/all.yml index d59b22d..794e1ea 100644 --- a/group_vars/all.yml +++ b/group_vars/all.yml @@ -1,7 +1,7 @@ ## # Global configuration server: - domain: mrdev023.fr + domain: mrdev023.test acme: email: florian.richer.97@outlook.com debug: true diff --git a/playbook.yml b/playbook.yml index 721ec4e..5e1f8f6 100644 --- a/playbook.yml +++ b/playbook.yml @@ -8,3 +8,6 @@ - { role: whoami, tags: ["whoami"] } - { role: protonmail, tags: ["protonmail"] } - { role: cloud, tags: ["cloud"] } + - { role: home_assistant, tags: ["home_assistant"] } + - { role: n8n, tags: ["n8n"] } + - { role: matrix, tags: ["matrix"] } diff --git a/roles/home_assistant/tasks/base.yml b/roles/home_assistant/tasks/base.yml new file mode 100644 index 0000000..063a322 --- /dev/null +++ b/roles/home_assistant/tasks/base.yml @@ -0,0 +1,32 @@ +--- + +- name: Check home_assistant directory exist + ansible.builtin.file: + path: home_assistant + state: directory + +- name: Copy template conf + ansible.builtin.template: + backup: true + src: "{{ item.src }}" + dest: "home_assistant/{{ item.dest }}" + loop: + - { src: 'docker-compose.yml.j2', dest: 'docker-compose.yml' } + register: home_assistant_copy_templates_results + +- name: Force update and restart container + community.docker.docker_compose: + project_src: home_assistant + state: present + pull: true + restarted: true + when: home_assistant_copy_templates_results.changed + become: true + +- name: Update or start container + community.docker.docker_compose: + project_src: home_assistant + state: present + pull: true + when: not home_assistant_copy_templates_results.changed + become: true \ No newline at end of file diff --git a/roles/home_assistant/tasks/main.yml b/roles/home_assistant/tasks/main.yml new file mode 100644 index 0000000..3f670ac --- /dev/null +++ b/roles/home_assistant/tasks/main.yml @@ -0,0 +1,4 @@ +--- + +- ansible.builtin.import_tasks: base.yml + name: base \ No newline at end of file diff --git a/roles/home_assistant/templates/docker-compose.yml.j2 b/roles/home_assistant/templates/docker-compose.yml.j2 new file mode 100644 index 0000000..e033599 --- /dev/null +++ b/roles/home_assistant/templates/docker-compose.yml.j2 @@ -0,0 +1,26 @@ +version: '3' + +services: + home_assistant: + image: homeassistant/home-assistant + restart: always + container_name: home_assistant + environment: + - TZ=Europe/Paris + volumes: + - home_assistant_config:/config + - /etc/localtime:/etc/localtime:ro + network_mode: host + expose: + - 8123 + labels: + - "traefik.enable=true" + - "traefik.http.routers.homeassistant-secure.entrypoints=https" + - "traefik.http.routers.homeassistant-secure.rule=Host(`domo.{{ server.domain }}`)" + - "traefik.http.routers.homeassistant-secure.tls=true" + - "traefik.http.routers.homeassistant-secure.tls.certresolver=sslResolver" + # - "traefik.http.routers.homeassistant-secure.service=homeassistant" + - "traefik.http.services.homeassistant.loadbalancer.server.port=8123" + +volumes: + home_assistant_config: \ No newline at end of file diff --git a/confs/matrix/nginx/matrix.conf b/roles/matrix/files/nginx/matrix.conf similarity index 100% rename from confs/matrix/nginx/matrix.conf rename to roles/matrix/files/nginx/matrix.conf diff --git a/confs/matrix/nginx/www/.well-known/matrix/client b/roles/matrix/files/nginx/www/.well-known/matrix/client similarity index 100% rename from confs/matrix/nginx/www/.well-known/matrix/client rename to roles/matrix/files/nginx/www/.well-known/matrix/client diff --git a/confs/matrix/nginx/www/.well-known/matrix/server b/roles/matrix/files/nginx/www/.well-known/matrix/server similarity index 100% rename from confs/matrix/nginx/www/.well-known/matrix/server rename to roles/matrix/files/nginx/www/.well-known/matrix/server diff --git a/roles/matrix/tasks/base.yml b/roles/matrix/tasks/base.yml new file mode 100644 index 0000000..931ec23 --- /dev/null +++ b/roles/matrix/tasks/base.yml @@ -0,0 +1,39 @@ +--- + +- name: Check matrix directory exist + ansible.builtin.file: + path: matrix + state: directory + +- name: Copy matrix conf + ansible.builtin.copy: + backup: true + src: . + dest: matrix/ + register: matrix_copy_files_results + +- name: Copy template conf + ansible.builtin.template: + backup: true + src: "{{ item.src }}" + dest: "matrix/{{ item.dest }}" + loop: + - { src: 'docker-compose.yml.j2', dest: 'docker-compose.yml' } + register: matrix_copy_templates_results + +- name: Force update and restart container + community.docker.docker_compose: + project_src: matrix + state: present + pull: true + restarted: true + when: matrix_copy_files_results.changed or matrix_copy_templates_results.changed + become: true + +- name: Update or start container + community.docker.docker_compose: + project_src: matrix + state: present + pull: true + when: not matrix_copy_files_results.changed and not matrix_copy_templates_results.changed + become: true \ No newline at end of file diff --git a/roles/matrix/tasks/main.yml b/roles/matrix/tasks/main.yml new file mode 100644 index 0000000..3f670ac --- /dev/null +++ b/roles/matrix/tasks/main.yml @@ -0,0 +1,4 @@ +--- + +- ansible.builtin.import_tasks: base.yml + name: base \ No newline at end of file diff --git a/confs/matrix/docker-compose.yaml b/roles/matrix/templates/docker-compose.yml.j2 similarity index 92% rename from confs/matrix/docker-compose.yaml rename to roles/matrix/templates/docker-compose.yml.j2 index ca71dc1..1e6e2e7 100644 --- a/confs/matrix/docker-compose.yaml +++ b/roles/matrix/templates/docker-compose.yml.j2 @@ -27,7 +27,7 @@ services: labels: - "traefik.enable=true" - "traefik.http.routers.matrix-secure.entrypoints=https" - - "traefik.http.routers.matrix-secure.rule=Host(`matrix.mrdev023.fr`)" + - "traefik.http.routers.matrix-secure.rule=Host(`matrix.{{ server.domain }}`)" - "traefik.http.routers.matrix-secure.tls=true" - "traefik.http.routers.matrix-secure.tls.certresolver=sslResolver" - "traefik.port=8008" @@ -47,7 +47,7 @@ services: - "traefik.http.middlewares.cors-headers.headers.accessControlAllowOriginList=*" - "traefik.http.middlewares.cors-headers.headers.accessControlAllowHeaders=Origin, X-Requested-With, Content-Type, Accept, Authorization" - "traefik.http.middlewares.cors-headers.headers.accessControlAllowMethods=GET, POST, PUT, DELETE, OPTIONS" - - "traefik.http.routers.matrix-wellknown.rule=Host(`matrix.mrdev023.fr`) && PathPrefix(`/.well-known/matrix`)" + - "traefik.http.routers.matrix-wellknown.rule=Host(`matrix.{{ server.domain }}`) && PathPrefix(`/.well-known/matrix`)" - "traefik.http.routers.matrix-wellknown.tls=true" - "traefik.http.routers.matrix-wellknown.tls.certresolver=sslResolver" - "traefik.http.routers.matrix-wellknown.middlewares=cors-headers@docker" diff --git a/roles/n8n/tasks/base.yml b/roles/n8n/tasks/base.yml new file mode 100644 index 0000000..3c3ef93 --- /dev/null +++ b/roles/n8n/tasks/base.yml @@ -0,0 +1,32 @@ +--- + +- name: Check n8n directory exist + ansible.builtin.file: + path: n8n + state: directory + +- name: Copy template conf + ansible.builtin.template: + backup: true + src: "{{ item.src }}" + dest: "n8n/{{ item.dest }}" + loop: + - { src: 'docker-compose.yml.j2', dest: 'docker-compose.yml' } + register: n8n_copy_templates_results + +- name: Force update and restart container + community.docker.docker_compose: + project_src: n8n + state: present + pull: true + restarted: true + when: n8n_copy_templates_results.changed + become: true + +- name: Update or start container + community.docker.docker_compose: + project_src: n8n + state: present + pull: true + when: not n8n_copy_templates_results.changed + become: true \ No newline at end of file diff --git a/roles/n8n/tasks/main.yml b/roles/n8n/tasks/main.yml new file mode 100644 index 0000000..3f670ac --- /dev/null +++ b/roles/n8n/tasks/main.yml @@ -0,0 +1,4 @@ +--- + +- ansible.builtin.import_tasks: base.yml + name: base \ No newline at end of file diff --git a/confs/n8n/docker-compose.yml b/roles/n8n/templates/docker-compose.yml.j2 similarity index 93% rename from confs/n8n/docker-compose.yml rename to roles/n8n/templates/docker-compose.yml.j2 index e071f14..2d35442 100644 --- a/confs/n8n/docker-compose.yml +++ b/roles/n8n/templates/docker-compose.yml.j2 @@ -26,7 +26,7 @@ services: labels: - "traefik.enable=true" - "traefik.http.routers.n8n-secure.entrypoints=https" - - "traefik.http.routers.n8n-secure.rule=Host(`n8n.mrdev023.fr`)" + - "traefik.http.routers.n8n-secure.rule=Host(`n8n.{{ server.domain }}`)" - "traefik.http.routers.n8n-secure.tls=true" - "traefik.http.routers.n8n-secure.tls.certresolver=sslResolver" # - "traefik.http.routers.whoami-secure.service=whoami"