SHA256
1
0
Files
deploy/roles/dotfiles/tasks/main.yml
2026-01-27 01:59:47 -05:00

83 lines
3.0 KiB
YAML

---
- name: Build file lists
ansible.builtin.set_fact:
dotfiles_files_home: "{{ lookup('community.general.filetree',
playbook_dir ~ '/dotfiles/common/home',
playbook_dir ~ '/dotfiles/' ~ group_names[0] ~ '/home') | selectattr('state', 'equalto', 'file') | rejectattr('path', 'match', '.*\\.j2$') | list }}"
dotfiles_templates_home: "{{ lookup('community.general.filetree',
playbook_dir ~ '/dotfiles/common/home',
playbook_dir ~ '/dotfiles/' ~ group_names[0] ~ '/home') | selectattr('state', 'equalto', 'file') | selectattr('path', 'match', '.*\\.j2$') | list }}"
dotfiles_files_root: "{{ lookup('community.general.filetree',
playbook_dir ~ '/dotfiles/common/root',
playbook_dir ~ '/dotfiles/' ~ group_names[0] ~ '/root') | selectattr('state', 'equalto', 'file') | rejectattr('path', 'match', '.*\\.j2$') | list }}"
dotfiles_templates_root: "{{ lookup('community.general.filetree',
playbook_dir ~ '/dotfiles/common/root',
playbook_dir ~ '/dotfiles/' ~ group_names[0] ~ '/root') | selectattr('state', 'equalto', 'file') | selectattr('path', 'match', '.*\\.j2$') | list }}"
- name: Ensure home directories
ansible.builtin.file:
path: "{{ ansible_facts.env.HOME }}/{{ item.path | dirname }}"
state: directory
mode: "{{ '0700' if (item.path | dirname).startswith('.ssh') else '0755' }}"
loop: "{{ dotfiles_files_home + dotfiles_templates_home }}"
when: item.path | dirname != ''
- name: Deploy home files (local)
ansible.builtin.file:
src: "{{ item.src }}"
dest: "{{ ansible_facts.env.HOME }}/{{ item.path }}"
state: link
force: true
loop: "{{ dotfiles_files_home }}"
when: ansible_connection in ['local', 'localhost']
- name: Deploy home files (remote)
ansible.builtin.copy:
src: "{{ item.src }}"
dest: "{{ ansible_facts.env.HOME }}/{{ item.path }}"
mode: preserve
loop: "{{ dotfiles_files_home }}"
when: ansible_connection not in ['local', 'localhost']
- name: Render home templates
ansible.builtin.template:
src: "{{ item.src }}"
dest: "{{ ansible_facts.env.HOME }}/{{ item.path | replace('.j2', '') }}"
mode: preserve
loop: "{{ dotfiles_templates_home }}"
- name: Ensure root directories
ansible.builtin.file:
path: "/{{ item.path | dirname }}"
state: directory
mode: '0755'
loop: "{{ dotfiles_files_root + dotfiles_templates_root }}"
become: true
- name: Deploy root files (local)
ansible.builtin.file:
src: "{{ item.src }}"
dest: "/{{ item.path }}"
state: link
force: true
loop: "{{ dotfiles_files_root }}"
when: ansible_connection in ['local', 'localhost']
become: true
- name: Deploy root files (remote)
ansible.builtin.copy:
src: "{{ item.src }}"
dest: "/{{ item.path }}"
mode: preserve
loop: "{{ dotfiles_files_root }}"
when: ansible_connection not in ['local', 'localhost']
become: true
- name: Render root templates
ansible.builtin.template:
src: "{{ item.src }}"
dest: "/{{ item.path | replace('.j2', '') }}"
mode: preserve
loop: "{{ dotfiles_templates_root }}"
become: true