/
/
/
1- name: Install required system packages for dotfiles
2 package:
3 name:
4 - git
5 - unzip
6 - curl
7 - wget
8 - fontconfig
9 - build-essential
10 - perl
11 state: present
12 become: true
13
14- name: Create dotfile parent directory structure
15 ansible.builtin.file:
16 path: "{{ dotfiles_dest | dirname }}"
17 state: directory
18 mode: '0755'
19 owner: "{{ my_user_username }}"
20 group: "{{ my_user_primary_group }}"
21 become: true
22
23- name: Clone or update dotfiles repo
24 git:
25 repo: "{{ dotfiles_repo }}"
26 dest: "{{ dotfiles_dest }}"
27 version: "{{ dotfiles_version }}"
28 update: yes
29 accept_hostkey: yes
30 become: true
31 become_user: "{{ my_user_username }}"
32
33- name: Make dotfiles installer executable
34 ansible.builtin.file:
35 path: "{{ dotfiles_run_from }}/{{ dotfiles_install_cmd }}"
36 mode: '0755'
37 become: true
38 become_user: "{{ my_user_username }}"
39
40- name: Check if dotfiles are already installed (idempotency check)
41 stat:
42 path: "/home/{{ my_user_username }}/.zshrc"
43 register: dotfiles_installed
44
45- name: Run dotfiles installer
46 args:
47 chdir: "{{ dotfiles_run_from }}"
48 shell: "timeout 1800 {{ dotfiles_install_cmd }}" # 30 minute timeout
49 become: true
50 become_user: "{{ my_user_username }}"
51 environment:
52 HOME: "/home/{{ my_user_username }}"
53 PATH: "/home/{{ my_user_username }}/.local/bin:/home/{{ my_user_username }}/.cargo/bin:{{ ansible_env.PATH }}"
54 USER: "{{ my_user_username }}"
55 CARGO_HOME: "/home/{{ my_user_username }}/.cargo"
56 RUSTUP_HOME: "/home/{{ my_user_username }}/.rustup"
57 DEBIAN_FRONTEND: noninteractive # Prevent interactive prompts
58 FORCE_UNSAFE_CONFIGURE: 1 # Skip some safety checks that may prompt
59 when: not dotfiles_installed.stat.exists or dotfiles_force_reinstall | default(false)
60 register: dotfiles_result
61 failed_when: dotfiles_result.rc != 0 and dotfiles_result.rc != 130 and dotfiles_result.rc != 124 # Allow Ctrl+C and timeout exits
62 ignore_errors: yes
63 async: 2000 # Allow up to 33+ minutes total
64 poll: 30 # Check every 30 seconds
65
66- name: Display dotfiles installation result
67 debug:
68 msg: |
69 {% if dotfiles_result.rc == 0 %}
70 â
Dotfiles installation completed successfully
71 {% elif dotfiles_result.rc == 124 %}
72 â±ï¸ Dotfiles installation timed out after 30 minutes
73 The installation may still be running in the background.
74 Check manually: ps aux | grep setup_dot
75 {% elif dotfiles_result.rc == 130 %}
76 â ï¸ Dotfiles installation was interrupted (Ctrl+C)
77 {% elif dotfiles_installed.stat.exists and not (dotfiles_force_reinstall | default(false)) %}
78 â¹ï¸ Dotfiles installation skipped - already installed (.zshrc exists)
79 Use -e dotfiles_force_reinstall=true to reinstall
80 {% else %}
81 â Dotfiles installation encountered issues (exit code: {{ dotfiles_result.rc }})
82 {% endif %}
83
84 {% if dotfiles_result.stdout is defined and dotfiles_result.stdout | length > 0 %}
85 Output: {{ dotfiles_result.stdout }}
86 {% endif %}
87 {% if dotfiles_result.stderr is defined and dotfiles_result.stderr | length > 0 %}
88 Errors: {{ dotfiles_result.stderr }}
89 {% endif %}
90 when: dotfiles_result is defined
91
92