Initial commit.

This commit is contained in:
yohan 2024-06-08 11:37:02 +02:00
commit 99a9c367ad
8 changed files with 222 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
roles/role*

2
README.md Normal file
View File

@ -0,0 +1,2 @@
# deploy
$ SECRETS_ARCHIVE_PASSPHRASE=XXXXXX ansible-playbook -e target_name=host.domain -e SECRET_HOST=host2.domain2 deploy.yml

4
ansible.cfg Normal file
View File

@ -0,0 +1,4 @@
[defaults]
inventory = inventory.yml
host_key_checking = accept-new
callback_whitelist=ansible.posix.profile_tasks, ansible.posix.timer

116
deploy.yml Normal file
View File

@ -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

9
install_requirements.sh Executable file
View File

@ -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/

4
inventory.yml Normal file
View File

@ -0,0 +1,4 @@
target:
vars:
ansible_user: yohan

9
roles/requirements.yml Normal file
View File

@ -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

77
templates/conf.yml.j2 Normal file
View File

@ -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