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