commit 99a9c367adad565b4543d3a9e18389bf94fe60cf Author: yohan <783b8c87@scimetis.net> Date: Sat Jun 8 11:37:02 2024 +0200 Initial commit. diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bb8d35e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +roles/role* diff --git a/README.md b/README.md new file mode 100644 index 0000000..ff36487 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# deploy +$ SECRETS_ARCHIVE_PASSPHRASE=XXXXXX ansible-playbook -e target_name=host.domain -e SECRET_HOST=host2.domain2 deploy.yml diff --git a/ansible.cfg b/ansible.cfg new file mode 100644 index 0000000..da03e95 --- /dev/null +++ b/ansible.cfg @@ -0,0 +1,4 @@ +[defaults] +inventory = inventory.yml +host_key_checking = accept-new +callback_whitelist=ansible.posix.profile_tasks, ansible.posix.timer diff --git a/deploy.yml b/deploy.yml new file mode 100644 index 0000000..391ffb8 --- /dev/null +++ b/deploy.yml @@ -0,0 +1,116 @@ +- name: Construct inventory + hosts: localhost + tasks: + - name: add new instance to host group at runtime + ansible.builtin.add_host: + name: "{{ target_name }}" + groups: target + changed_when: false + +- name: Configure Modane server + hosts: target + gather_facts: false + tasks: + - name: Gather facts + ansible.builtin.setup: + + - name: Include role_unpack_secrets + ansible.builtin.include_role: + name: role_unpack_secrets + vars: + LOCAL_AND_REMOTE: true + + - name: Include secrets from yml db + ansible.builtin.include_vars: "{{ local_workdir }}/secrets/secrets.yml" + + - name: Create homeassistant container + containers.podman.podman_container: + name: homeassistant + image: ghcr.io/home-assistant/home-assistant:2024.3 + network: + - host + env: + TZ: "Europe/Paris" + privileged: true + restart_policy: always + volume: + - /mnt/apps/volumes/homeassistant_conf:/config + become: true + + - name: create docker-mounted-files directory + ansible.builtin.file: + path: "/usr/local/docker-mounted-files/docker-thermostat" + state: directory + become: true + + - name: Template thermostat conf.yml + ansible.builtin.template: + src: templates/conf.yml.j2 + dest: /usr/local/docker-mounted-files/docker-thermostat/conf.yml + become: true + + - name: Build thermostat image + ansible.builtin.include_role: + name: role_build_container_image + vars: + image: "{{ item }}" + with_items: + - repo_url: https://git.scimetis.net/yohan/docker-thermostat.git + repo_name: docker-thermostat + name: thermostat + result_var: build_result + + - debug: var=build_result + when: build_result.changed + + - name: Gather facts on thermostat container + containers.podman.podman_container_info: + name: thermostat + register: container_info + become: true + + - debug: var=container_info.containers[0].Config.Annotations.git_commit + when: container_info.containers | length == 1 + + - name: Set fact bool_recreate to true + set_fact: + bool_recreate: true + when: + - container_info.containers | length == 1 + - container_info.containers[0].Config.Annotations.git_commit != commit + + - name: create thermostat volume + ansible.builtin.file: + path: "/mnt/apps/volumes/thermostat" + state: directory + become: true + + - name: Delete thermostat container + containers.podman.podman_container: + name: thermostat + state: absent + become: true + when: bool_recreate | default(false) + + - name: Create thermostat container + containers.podman.podman_container: + name: thermostat + image: localhost/thermostat:latest + network: + - host + env: + TZ: "Europe/Paris" + GUNICORN_CMD_ARGS: "--bind=0.0.0.0:3002" + privileged: true + restart_policy: always + volume: + - /usr/local/docker-mounted-files/docker-thermostat/conf.yml:/root/conf.yml + - /mnt/apps/volumes/thermostat:/root/instance + - /run/udev:/run/udev + become: true + when: bool_recreate | default(false) or container_info.containers | length == 0 + + - name: Prune images + containers.podman.podman_prune: + image: true + become: true diff --git a/install_requirements.sh b/install_requirements.sh new file mode 100755 index 0000000..e574ee3 --- /dev/null +++ b/install_requirements.sh @@ -0,0 +1,9 @@ +#!/bin/bash +#Absolute path to this script +SCRIPT=$(readlink -f $0) +#Absolute path this script is in +SCRIPTPATH=$(dirname $SCRIPT) + +cd $SCRIPTPATH +ansible-galaxy role install -r roles/requirements.yml -p roles/ + diff --git a/inventory.yml b/inventory.yml new file mode 100644 index 0000000..e0ca795 --- /dev/null +++ b/inventory.yml @@ -0,0 +1,4 @@ +target: + vars: + ansible_user: yohan + diff --git a/roles/requirements.yml b/roles/requirements.yml new file mode 100644 index 0000000..e0bf56c --- /dev/null +++ b/roles/requirements.yml @@ -0,0 +1,9 @@ +--- +- name : role_unpack_secrets + src : ssh://git@git.scimetis.net:2222/yohan/role_unpack_secrets.git + scm: git + +- name : role_build_container_image + src : ssh://git@git.scimetis.net:2222/yohan/role_build_container_image.git + scm: git + diff --git a/templates/conf.yml.j2 b/templates/conf.yml.j2 new file mode 100644 index 0000000..ff96e50 --- /dev/null +++ b/templates/conf.yml.j2 @@ -0,0 +1,77 @@ +api_key: "{{ modane_server_thermostat_api_key }}" + +debug: False + +targets: + - target_awake_temperature + - target_sleep_temperature + - target_frost_protection + +modes: + - short_absence + - long_absence + +rooms_settings: + "double bedroom": + target_awake_temperature: 19 + target_unconfirmed_awake_temperature: 18 + target_sleep_temperature: 18 + target_unconfirmed_sleep_temperature: 18 + target_frost_protection: 6 + metric: Modane_temperature_double_bedroom + relays: "1" + enabled: True + "single bedroom": + target_awake_temperature: 17 + target_unconfirmed_awake_temperature: 16 + target_sleep_temperature: 16 + target_unconfirmed_sleep_temperature: 16 + target_frost_protection: 6 + metric: Modane_temperature_single_bedroom + relays: "3" + enabled: True + "living room": + target_awake_temperature: 21 + target_unconfirmed_awake_temperature: 21 + target_sleep_temperature: 18 + target_unconfirmed_sleep_temperature: 18 + target_frost_protection: 6 + metric: Modane_temperature_living_room + relays: "4" + enabled: True + "bathroom": + target_awake_temperature: 21 + target_unconfirmed_awake_temperature: 21 + target_sleep_temperature: 19 + target_unconfirmed_sleep_temperature: 19 + target_frost_protection: 6 + metric: Modane_temperature_bathroom + relays: "" + enabled: False + +# If there is too much load, it most likely means someone is cooking and nobody is in the bedrooms. +shedding_order: + - double bedroom + - single bedroom + - living room + +default_target: target_frost_protection + +# Load in VA +relays_load: + "1": 1500 + "3": 1500 + "4": 2000 + +awake_hour: "7:30" +sleep_hour: "23:30" +forced_mode_duration: 7200.0 +load_shedder_interval: 10.0 +relay_control_interval: 300.0 +hysteresis: 0.5 + +# Puissance souscrite : 6kVA +# Puissance max avant coupure (marge 30%) : 7,8kVA +max_load: 7800 +load_margin: 100 +