/
/
/
This repo is destined for my server automations and setup.
1---
2# ============================================================================
3# Home Assistant Supervised Complete Installation Playbook
4# ============================================================================
5#
6#
7# PREREQUISITES:
8# - Fresh Debian 11 or 12 installation
9# - SSH access with sudo privileges for ansible_user
10# - Internet connectivity for package downloads
11# - Static IP address recommended
12#
13# ============================================================================
14
15- name: "Complete Home Assistant Supervised Setup"
16 hosts: homeassistant_servers
17 become: true
18 gather_facts: true
19
20 pre_tasks:
21 - name: Display deployment information
22 debug:
23 msg: |
24 ============================================================================
25 Home Assistant Supervised Installation Starting
26 ============================================================================
27 Target Host: {{ inventory_hostname }}
28 Target IP: {{ ansible_default_ipv4.address }}
29 OS: {{ ansible_distribution }} {{ ansible_distribution_version }}
30 Architecture: {{ ansible_architecture }}
31 User: {{ homeassistant_user }}
32 ============================================================================
33 tags: always
34
35 - name: Validate system requirements
36 assert:
37 that:
38 - ansible_distribution == "Debian"
39 - ansible_distribution_major_version | int >= 11
40 - ansible_memtotal_mb >= 1500 # Minimum 1.5GB RAM
41 - ansible_processor_vcpus >= 2 # Minimum 2 CPU cores
42 fail_msg: |
43 System requirements not met:
44 - Requires Debian 11 or 12
45 - Minimum 1.5GB RAM (found {{ ansible_memtotal_mb }}MB)
46 - Minimum 2 CPU cores (found {{ ansible_processor_vcpus }})
47 success_msg: "System requirements validated successfully"
48 tags: always
49
50 - name: Verify server is in homeassistant_servers group
51 fail:
52 msg: "This server must be in the [homeassistant_servers] inventory group. Check your inventory/hosts file."
53 when: "'homeassistant_servers' not in group_names"
54 tags: always
55
56 # ============================================================================
57 # ROLE EXECUTION ORDER (CRITICAL FOR PROPER INSTALLATION)
58 # ============================================================================
59
60 roles:
61 # 1. USER MANAGEMENT - Create homeassistant user with proper groups
62 - role: user
63 tags: [user, setup]
64
65 # 2. SYSTEM SETUP - Basic system configuration and packages
66 - role: system
67 tags: [system, setup]
68
69 # 3. DOCKER INSTALLATION - Install Docker using geerlingguy.docker
70 - role: geerlingguy.docker
71 tags: [docker, setup]
72
73 # 4. SECURITY HARDENING - Apply security settings
74 - role: geerlingguy.security
75 tags: [security, hardening]
76
77 # 5. HOME ASSISTANT SUPERVISED - Complete installation (Docker required)
78 - role: homeassistant
79 tags: [homeassistant, ha]
80
81 # ============================================================================
82 # POST-INSTALLATION TASKS
83 # ============================================================================
84
85 post_tasks:
86 - name: Check if network transition is pending
87 stat:
88 path: /etc/systemd/system/ha-network-transition.service
89 register: network_transition_pending
90
91 - name: Display network transition requirement
92 debug:
93 msg: |
94 â ï¸ NETWORK TRANSITION PENDING â ï¸
95
96 A reboot is required to complete the NetworkManager transition.
97 The transition script is ready at: /usr/local/bin/ha-network-transition.sh
98
99 After Home Assistant installation completes:
100 1. Reboot the server: sudo reboot
101 2. Check transition log: cat /var/log/ha-network-transition.log
102 3. Verify NetworkManager: systemctl status NetworkManager
103 when: network_transition_pending.stat.exists
104
105 - name: Wait for Home Assistant to become available
106 uri:
107 url: "http://{{ ansible_default_ipv4.address }}:8123"
108 method: GET
109 status_code: 200
110 timeout: 10
111 register: ha_check
112 until: ha_check.status == 200
113 retries: 30
114 delay: 10
115 ignore_errors: yes
116 tags: [homeassistant, validation]
117
118 - name: Display installation summary
119 debug:
120 msg: |
121 ============================================================================
122 Home Assistant Supervised Installation Complete!
123 ============================================================================
124
125 ð Home Assistant Access:
126 Web Interface: http://{{ ansible_default_ipv4.address }}:8123
127 SSH Access: ssh {{ homeassistant_user }}@{{ ansible_default_ipv4.address }}
128
129 ð System Information:
130 Host: {{ inventory_hostname }}
131 OS: {{ ansible_distribution }} {{ ansible_distribution_version }}
132 Architecture: {{ homeassistant_machine_type }}
133 User: {{ homeassistant_user }}
134 Docker Version: {{ docker_version.stdout | default('Unknown') }}
135
136 ð§ Services Status:
137 - Home Assistant Supervisor: {{ 'Running' if ha_check.status == 200 else 'Starting (may take 5-10 minutes)' }}
138 - Docker: Running
139 - OS Agent: Installed
140 - NetworkManager: Configured
141
142 ð Next Steps:
143 1. Open http://{{ ansible_default_ipv4.address }}:8123 in your browser
144 2. Complete Home Assistant onboarding process
145 3. Install HACS (Home Assistant Community Store)
146 4. Configure integrations and add-ons
147 5. Set up backups and monitoring
148
149 ð¡ Useful Commands:
150 - Check supervisor status: sudo systemctl status hassio-supervisor
151 - View supervisor logs: sudo journalctl -fu hassio-supervisor
152 - Restart supervisor: sudo systemctl restart hassio-supervisor
153 - Docker containers: docker ps
154
155 â ï¸ Important Notes:
156 - Initial startup may take 5-10 minutes
157 - Create backups before major updates
158 - Monitor system resources (RAM usage can grow over time)
159 - Use SSH access for system maintenance
160
161 ============================================================================
162 tags: always
163
164 - name: Save installation details to file
165 copy:
166 content: |
167 Home Assistant Supervised Installation Details
168 =============================================
169
170 Installation Date: {{ ansible_date_time.iso8601 }}
171 Host: {{ inventory_hostname }}
172 IP Address: {{ ansible_default_ipv4.address }}
173 OS: {{ ansible_distribution }} {{ ansible_distribution_version }}
174 Architecture: {{ ansible_architecture }}
175 Machine Type: {{ homeassistant_machine_type }}
176
177 User Configuration:
178 - Username: {{ homeassistant_user }}
179 - Groups: {{ homeassistant_user_groups | join(', ') }}
180 - Sudo Access: Passwordless
181
182 Home Assistant:
183 - Web Interface: http://{{ ansible_default_ipv4.address }}:8123
184 - Data Directory: {{ homeassistant_data_share | default('/usr/share/hassio') }}
185 - Supervisor Status: {{ 'Running' if ha_check.status == 200 else 'Starting' }}
186
187 Docker Configuration:
188 - Compose Installed: {{ docker_install_compose }}
189 - Users with Access: {{ docker_users | join(', ') }}
190 - Log Rotation: 50MB max, 3 files
191
192 Security:
193 - SSH Port: {{ security_ssh_port }}
194 - Root Login: Disabled
195 - Password Authentication: Disabled
196 - Fail2ban: {{ security_fail2ban_enabled | default('Enabled') }}
197 - Auto Updates: {{ security_autoupdate_enabled }}
198
199 Useful Commands:
200 - Check HA status: sudo systemctl status hassio-supervisor
201 - View HA logs: sudo journalctl -fu hassio-supervisor
202 - Docker containers: docker ps
203 - System resources: htop
204
205 dest: "/home/{{ homeassistant_user }}/homeassistant-installation-details.txt"
206 owner: "{{ homeassistant_user }}"
207 group: "{{ homeassistant_user }}"
208 mode: "0644"
209 tags: [homeassistant, documentation]
210