-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.yml
More file actions
913 lines (898 loc) · 25.7 KB
/
setup.yml
File metadata and controls
913 lines (898 loc) · 25.7 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
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
- name: Setup Development Environment
hosts: all
gather_facts: true
vars:
os_family: '{{ ansible_os_family }}'
is_macos: '{{ ansible_os_family == ''Darwin'' }}'
is_linux: '{{ ansible_os_family != ''Darwin'' }}'
brewfile_path: "{{ playbook_dir }}/Brewfile"
tasks:
- name: Detect Homebrew installation path
ansible.builtin.command: which brew
register: brew_which_result
failed_when: false
changed_when: false
tags:
- always
- homebrew
- name: Set homebrew_prefix from detected path
ansible.builtin.set_fact:
homebrew_prefix: "{{ brew_which_result.stdout | dirname | dirname }}"
when: brew_which_result.rc == 0
tags:
- always
- homebrew
- name: Set homebrew_prefix to default if not found
ansible.builtin.set_fact:
homebrew_prefix: "{{ '/opt/homebrew' if is_macos else '/home/linuxbrew/.linuxbrew' }}"
when: brew_which_result.rc != 0
tags:
- always
- homebrew
- name: Display homebrew_prefix being used
ansible.builtin.debug:
msg: "Using Homebrew at: {{ homebrew_prefix }}"
tags:
- always
- homebrew
- name: Set user and home variables from environment
ansible.builtin.set_fact:
user: "{{ (lookup('env', 'USER') or lookup('env', 'LOGNAME') or 'root') | trim }}"
home: "{{ (lookup('env', 'HOME') or '/root') | trim }}"
tags:
- always
- name: Check if Brewfile exists
ansible.builtin.stat:
path: '{{ brewfile_path }}'
register: brewfile_check
tags:
- always
- homebrew
- packages
- name: Check if terraform is installed
ansible.builtin.command: '{{ homebrew_prefix }}/bin/brew list terraform'
register: terraform_check
failed_when: false
changed_when: false
when:
- brewfile_check.stat.exists
tags:
- homebrew
- packages
- name: Unlink terraform if tenv will be installed
ansible.builtin.shell: '{{ homebrew_prefix }}/bin/brew unlink terraform'
register: terraform_unlink
when:
- terraform_check.rc is defined
- terraform_check.rc == 0
- brewfile_check.stat.exists
failed_when: false
changed_when: |
terraform_unlink.rc is defined and terraform_unlink.rc == 0 and 'Unlinking' in terraform_unlink.stderr
tags:
- homebrew
- packages
- name: Install packages from Brewfile (if it exists)
ansible.builtin.shell: |
{{ homebrew_prefix }}/bin/brew bundle install \
--file={{ brewfile_path }} || true
args:
chdir: '{{ playbook_dir }}'
environment:
PATH: '{{ homebrew_prefix }}/bin:{{ ansible_env.PATH }}'
register: brew_bundle_result
when:
- ansible_os_family == "Darwin"
- brewfile_check.stat.exists
- install_gui_apps | default(true) or install_dev_tools | default(true)
changed_when: |
'Installing' in brew_bundle_result.stdout or
'Upgrading' in brew_bundle_result.stdout
failed_when: false
tags:
- homebrew
- packages
- name: Install essential packages with Homebrew (macOS fallback)
ansible.builtin.command: '{{ homebrew_prefix }}/bin/brew install {{ item }}'
loop:
- tmux
- neovim
- fzf
- ripgrep
- bat
when:
- ansible_os_family == "Darwin"
- install_dev_tools | default(true)
register: brew_install_result
changed_when: 'not "is already installed" in brew_install_result.stdout'
failed_when: false
tags:
- homebrew
- packages
- name: Install essential Linux packages (Debian/Ubuntu)
ansible.builtin.apt:
name:
- git
- curl
- wget
- vim
- zsh
- tree
- htop
- jq
- build-essential
- python3-pip
- nodejs
- npm
- golang-go
- postgresql
- sqlite3
- direnv
- shellcheck
state: present
update_cache: true
become: "{{ not (ansible_user_id == 'root') }}"
when:
- ansible_os_family == "Debian"
- install_dev_tools | default(true)
tags:
- linux
- packages
- name: Install optional packages from apt (best effort)
ansible.builtin.apt:
name:
- neovim
- tmux
- fzf
- ripgrep
- bat
- pipx
state: present
update_cache: false
become: "{{ not (ansible_user_id == 'root') }}"
register: apt_optional_result
failed_when: false
ignore_errors: true
when:
- ansible_os_family == "Debian"
- install_dev_tools | default(true)
tags:
- linux
- packages
- name: Install optional Linux tools via Homebrew (Linuxbrew fallback)
ansible.builtin.command: '{{ homebrew_prefix }}/bin/brew install {{ item }}'
loop:
- neovim
- tmux
- fzf
- ripgrep
- bat
when:
- ansible_os_family != "Darwin"
- install_dev_tools | default(true)
register: brew_linux_result
changed_when: 'not "is already installed" in brew_linux_result.stdout'
failed_when: false
tags:
- linux
- homebrew
- packages
- name: Install essential Linux packages (RedHat/Fedora)
ansible.builtin.dnf:
name:
- git
- curl
- wget
- vim
- zsh
- tree
- htop
- jq
- gcc
- gcc-c++
- make
- python3-pip
- nodejs
- npm
- golang
- postgresql
- sqlite
- direnv
- ShellCheck
state: present
become: "{{ not (ansible_user_id == 'root') }}"
register: dnf_result
failed_when: false
when:
- ansible_os_family == "RedHat"
- install_dev_tools | default(true)
tags:
- linux
- packages
- name: Install optional packages from dnf (best effort)
ansible.builtin.dnf:
name:
- neovim
- tmux
- fzf
- ripgrep
- bat
- pipx
state: present
become: "{{ not (ansible_user_id == 'root') }}"
register: dnf_optional_result
failed_when: false
ignore_errors: true
when:
- ansible_os_family == "RedHat"
- install_dev_tools | default(true)
tags:
- linux
- packages
- name: Install essential Linux packages (Arch Linux)
community.general.pacman:
name:
- git
- curl
- wget
- vim
- neovim
- tmux
- zsh
- fzf
- ripgrep
- bat
- tree
- htop
- jq
- base-devel
- python-pip
- python-pipx
- nodejs
- npm
- go
- postgresql
- sqlite
- direnv
- shellcheck
state: present
update_cache: yes
become: "{{ not (ansible_user_id == 'root') }}"
when:
- ansible_os_family == "Archlinux"
- install_dev_tools | default(true)
tags:
- linux
- packages
- name: Set ansible_user_dir for dotfiles role (container compatibility)
ansible.builtin.set_fact:
ansible_user_dir: "{{ home }}"
ansible_user_id: "{{ user }}"
tags:
- dotfiles
- configuration
- always
# NOTE: dotfiles role moved to run AFTER Oh My Zsh installation
# to prevent .zshrc from being overwritten by Oh My Zsh installer
- name: Include git role
ansible.builtin.include_role:
name: git
vars:
git_current_user: "{{ user }}"
git_home_dir: "{{ home }}"
git_repo_root: "{{ playbook_dir }}"
git_enable_precommit: true
tags:
- git
- configuration
- always
- name: Download mise installer
ansible.builtin.get_url:
url: https://mise.run
dest: /tmp/mise-installer.sh
mode: '0755'
when:
- ansible_os_family != "Darwin"
- install_dev_tools | default(true)
tags:
- mise
- dev-tools
- name: Install mise on Linux
ansible.builtin.shell: /tmp/mise-installer.sh
args:
creates: '{{ home }}/.local/bin/mise'
when:
- ansible_os_family != "Darwin"
- install_dev_tools | default(true)
tags:
- mise
- dev-tools
- name: Add mise to PATH for Linux
ansible.builtin.lineinfile:
path: '{{ home }}/.bashrc'
line: eval "$(~/.local/bin/mise activate bash)"
create: true
mode: '0644'
when:
- ansible_os_family != "Darwin"
- install_dev_tools | default(true)
tags:
- mise
- dev-tools
- name: Check if .mise.toml exists
ansible.builtin.stat:
path: '{{ playbook_dir }}/.mise.toml'
register: mise_toml_check
tags:
- always
- mise
- name: Set mise binary path
ansible.builtin.set_fact:
mise_bin: |
{{ homebrew_prefix ~ '/bin/mise' if ansible_os_family == 'Darwin'
else home ~ '/.local/bin/mise' }}
tags:
- always
- mise
- name: Check if mise binary exists
ansible.builtin.stat:
path: '{{ mise_bin }}'
register: mise_binary_check
tags:
- always
- mise
- name: Trust mise config file
ansible.builtin.command: '{{ mise_bin }} trust'
args:
chdir: '{{ playbook_dir }}'
register: mise_trust_result
when:
- mise_binary_check.stat.exists
- mise_toml_check.stat.exists
- install_dev_tools | default(true)
changed_when: |
mise_trust_result.rc == 0 and 'trusted' in mise_trust_result.stdout
failed_when: false
tags:
- mise
- dev-tools
- name: Install tool versions with mise
ansible.builtin.command: '{{ mise_bin }} install'
args:
chdir: '{{ playbook_dir }}'
register: mise_install_result
when:
- mise_binary_check.stat.exists
- mise_toml_check.stat.exists
- install_dev_tools | default(true)
changed_when: |
'installed' in mise_install_result.stdout or
'Installing' in mise_install_result.stdout
failed_when: false
retries: 3
delay: 5
until: mise_install_result is succeeded
tags:
- mise
- dev-tools
- name: Check Oh My Zsh installation
ansible.builtin.stat:
path: '{{ home }}/.oh-my-zsh/oh-my-zsh.sh'
register: ohmyzsh_check
tags:
- always
- shell
- name: Install Oh My Zsh
ansible.builtin.shell: |
curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh -o /tmp/install-oh-my-zsh.sh
env -u ZSH RUNZSH=no sh /tmp/install-oh-my-zsh.sh --unattended
register: ohmyzsh_install
when:
- not ohmyzsh_check.stat.exists
- install_shell_tools | default(true)
changed_when: ohmyzsh_install.rc == 0
retries: 3
delay: 5
until: ohmyzsh_install is succeeded
tags:
- shell
- name: Clone Powerlevel10k theme
ansible.builtin.git:
repo: https://github.com/romkatv/powerlevel10k.git
dest: '{{ home }}/.oh-my-zsh/custom/themes/powerlevel10k'
depth: 1
version: master
update: true
register: p10k_result
when: install_shell_tools | default(true)
retries: 3
delay: 5
until: p10k_result is succeeded
tags:
- shell
- name: Clone zsh plugins
ansible.builtin.git:
repo: '{{ item.repo }}'
dest: '{{ home }}/.oh-my-zsh/custom/plugins/{{ item.name }}'
version: master
update: true
loop: '{{ zsh_plugins }}'
register: zsh_plugins_result
when: install_shell_tools | default(true)
retries: 3
delay: 5
until: zsh_plugins_result is succeeded
tags:
- shell
- name: Check if fzf is installed
ansible.builtin.stat:
path: '{{ homebrew_prefix }}/opt/fzf/install'
register: fzf_check
when:
- ansible_os_family == "Darwin"
- install_shell_tools | default(true)
tags:
- always
- shell
- name: Install fzf key bindings and completion
ansible.builtin.shell: "{{ homebrew_prefix }}/opt/fzf/install --key-bindings --completion --no-update-rc"
args:
creates: '{{ home }}/.fzf.zsh'
when:
- ansible_os_family == "Darwin"
- install_shell_tools | default(true)
- fzf_check.stat.exists | default(false)
tags:
- shell
- name: Download dircolors (LS_COLORS)
ansible.builtin.get_url:
url: https://raw.githubusercontent.com/trapd00r/LS_COLORS/master/LS_COLORS
dest: '{{ home }}/.dircolors'
mode: '0644'
register: dircolors_result
when: install_shell_tools | default(true)
retries: 3
delay: 5
until: dircolors_result is succeeded
tags:
- shell
# ============================================================================
# Deploy dotfiles AFTER Oh My Zsh installation
# This ensures .zshrc with p10k configuration is not overwritten
# ============================================================================
- name: Check if dotfiles directory exists
ansible.builtin.stat:
path: "{{ playbook_dir }}/dotfiles"
register: dotfiles_dir_check
tags:
- dotfiles
- configuration
- always
- name: Include dotfiles role
ansible.builtin.include_role:
name: dotfiles
when: dotfiles_dir_check.stat.exists
tags:
- dotfiles
- configuration
- always
# NOTE: .inputrc and .direnvrc deployed by dotfiles role above
# These duplicate tasks removed to avoid overwriting permissions
- name: Enable direnv in zsh
ansible.builtin.lineinfile:
path: '{{ home }}/.zshrc'
line: eval "$(direnv hook zsh)"
state: present
create: true
mode: '0644'
when:
- install_dev_tools | default(true)
- ansible_os_family == "Darwin"
tags:
- shell
- direnv
- name: Configure passwordless sudo
ansible.builtin.copy:
content: '# Allow {{ user }} to use sudo with no password
{{ user }} ALL=(ALL) NOPASSWD: ALL
'
dest: /etc/sudoers.d/{{ user }}
mode: '0440'
validate: visudo -cf %s
become: "{{ not (ansible_user_id == 'root') }}"
when: configure_sudoers | default(false)
tags:
- sudoers
- name: Check if TPM (Tmux Plugin Manager) is installed
ansible.builtin.stat:
path: '{{ home }}/.tmux/plugins/tpm'
register: tpm_check
when: install_shell_tools | default(true)
tags:
- always
- tmux
- name: Clone TPM (Tmux Plugin Manager)
ansible.builtin.git:
repo: https://github.com/tmux-plugins/tpm
dest: '{{ home }}/.tmux/plugins/tpm'
depth: 1
version: master
update: true
register: tpm_result
when:
- install_shell_tools | default(true)
- not tpm_check.stat.exists
retries: 3
delay: 5
until: tpm_result is succeeded
tags:
- tmux
# NOTE: .tmux.conf is now deployed by the dotfiles role
# These duplicate tasks have been removed to avoid overwriting
# correct permissions
- name: Display tmux plugin installation instructions
ansible.builtin.debug:
msg:
- Tmux configuration installed!
- 'To install plugins, start tmux and press: Ctrl-a + I'
- (That's prefix key + capital I)
when:
- install_shell_tools | default(true)
- not tpm_check.stat.exists
tags:
- tmux
# NOTE: neovim config is now deployed by the dotfiles role
- name: Create vim symlinks to neovim (override system vim)
ansible.builtin.file:
src: |
{{ '/usr/bin/nvim' if ansible_os_family == 'Debian' else
homebrew_prefix ~ '/bin/nvim' }}
dest: /usr/local/bin/{{ item }}
state: link
force: true
loop:
- vim
- vi
when: install_neovim | default(true)
become: "{{ not (ansible_user_id == 'root') }}"
tags:
- neovim
- name: Check if VS Code is installed
ansible.builtin.command: which code
register: vscode_check
failed_when: false
changed_when: false
tags:
- always
- vscode
- name: Get currently installed VS Code extensions
ansible.builtin.command: code --list-extensions
register: installed_extensions
when:
- vscode_check.rc is defined
- vscode_check.rc == 0
- install_vscode | default(true)
changed_when: false
failed_when: false
tags:
- vscode
- name: Install VS Code extensions
ansible.builtin.command: code --install-extension {{ item }}
loop: '{{ vscode_extensions }}'
register: vscode_install
when:
- vscode_check.rc is defined
- vscode_check.rc == 0
- install_vscode | default(true)
- installed_extensions.stdout_lines is defined
- item not in installed_extensions.stdout_lines
changed_when: '''was successfully installed'' in vscode_install.stdout'
failed_when: false
tags:
- vscode
- name: Ensure VS Code User directory exists
ansible.builtin.file:
path: '{{ home }}/Library/Application Support/Code/User'
state: directory
mode: '0755'
when:
- vscode_check.rc is defined
- vscode_check.rc == 0
- install_vscode | default(true)
- is_macos
tags:
- vscode
- name: Ensure VS Code User directory exists (Linux)
ansible.builtin.file:
path: '{{ home }}/.config/Code/User'
state: directory
mode: '0755'
when:
- vscode_check.rc is defined
- vscode_check.rc == 0
- install_vscode | default(true)
- is_linux
tags:
- vscode
- name: Configure VS Code settings.json (macOS)
ansible.builtin.copy:
content: '{{ vscode_settings | to_nice_json }}'
dest: '{{ home }}/Library/Application Support/Code/User/settings.json'
mode: '0644'
backup: true
when:
- vscode_check.rc is defined
- vscode_check.rc == 0
- install_vscode | default(true)
- vscode_settings is defined
- is_macos
tags:
- vscode
- name: Configure VS Code settings.json (Linux)
ansible.builtin.copy:
content: '{{ vscode_settings | to_nice_json }}'
dest: '{{ home }}/.config/Code/User/settings.json'
mode: '0644'
backup: true
when:
- vscode_check.rc is defined
- vscode_check.rc == 0
- install_vscode | default(true)
- vscode_settings is defined
- is_linux
tags:
- vscode
- name: Check if Ghostty config directory exists
ansible.builtin.stat:
path: '{{ home }}/.config/ghostty'
register: ghostty_dir_check
tags:
- always
- ghostty
- name: Create Ghostty config directory
ansible.builtin.file:
path: '{{ home }}/.config/ghostty'
state: directory
mode: '0755'
when: install_shell_tools | default(true)
tags:
- ghostty
# NOTE: ghostty config is now deployed by the dotfiles role
- name: Check if chezmoi binary exists
ansible.builtin.stat:
path: '{{ homebrew_prefix }}/bin/chezmoi'
register: chezmoi_binary_check
when: configure_dotfiles | default(true)
tags:
- always
- dotfiles
- name: Check if chezmoi is initialized
ansible.builtin.stat:
path: '{{ home }}/.local/share/chezmoi'
register: chezmoi_check
when:
- configure_dotfiles | default(true)
- chezmoi_binary_check.stat.exists | default(false)
tags:
- always
- dotfiles
- name: Initialize chezmoi
ansible.builtin.command: '{{ homebrew_prefix }}/bin/chezmoi init'
register: chezmoi_init
when:
- configure_dotfiles | default(true)
- chezmoi_binary_check.stat.exists | default(false)
- chezmoi_check is not defined or not chezmoi_check.stat.exists
changed_when: chezmoi_init.rc == 0
tags:
- dotfiles
# NOTE: .zshrc is now deployed by the dotfiles role
# Chezmoi-specific tasks removed as they conflict with dotfiles
# role deployment
- name: macOS-specific tasks
when: is_macos
tags:
- macos
block:
- name: Install dockutil for Dock management
community.general.homebrew:
name: dockutil
state: present
when: configure_dock | default(true)
- name: Check if dockutil is available
ansible.builtin.command: which dockutil
register: dockutil_check
changed_when: false
failed_when: false
when: configure_dock | default(true)
- name: Configure Dock items
ansible.builtin.shell: >
{{ homebrew_prefix }}/bin/dockutil --remove 'Launchpad'
--no-restart 2>/dev/null || true &&
{{ homebrew_prefix }}/bin/dockutil --remove 'TV'
--no-restart 2>/dev/null || true &&
{{ homebrew_prefix }}/bin/dockutil --remove 'Podcasts'
--no-restart 2>/dev/null || true &&
{{ homebrew_prefix }}/bin/dockutil --remove 'App Store'
--no-restart 2>/dev/null || true &&
({{ homebrew_prefix }}/bin/dockutil --find 'Messages' ||
{{ homebrew_prefix }}/bin/dockutil --add
'/System/Applications/Messages.app' --no-restart 2>/dev/null
|| true) &&
({{ homebrew_prefix }}/bin/dockutil --find 'Safari' ||
{{ homebrew_prefix }}/bin/dockutil --add
'/Applications/Safari.app' --position 2 --no-restart
2>/dev/null || true) &&
({{ homebrew_prefix }}/bin/dockutil --find 'iTerm' ||
{{ homebrew_prefix }}/bin/dockutil --add
'/Applications/iTerm.app' --position 3 --no-restart
2>/dev/null || true) &&
({{ homebrew_prefix }}/bin/dockutil --find 'Google Chrome' ||
{{ homebrew_prefix }}/bin/dockutil --add
'/Applications/Google Chrome.app' --position 4
--no-restart 2>/dev/null || true) &&
({{ homebrew_prefix }}/bin/dockutil --find
'Visual Studio Code' ||
{{ homebrew_prefix }}/bin/dockutil --add
'/Applications/Visual Studio Code.app' --position 5
--no-restart 2>/dev/null || true) &&
({{ homebrew_prefix }}/bin/dockutil --find 'Slack' ||
{{ homebrew_prefix }}/bin/dockutil --add
'/Applications/Slack.app' --position 6 --no-restart
2>/dev/null || true)
register: dock_config
when:
- configure_dock | default(true)
- dockutil_check.rc is defined
- dockutil_check.rc == 0
changed_when: false
failed_when: false
- name: Restart Dock
ansible.builtin.command: killall Dock
when: dock_config is changed
changed_when: false
failed_when: false
- name: Configure macOS defaults
community.general.osx_defaults:
domain: '{{ item.domain }}'
key: '{{ item.key }}'
type: '{{ item.type }}'
value: '{{ item.value }}'
state: present
loop:
- domain: com.apple.dock
key: autohide
type: bool
value: true
- domain: com.apple.dock
key: show-recents
type: bool
value: false
- domain: com.apple.dock
key: tilesize
type: int
value: 48
- domain: com.apple.dock
key: minimize-to-application
type: bool
value: true
- domain: NSGlobalDomain
key: AppleShowAllExtensions
type: bool
value: true
- domain: com.apple.finder
key: ShowPathbar
type: bool
value: true
- domain: com.apple.finder
key: ShowStatusBar
type: bool
value: true
- domain: com.apple.finder
key: FXPreferredViewStyle
type: string
value: Nlsv
- domain: com.apple.finder
key: FXDefaultSearchScope
type: string
value: SCcf
- domain: com.apple.finder
key: _FXShowPosixPathInTitle
type: bool
value: true
- domain: NSGlobalDomain
key: KeyRepeat
type: int
value: 2
- domain: NSGlobalDomain
key: InitialKeyRepeat
type: int
value: 15
- domain: com.apple.screencapture
key: location
type: string
value: ~/Desktop
- domain: com.apple.screencapture
key: type
type: string
value: png
- domain: com.apple.screencapture
key: disable-shadow
type: bool
value: true
- domain: NSGlobalDomain
key: NSAutomaticWindowAnimationsEnabled
type: bool
value: false
- domain: NSGlobalDomain
key: NSNavPanelExpandedStateForSaveMode
type: bool
value: true
when: configure_macos_defaults | default(true)
notify: restart_dock
- name: Check if tmux is installed
ansible.builtin.command: which tmux
register: tmux_check
changed_when: false
failed_when: false
tags:
- always
- name: Generate setup report
ansible.builtin.set_fact:
setup_report:
hostname: '{{ ansible_hostname }}'
os: |
{{ ansible_distribution | default('Unknown') }}
{{ ansible_distribution_version | default('') }}
homebrew_installed: '{{ homebrew_check.stat.exists }}'
packages_updated: |
{{ brew_bundle_result is defined and
brew_bundle_result is changed }}
mise_updated: |
{{ mise_install_result is defined and
mise_install_result is changed }}
shell_configured: '{{ ohmyzsh_check.stat.exists }}'
tmux_configured: '{{ tmux_check is defined and tmux_check.rc == 0 }}'
neovim_configured: '{{ install_neovim | default(true) }}'
vscode_configured: |
{{ vscode_check is defined and vscode_check.rc == 0 }}
tags:
- always
- name: Display setup report
ansible.builtin.debug:
msg:
- ==========================================
- Setup Report for {{ ansible_hostname }}
- ==========================================
- 'OS: {{ setup_report.os }}'
- |
Homebrew: {{ 'Installed' if setup_report.homebrew_installed else 'Not
Installed' }}
- |
Packages Updated: {{ 'Yes' if setup_report.packages_updated else 'No' }}
- |
mise Updated: {{ 'Yes' if setup_report.mise_updated else 'No' }}
- |
Shell Configured: {{ 'Yes' if setup_report.shell_configured else 'No' }}
- |
Tmux Configured: {{ 'Yes' if setup_report.tmux_configured else 'No' }}
- |
Neovim Configured: {{ 'Yes'
if setup_report.neovim_configured else 'No' }}
- |
VS Code Configured: {{ 'Yes'
if setup_report.vscode_configured else 'No' }}
- ''
- 'Next steps:'
- ' 1. Restart terminal: source ~/.zshrc'
- ' 2. Configure Powerlevel10k: p10k configure'
- ' 3. Open Neovim: nvim (or vim/vi aliases)'
- ' 4. Start tmux: tmux (Prefix is C-a)'
tags:
- always
handlers:
- name: restart_dock
ansible.builtin.command: killall Dock
failed_when: false
changed_when: false
when: is_macos