docs: rewrite README with structured overview and quick start guide
Replaces the minimal project description with a comprehensive README including a component overview table, quick start instructions, common Ansible operations, and links to detailed documentation. Aligns with Red Panda Approval™ standards.
This commit is contained in:
139
ansible/hass/deploy.yml
Normal file
139
ansible/hass/deploy.yml
Normal file
@@ -0,0 +1,139 @@
|
||||
---
|
||||
- name: Deploy Home Assistant to Dev Environment
|
||||
hosts: ubuntu
|
||||
vars:
|
||||
ansible_common_remote_group: "{{hass_group}}"
|
||||
allow_world_readable_tmpfiles: true
|
||||
tasks:
|
||||
- name: Check if host has hass service
|
||||
ansible.builtin.set_fact:
|
||||
has_hass_service: "{{ 'hass' in services | default([]) }}"
|
||||
|
||||
- name: Skip hosts without hass service
|
||||
ansible.builtin.meta: end_host
|
||||
when: not has_hass_service
|
||||
|
||||
- name: Create hass user
|
||||
become: true
|
||||
ansible.builtin.user:
|
||||
name: "{{hass_user}}"
|
||||
comment: "{{hass_user}}"
|
||||
system: true
|
||||
create_home: false
|
||||
|
||||
- name: Add group hass to user {{remote_user}}
|
||||
become: true
|
||||
ansible.builtin.user:
|
||||
name: "{{remote_user}}"
|
||||
groups: "{{hass_group}}"
|
||||
append: true
|
||||
|
||||
- name: Create required directories
|
||||
become: true
|
||||
ansible.builtin.file:
|
||||
path: "{{item.path}}"
|
||||
owner: "{{hass_user}}"
|
||||
group: "{{hass_group}}"
|
||||
state: directory
|
||||
mode: '750'
|
||||
loop:
|
||||
- path: "{{hass_directory}}"
|
||||
- path: "{{hass_media_directory}}"
|
||||
|
||||
- name: Add Deadsnakes APT repository
|
||||
become: true
|
||||
ansible.builtin.apt_repository:
|
||||
repo: ppa:deadsnakes/ppa
|
||||
|
||||
- name: Install Python 3.13 and build dependencies
|
||||
become: true
|
||||
ansible.builtin.apt:
|
||||
name:
|
||||
- python3.13-dev
|
||||
- python3.13-venv
|
||||
- build-essential
|
||||
- libffi-dev
|
||||
- libssl-dev
|
||||
state: present
|
||||
update_cache: true
|
||||
|
||||
- name: Create virtual environment
|
||||
become: true
|
||||
become_user: "{{hass_user}}"
|
||||
ansible.builtin.command:
|
||||
cmd: python3.13 -m venv {{hass_directory}}/env
|
||||
args:
|
||||
creates: "{{hass_directory}}/env/bin/activate"
|
||||
|
||||
- name: Template configuration files
|
||||
become: true
|
||||
ansible.builtin.template:
|
||||
src: "{{item.src}}"
|
||||
dest: "{{hass_directory}}/{{item.dest}}"
|
||||
owner: "{{hass_user}}"
|
||||
group: "{{hass_group}}"
|
||||
mode: '550'
|
||||
loop:
|
||||
- src: "configuration.yaml.j2"
|
||||
dest: "configuration.yaml"
|
||||
- src: "requirements.txt.j2"
|
||||
dest: "requirements.txt"
|
||||
notify: restart hass
|
||||
|
||||
- name: Create systemd service file
|
||||
become: true
|
||||
ansible.builtin.template:
|
||||
src: hass.service.j2
|
||||
dest: /etc/systemd/system/hass.service
|
||||
mode: '644'
|
||||
notify: restart hass
|
||||
|
||||
- name: Install Python packages from requirements
|
||||
become: true
|
||||
become_user: "{{hass_user}}"
|
||||
ansible.builtin.pip:
|
||||
requirements: "{{hass_directory}}/requirements.txt"
|
||||
virtualenv: "{{hass_directory}}/env"
|
||||
virtualenv_python: python3.13
|
||||
vars:
|
||||
ansible_common_remote_group: "{{hass_group}}"
|
||||
allow_world_readable_tmpfiles: true
|
||||
notify: restart hass
|
||||
|
||||
- name: Reset SSH connection to apply group changes
|
||||
meta: reset_connection
|
||||
|
||||
- name: Enable and start Home Assistant service
|
||||
become: true
|
||||
ansible.builtin.systemd:
|
||||
name: hass
|
||||
enabled: true
|
||||
state: started
|
||||
daemon_reload: true
|
||||
|
||||
post_tasks:
|
||||
- name: Wait for Home Assistant to initialize
|
||||
ansible.builtin.pause:
|
||||
seconds: 30
|
||||
prompt: "Waiting for Home Assistant to initialize..."
|
||||
|
||||
- name: Check if Home Assistant is running
|
||||
ansible.builtin.uri:
|
||||
url: http://localhost:{{hass_port}}/
|
||||
method: GET
|
||||
status_code: 200
|
||||
timeout: 10
|
||||
register: hass_status
|
||||
ignore_errors: true
|
||||
|
||||
- name: Show Home Assistant status
|
||||
ansible.builtin.debug:
|
||||
msg: "Home Assistant is {{ 'running' if hass_status.status == 200 else 'not running properly' }}"
|
||||
|
||||
handlers:
|
||||
- name: restart hass
|
||||
become: true
|
||||
ansible.builtin.systemd:
|
||||
name: hass
|
||||
state: restarted
|
||||
daemon_reload: true
|
||||
Reference in New Issue
Block a user