modane_server_playbooks/deploy.yml

117 lines
3.4 KiB
YAML
Raw Normal View History

2024-06-08 09:37:02 +00:00
- 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