diff --git a/.gitignore b/.gitignore index 691037e..3e7f87c 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ .venv/* +.ansible/* diff --git a/README.md b/README.md index 66869ec..6fd2fcb 100644 --- a/README.md +++ b/README.md @@ -7,22 +7,21 @@ System: ``` Python: - ```bash python3 -m venv .venv source ./.venv/bin/activate pip install -r requirements.txt ``` -Ansible (not needed for now): +Ansible (not needed for now): ```bash ansible-galaxy install -r requirements.yml ``` ## Start Files: -- `./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 +- `./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. Then start the root of repo and execute ```bash diff --git a/ansible.cfg b/ansible.cfg new file mode 100644 index 0000000..859f3e1 --- /dev/null +++ b/ansible.cfg @@ -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 diff --git a/main.yml b/main.yml index d8e653e..f556783 100644 --- a/main.yml +++ b/main.yml @@ -8,3 +8,5 @@ ansible.builtin.import_playbook: playbooks/10-install-docker.yml - name: Setup wireguard ansible.builtin.import_playbook: playbooks/20-install-wireguard.yml +- name: Setup homeassistant + ansible.builtin.import_playbook: playbooks/110-install-homeassistant.yml diff --git a/playbooks/10-install-docker.yml b/playbooks/10-install-docker.yml index 9e9f6cf..9ee8ff5 100644 --- a/playbooks/10-install-docker.yml +++ b/playbooks/10-install-docker.yml @@ -38,9 +38,11 @@ state: latest update_cache: true - - name: Install Docker Module for Python + - name: Install Docker Module for Python (ansible needs this to work) pip: - name: docker + name: + - docker + - docker-compose - name: Ensure Docker is enabled and running ansible.builtin.systemd: diff --git a/playbooks/110-install-homeassistant.yml b/playbooks/110-install-homeassistant.yml new file mode 100644 index 0000000..4f28770 --- /dev/null +++ b/playbooks/110-install-homeassistant.yml @@ -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 diff --git a/playbooks/templates/homeassistant/docker-compose.yml.j2 b/playbooks/templates/homeassistant/docker-compose.yml.j2 new file mode 100644 index 0000000..9cc5ec3 --- /dev/null +++ b/playbooks/templates/homeassistant/docker-compose.yml.j2 @@ -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