Update ansible config and add homeassistant setup

main
Gašper Spagnolo 2023-04-16 22:13:49 +02:00
parent fef57fbea1
commit e6826fad67
7 changed files with 86 additions and 6 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
.venv/* .venv/*
.ansible/*

View File

@ -7,22 +7,21 @@ System:
``` ```
Python: Python:
```bash ```bash
python3 -m venv .venv python3 -m venv .venv
source ./.venv/bin/activate source ./.venv/bin/activate
pip install -r requirements.txt pip install -r requirements.txt
``` ```
Ansible (not needed for now):
Ansible (not needed for now):
```bash ```bash
ansible-galaxy install -r requirements.yml ansible-galaxy install -r requirements.yml
``` ```
## Start ## Start
Files: Files:
- `./playbooks/files/wireguard/de.conf` - Wireguard config should be placed here before running the playbook (basically the peer file for the wireguard - `./playbooks/files/wireguard/de.conf` - Wireguard config should be placed here before running the playbook (basically the peer file for the wireguard).
- `inventory` - Should be checked if the host is correct one, also the pubkey should be included - `inventory` - Should be checked if the host is correct one, also the pubkey should be included.
Then start the root of repo and execute Then start the root of repo and execute
```bash ```bash

15
ansible.cfg Normal file
View File

@ -0,0 +1,15 @@
[defaults]
inventory = ./inventory.ini
forks = 20
host_key_checking = False
retry_files_enabled = False
callbacks_enabled = profile_tasks
gathering = smart
fact_caching = jsonfile
fact_caching_timeout = 86400
fact_caching_connection = .ansible/cache
[ssh_connection]
ssh_args = -o ControlMaster=auto -o ControlPersist=600s -o UserKnownHostsFile=/dev/null
control_path = %(directory)s/ansible-ssh-%%h-%%p-%%r
pipelining = True

View File

@ -8,3 +8,5 @@
ansible.builtin.import_playbook: playbooks/10-install-docker.yml ansible.builtin.import_playbook: playbooks/10-install-docker.yml
- name: Setup wireguard - name: Setup wireguard
ansible.builtin.import_playbook: playbooks/20-install-wireguard.yml ansible.builtin.import_playbook: playbooks/20-install-wireguard.yml
- name: Setup homeassistant
ansible.builtin.import_playbook: playbooks/110-install-homeassistant.yml

View File

@ -38,9 +38,11 @@
state: latest state: latest
update_cache: true update_cache: true
- name: Install Docker Module for Python - name: Install Docker Module for Python (ansible needs this to work)
pip: pip:
name: docker name:
- docker
- docker-compose
- name: Ensure Docker is enabled and running - name: Ensure Docker is enabled and running
ansible.builtin.systemd: ansible.builtin.systemd:

View File

@ -0,0 +1,45 @@
---
- name: Install home assitant
hosts: all
become: true
strategy: free
gather_facts: true
become_method: sudo
vars:
- hass_dir: /docker/homeassistant
- hass_config: "{{ hass_dir }}/config"
- hass_docker_compose: "{{ hass_dir }}/docker-compose.yml"
tasks:
- name: "Check if {{ hass_dir }} exists, otherwise create it"
ansible.builtin.file:
path: "{{ hass_dir }}"
state: directory
owner: root
group: root
mode: 0755
- name: "Check if {{ hass_config }} exists, otherwise create it"
ansible.builtin.file:
path: "{{ hass_config }}"
state: directory
owner: root
group: root
mode: 0755
- name: Copy docker-compose jinja templaate to host
ansible.builtin.template:
src: templates/homeassistant/docker-compose.yml.j2
dest: "{{ hass_docker_compose }}"
owner: root
group: root
mode: 0600
- name: Start home assistant
docker_compose:
project_src: "{{ hass_dir }}"
state: present
pull: true
recreate: smart
build: true
services: homeassistant

View File

@ -0,0 +1,16 @@
---
version: "3"
services:
homeassistant:
image: lscr.io/linuxserver/homeassistant:latest
container_name: homeassistant
#network_mode: host
environment:
- PUID=1000
- PGID=1000
- TZ=Etc/UTC
volumes:
- {{ hass_config }}:/config
ports:
- 8123:8123 #optional
restart: unless-stopped