82 lines
2.2 KiB
YAML
82 lines
2.2 KiB
YAML
---
|
|
# Phase 2: Install Chezmoi and apply dotfiles from Gitea repo.
|
|
|
|
- name: Check if Chezmoi is already installed
|
|
ansible.builtin.command: chezmoi --version
|
|
register: cli_modern_chezmoi_check
|
|
changed_when: false
|
|
failed_when: false
|
|
|
|
# --- Install Chezmoi (Arch) ---
|
|
|
|
- name: Install Chezmoi via pacman
|
|
become: true
|
|
community.general.pacman:
|
|
name: chezmoi
|
|
state: present
|
|
when:
|
|
- cli_modern_chezmoi_check.rc != 0
|
|
- ansible_os_family == "Archlinux"
|
|
|
|
# --- Install Chezmoi (Debian/Ubuntu) ---
|
|
|
|
- name: Download Chezmoi install script
|
|
ansible.builtin.get_url:
|
|
url: https://get.chezmoi.io
|
|
dest: /tmp/chezmoi-install.sh
|
|
mode: "0755"
|
|
when:
|
|
- cli_modern_chezmoi_check.rc != 0
|
|
- ansible_os_family == "Debian"
|
|
|
|
- name: Install Chezmoi via official installer
|
|
become: true
|
|
ansible.builtin.command: /tmp/chezmoi-install.sh -b /usr/local/bin
|
|
args:
|
|
creates: /usr/local/bin/chezmoi
|
|
when:
|
|
- cli_modern_chezmoi_check.rc != 0
|
|
- ansible_os_family == "Debian"
|
|
|
|
- name: Clean up Chezmoi installer
|
|
ansible.builtin.file:
|
|
path: /tmp/chezmoi-install.sh
|
|
state: absent
|
|
when:
|
|
- cli_modern_chezmoi_check.rc != 0
|
|
- ansible_os_family == "Debian"
|
|
|
|
# --- Initialize and apply dotfiles ---
|
|
|
|
- name: Check if Chezmoi is already initialized
|
|
ansible.builtin.stat:
|
|
path: "{{ cli_modern_user_home }}/.local/share/chezmoi"
|
|
register: cli_modern_chezmoi_dir
|
|
|
|
- name: Initialize Chezmoi from dotfiles repo
|
|
become: true
|
|
become_user: "{{ cli_modern_user }}"
|
|
ansible.builtin.command: >
|
|
chezmoi init {{ cli_modern_chezmoi_repo }}
|
|
--promptString "Your name={{ cli_modern_user }}"
|
|
--promptString "Your email="
|
|
--promptChoice "Machine type={{ cli_modern_chezmoi_machine_type }}"
|
|
--no-tty
|
|
args:
|
|
chdir: "{{ cli_modern_user_home }}"
|
|
creates: "{{ cli_modern_user_home }}/.local/share/chezmoi/.git"
|
|
when:
|
|
- cli_modern_chezmoi_repo | length > 0
|
|
- not cli_modern_chezmoi_dir.stat.exists
|
|
|
|
- name: Apply Chezmoi dotfiles
|
|
become: true
|
|
become_user: "{{ cli_modern_user }}"
|
|
ansible.builtin.command: chezmoi apply --no-tty
|
|
args:
|
|
chdir: "{{ cli_modern_user_home }}"
|
|
register: cli_modern_chezmoi_apply
|
|
changed_when: cli_modern_chezmoi_apply.rc == 0
|
|
when:
|
|
- cli_modern_chezmoi_repo | length > 0
|