From 95b73daa36b23565a8566f71f9b202d3459b685f Mon Sep 17 00:00:00 2001 From: Sam Chudnick Date: Sun, 25 Jun 2023 09:52:36 -0400 Subject: Initial Commit --- .../containers/home_assistant/tasks/main.yml | 86 ++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 roles/services/containers/home_assistant/tasks/main.yml (limited to 'roles/services/containers/home_assistant/tasks') diff --git a/roles/services/containers/home_assistant/tasks/main.yml b/roles/services/containers/home_assistant/tasks/main.yml new file mode 100644 index 0000000..b44c529 --- /dev/null +++ b/roles/services/containers/home_assistant/tasks/main.yml @@ -0,0 +1,86 @@ +- name: set image fact + set_fact: + image: homeassistant/home-assistant:2023.6.3 + +- name: set other facts + vars: + array: "{{ image.split('/', 1) }}" + set_fact: + repo_tag: "{{ array.1 }}" + custom_registry: "{{ docker_registry_url + '/' + docker_registry_username }}" + +- name: create home_assistant directory + file: + path: "{{ docker_home }}/home_assistant" + state: directory + owner: "{{ docker_username }}" + group: "{{ docker_username }}" + mode: '0755' + +- name: create config directory + file: + path: "{{ docker_home }}/home_assistant/config" + state: directory + owner: "{{ docker_username }}" + group: "{{ docker_username }}" + mode: '0755' + +- name: deploy configuration + copy: + src: "{{ home_assistant_config }}" + dest: "{{ docker_home }}/home_assistant/config/configuration.yaml" + owner: "{{ docker_username }}" + group: "{{ docker_username }}" + mode: '0644' + +- name: create home_assistant network + become: yes + become_user: "{{ docker_username }}" + docker_network: + name: "{{ home_assistant_network_name }}" + docker_host: "unix://run/user/{{ docker_uid }}/docker.sock" + driver: bridge + ipam_config: + - subnet: "{{ home_assistant_subnet }}" + gateway: "{{ home_assistant_gateway }}" + +- name: create and deploy home_assistant container + become: yes + become_user: "{{ docker_username }}" + environment: + XDG_RUNTIME_DIR: "/run/user/{{ docker_uid }}" + docker_container: + name: "home_assistant" + hostname: "home_assistant" + image: "{{ image }}" + docker_host: "unix://run/user/{{ docker_uid }}/docker.sock" + purge_networks: yes + networks: + - name: "{{ home_assistant_network_name }}" + ipv4_address: "{{ home_assistant_ipv4 }}" + ports: + - "127.0.0.1:{{ home_assistant_external_port }}:8123" + volumes: + - "{{ docker_home }}/home_assistant/config:/config" + env: + "TZ": "{{ timezone }}" + state: 'started' + recreate: yes + restart_policy: unless-stopped + +- name: deploy nginx configuration + notify: restart nginx + template: + src: "{{ home_assistant_nginx_config }}" + dest: /etc/nginx/sites-available/home_assistant.conf + owner: root + group: root + mode: '0644' + +- name: symlink site + file: + src: /etc/nginx/sites-available/home_assistant.conf + dest: /etc/nginx/sites-enabled/home_assistant.conf + owner: root + group: root + state: link -- cgit v1.2.3