-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsite.yml
More file actions
522 lines (442 loc) · 18.4 KB
/
site.yml
File metadata and controls
522 lines (442 loc) · 18.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
---
# Main site playbook - Comprehensive cross-platform system configuration
# This playbook orchestrates the complete setup of workstations and servers
- name: Pre-Flight Validation and Setup
hosts: all
gather_facts: yes
become: no
vars:
ansible_python_interpreter: "{{ ansible_playbook_python }}"
dotsible_version: "2.0.0"
execution_timestamp: "{{ ansible_date_time.iso8601 }}"
dry_run_mode: "{{ ansible_check_mode | default(false) }}"
pre_tasks:
- name: Display execution banner
debug:
msg: |
╔══════════════════════════════════════════════════════════════╗
║ DOTSIBLE v{{ dotsible_version }} ║
║ Cross-Platform Configuration Management ║
╚══════════════════════════════════════════════════════════════╝
🖥️ Host: {{ inventory_hostname }}
🐧 OS: {{ ansible_distribution }} {{ ansible_distribution_version }}
🏗️ Architecture: {{ ansible_architecture }}
👤 Profile: {{ profile | default('minimal') }}
🐍 Python: {{ ansible_python_version }}
⏰ Timestamp: {{ execution_timestamp }}
🧪 Dry Run: {{ dry_run_mode }}
{{ '🔍 DRY RUN MODE - No changes will be made' if dry_run_mode else '🚀 LIVE EXECUTION - Changes will be applied' }}
tags: ['always']
- name: Validate system requirements
block:
- name: Check Python version compatibility
assert:
that:
- ansible_python_version is version('3.8', '>=')
fail_msg: |
Python version {{ ansible_python_version }} is not supported.
Minimum required version: 3.8
Target version: {{ python_version_management.target_version }}
Python will be upgraded automatically in the next step.
success_msg: "Python version {{ ansible_python_version }} is compatible"
- name: Check available disk space
assert:
that:
- ansible_mounts | selectattr('mount', 'equalto', '/') | map(attribute='size_available') | first > 1073741824
fail_msg: |
Insufficient disk space available.
At least 1GB of free space is required.
Current available: {{ (ansible_mounts | selectattr('mount', 'equalto', '/') | map(attribute='size_available') | first / 1024 / 1024 / 1024) | round(2) }}GB
success_msg: "Sufficient disk space available"
when: ansible_mounts is defined
- name: Validate profile compatibility
assert:
that:
- profile_compatibility[profile | default('minimal')][ansible_distribution | lower] | default(true)
fail_msg: |
Profile '{{ profile | default('minimal') }}' is not compatible with {{ ansible_distribution }}.
Supported profiles for {{ ansible_distribution }}:
{{ profile_compatibility | dict2items | selectattr('value.' + (ansible_distribution | lower), 'defined') | selectattr('value.' + (ansible_distribution | lower)) | map(attribute='key') | list | join(', ') }}
success_msg: "Profile '{{ profile | default('minimal') }}' is compatible with {{ ansible_distribution }}"
when: profile_compatibility is defined
- name: Check network connectivity
uri:
url: https://www.google.com
method: HEAD
timeout: 10
register: network_check
failed_when: false
changed_when: false
- name: Warn about network connectivity
debug:
msg: |
⚠️ WARNING: Network connectivity check failed.
Some packages may not install correctly.
Error: {{ network_check.msg | default('Unknown network error') }}
when: network_check.status is defined and network_check.status != 200
rescue:
- name: Handle validation failures
fail:
msg: |
❌ Pre-flight validation failed!
Please resolve the above issues before continuing.
For help, see:
- docs/TROUBLESHOOTING.md
- Run: ./scripts/validate.sh
- Run: ./scripts/bootstrap.sh (if dependencies are missing)
tags: ['always', 'validation']
- name: Create system runtime directories
file:
path: /var/log/ansible
state: directory
mode: '0755'
become: yes
when: ansible_os_family != "Windows"
ignore_errors: yes # Don't fail if we can't create system directories
tags: ['always']
- name: Create user runtime directories
file:
path: "{{ item }}"
state: directory
mode: '0755'
loop:
- "{{ ansible_env.HOME }}/.dotsible"
- "{{ ansible_env.HOME }}/.dotsible/backups"
- "{{ ansible_env.HOME }}/.dotsible/logs"
when: ansible_os_family != "Windows"
tags: ['always']
- name: Initialize execution log
copy:
content: |
Dotsible Execution Log
=====================
Execution ID: {{ execution_timestamp }}
Host: {{ inventory_hostname }}
OS: {{ ansible_distribution }} {{ ansible_distribution_version }}
Profile: {{ profile | default('minimal') }}
Dry Run: {{ dry_run_mode }}
Started: {{ ansible_date_time.iso8601 }}
dest: "{{ ansible_env.HOME }}/.dotsible/logs/execution_{{ execution_timestamp | regex_replace('[^0-9]', '') }}.log"
mode: '0644'
tags: ['always']
- name: Bootstrap System
hosts: all
gather_facts: no
become: yes
vars:
ansible_python_interpreter: "{{ ansible_playbook_python }}"
pre_tasks:
- name: Bootstrap phase banner
debug:
msg: |
🔧 BOOTSTRAP PHASE
==================
Installing essential packages and configuring package managers...
tags: ['always']
- name: Create backup before bootstrap (if enabled)
command: "{{ playbook_dir }}/scripts/backup.sh --dotfiles-only"
delegate_to: localhost
run_once: true
when:
- backup_before_run | default(false)
- not ansible_check_mode
tags: ['backup']
roles:
- role: common
tags: ['common', 'bootstrap']
# Platform-specific setup
- role: platform_specific/macos
when: ansible_os_family == "Darwin"
tags: ['platform', 'macos']
- role: platform_specific/windows
when: ansible_os_family == "Windows"
tags: ['platform', 'windows']
- role: platform_specific/archlinux
when: ansible_distribution == "Archlinux"
tags: ['platform', 'archlinux']
- role: platform_specific/ubuntu
when: ansible_os_family == "Debian"
tags: ['platform', 'ubuntu']
post_tasks:
- name: Verify bootstrap completion
block:
- name: Check package manager functionality
package:
name: curl
state: present
register: package_test
failed_when: false
changed_when: false
- name: Bootstrap verification
assert:
that:
- package_test is not failed
fail_msg: |
❌ Bootstrap verification failed!
Package manager is not functioning correctly.
Please check the bootstrap logs and try again.
success_msg: "✅ Bootstrap completed successfully"
- name: Log bootstrap completion
copy:
content: |
Bootstrap Phase Completed
========================
Timestamp: {{ ansible_date_time.iso8601 }}
Host: {{ inventory_hostname }}
OS: {{ ansible_distribution }} {{ ansible_distribution_version }}
Profile: {{ profile | default('minimal') }}
Package Manager: {{ package_manager | default('auto-detected') }}
Status: SUCCESS
dest: "{{ ansible_env.HOME }}/.dotsible/logs/bootstrap.log"
mode: '0644'
become: no
when: ansible_os_family != "Windows"
rescue:
- name: Handle bootstrap failure
fail:
msg: |
❌ Bootstrap phase failed!
This is a critical error that prevents further execution.
Please check:
1. Internet connectivity
2. Package manager configuration
3. System permissions
For troubleshooting, see docs/TROUBLESHOOTING.md
tags: ['always']
- name: Python Version Management
hosts: all
gather_facts: no
become: no
vars:
ansible_python_interpreter: "{{ ansible_playbook_python }}"
pre_tasks:
- name: Python management phase banner
debug:
msg: |
🐍 PYTHON VERSION MANAGEMENT
============================
Target Python version: {{ python_version_management.target_version }}
Current Python version: {{ dotsible_python_version | default('Unknown') }}
Upgrade needed: {{ 'YES' if dotsible_python_needs_upgrade | default(true) else 'NO' }}
tags: ['always']
roles:
- role: python_management
tags: ['python', 'python_management']
when: python_version_management.auto_upgrade | default(true)
post_tasks:
- name: Python management completion
debug:
msg: |
🐍 Python Version Management Complete
====================================
• Python version: {{ detected_python_version | default('Unknown') }}
• pip available: {{ 'YES' if detected_pip_version is defined else 'NO' }}
• pipx available: {{ 'YES' if pipx_available | default(false) else 'NO' }}
{% if python_packages_backup is defined %}
• Package backup: {{ python_packages_backup.backup_path }}
{% endif %}
tags: ['always']
- name: Configure Applications
hosts: all
gather_facts: no
become: no
pre_tasks:
- name: Applications phase banner
debug:
msg: |
📱 APPLICATIONS PHASE
====================
Installing and configuring applications for profile: {{ profile | default('minimal') }}
Applications: {{ profiles[profile | default('minimal')].applications | default([]) | join(', ') }}
tags: ['always']
- name: Validate application requirements
block:
- name: Check if applications are defined for profile
assert:
that:
- profiles[profile | default('minimal')].applications is defined
- profiles[profile | default('minimal')].applications | length > 0
fail_msg: |
No applications defined for profile '{{ profile | default('minimal') }}'.
Please check your profile configuration in group_vars/all/profiles.yml
success_msg: "Applications defined for profile '{{ profile | default('minimal') }}'"
- name: Display application installation plan
debug:
msg: |
📋 Application Installation Plan:
{% for app in profiles[profile | default('minimal')].applications %}
- {{ app }}
{% endfor %}
when: not ansible_check_mode
rescue:
- name: Handle application validation failure
debug:
msg: |
⚠️ Application validation failed, but continuing with available applications.
Some applications may not be installed.
tags: ['always']
roles:
- role: applications/fonts
tags: ['applications', 'fonts']
when: profile in ['minimal', 'developer', 'enterprise']
- role: applications/zoxide
tags: ['applications', 'zoxide', 'cli-tools']
when: profile in ['minimal', 'developer', 'enterprise']
# FZF must be installed before shell configurations that depend on it
- role: applications/fzf
tags: ['applications', 'fzf']
when: "'fzf' in profiles[profile | default('minimal')].applications | default([])"
- role: applications/zsh
tags: ['applications', 'zsh']
when: "'zsh' in profiles[profile | default('minimal')].applications | default([])"
- role: applications/tmux
tags: ['applications', 'tmux']
when: "'tmux' in profiles[profile | default('minimal')].applications | default([])"
- role: applications/alacritty
tags: ['applications', 'alacritty']
when: "'alacritty' in profiles[profile | default('minimal')].applications | default([])"
- role: applications/starship
tags: ['applications', 'starship']
when: "'starship' in profiles[profile | default('minimal')].applications | default([])"
# Window manager specific configurations (Linux only)
- role: applications/i3
tags: ['applications', 'i3', 'window-manager']
when:
- dotsible_window_manager is defined
- dotsible_window_manager == "i3"
- "'i3' in profiles[profile | default('minimal')].applications | default([])"
- role: applications/hyprland
tags: ['applications', 'hyprland', 'window-manager']
when:
- dotsible_window_manager is defined
- dotsible_window_manager == "hyprland"
- "'hyprland' in profiles[profile | default('minimal')].applications | default([])"
- role: applications/sway
tags: ['applications', 'sway', 'window-manager']
when:
- dotsible_window_manager is defined
- dotsible_window_manager == "sway"
- "'sway' in profiles[profile | default('minimal')].applications | default([])"
# macOS Enterprise Management
- role: macos_enterprise
tags: ['macos_enterprise', 'enterprise', 'mdm', 'desktop', 'macos']
when: ansible_os_family == "Darwin"
post_tasks:
- name: Verify application installations
block:
- name: Test installed applications
command: "{{ item.command }}"
loop: "{{ application_verification | default([]) }}"
register: app_verification_results
failed_when: false
changed_when: false
when: item.name in profiles[profile | default('minimal')].applications | default([])
- name: Log application configuration completion
copy:
content: |
Application Configuration Completed
==================================
Timestamp: {{ ansible_date_time.iso8601 }}
Host: {{ inventory_hostname }}
Profile: {{ profile | default('minimal') }}
Applications: {{ profiles[profile | default('minimal')].applications | default([]) | join(', ') }}
Verification Results:
{% for result in app_verification_results.results | default([]) %}
- {{ result.item.name }}: {{ 'SUCCESS' if result.rc == 0 else 'FAILED' }}
{% endfor %}
dest: "{{ ansible_env.HOME }}/.dotsible/logs/applications.log"
mode: '0644'
become: no
when: ansible_os_family != "Windows"
rescue:
- name: Handle application verification failure
debug:
msg: |
⚠️ Some application verifications failed.
Applications may still be functional.
Check the application logs for details.
tags: ['always']
- name: Apply Profile Configuration
hosts: all
gather_facts: no
become: no
roles:
- role: profiles/developer
tags: ['profiles', 'developer']
when: profile == "developer"
# Environment-specific configurations
- role: profiles/enterprise
tags: ['profiles', 'enterprise']
when:
- profile is defined
- profile == "enterprise" or environment_type == "enterprise"
- role: dotfiles
tags: ['dotfiles', 'configuration', 'conditional']
when: dotfiles_enabled | default(true)
post_tasks:
- name: Create profile summary
template:
src: profile_summary.j2
dest: "{{ ansible_env.HOME }}/.ansible_profile_summary"
mode: '0644'
vars:
profile_name: "{{ profile | default('minimal') }}"
profile_config: "{{ profiles[profile | default('minimal')] }}"
installation_date: "{{ ansible_date_time.iso8601 }}"
tags: ['always']
- name: Display completion message
debug:
msg: |
========================================
Configuration Complete!
========================================
Host: {{ inventory_hostname }}
Profile: {{ profile | default('minimal') }}
Applications: {{ profiles[profile | default('minimal')].applications | join(', ') }}
Features: {{ profiles[profile | default('minimal')].features | join(', ') }}
Summary saved to: ~/.ansible_profile_summary
Logs available in: ~/.dotsible/logs/
You may need to restart your shell or reboot to apply all changes.
tags: ['always']
- name: Verification and Cleanup
hosts: all
gather_facts: no
become: no
tasks:
- name: Verify critical applications
command: "{{ item.command }}"
loop: "{{ application_verification | default([]) }}"
register: verification_results
failed_when: false
changed_when: false
tags: ['verify']
- name: Create verification report
template:
src: verification_report.j2
dest: "{{ ansible_env.HOME }}/.ansible_verification_report"
mode: '0644'
vars:
verification_results: "{{ verification_results }}"
when: verification_results is defined
tags: ['verify']
- name: Cleanup temporary files
file:
path: "{{ item }}"
state: absent
loop:
- /tmp/ansible_temp
- /tmp/install_oh_my_zsh.sh
- /tmp/homebrew_install.sh
when: cleanup_temp_files | default(true)
tags: ['cleanup']
- name: Final system status
debug:
msg: |
System configuration completed successfully!
Profile: {{ profile | default('minimal') }}
Verification report: ~/.ansible_verification_report
Next steps:
1. Restart your shell: exec $SHELL
2. Review configuration: cat ~/.ansible_profile_summary
3. Check logs: ls -la ~/.dotsible/logs/
tags: ['always']