ansible-nas/roles/esphome/tasks/main.yml

43 lines
1.5 KiB
YAML
Raw Normal View History

---
2022-09-07 21:37:47 +00:00
- name: Start EspHome
block:
- name: Create EspHome Directories
2023-04-15 13:11:49 +00:00
ansible.builtin.file:
2022-09-07 21:37:47 +00:00
path: "{{ item }}"
state: directory
with_items:
- "{{ esphome_data_directory }}/data"
2022-09-07 21:37:47 +00:00
- name: EspHome Docker Container
2023-04-15 13:11:49 +00:00
community.docker.docker_container:
2022-09-07 21:37:47 +00:00
name: "{{ esphome_container_name }}"
image: esphome/esphome:latest
pull: true
volumes:
- "{{ esphome_data_directory }}:/config:rw"
- "/etc/localtime:/etc/localtime:ro"
ports:
- "{{ esphome_port }}:6052"
env:
TZ: "{{ ansible_nas_timezone }}"
PUID: "{{ esphome_user_id }}"
PGID: "{{ esphome_group_id }}"
restart_policy: unless-stopped
memory: "{{ esphome_memory }}"
labels:
traefik.enable: "{{ esphome_available_externally | string }}"
traefik.http.routers.esphome.rule: "Host(`{{ esphome_hostname }}.{{ ansible_nas_domain }}`)"
traefik.http.routers.esphome.tls.certresolver: "letsencrypt"
traefik.http.routers.esphome.tls.domains[0].main: "{{ ansible_nas_domain }}"
traefik.http.routers.esphome.tls.domains[0].sans: "*.{{ ansible_nas_domain }}"
traefik.http.services.esphome.loadbalancer.server.port: "80"
when: esphome_enabled is true
- name: Stop EspHome
block:
- name: Stop EspHome
2023-04-15 13:11:49 +00:00
community.docker.docker_container:
2022-09-07 21:37:47 +00:00
name: "{{ esphome_container_name }}"
state: absent
when: esphome_enabled is false