feat: install dotfiles (improvements needed)
This commit is contained in:
4
hosts
4
hosts
@@ -1,13 +1,16 @@
|
||||
[desktop]
|
||||
# dont put localhost here, ansible will attempt to connect via ssh
|
||||
|
||||
[headless]
|
||||
server[1:7]
|
||||
openmediavault
|
||||
kali
|
||||
|
||||
[oracleServer]
|
||||
server[1:7]
|
||||
|
||||
[home]
|
||||
kali
|
||||
|
||||
[ubuntu]
|
||||
server[1:7]
|
||||
@@ -15,6 +18,7 @@ server[1:7]
|
||||
[arm64]
|
||||
server[2:6:2]
|
||||
server7
|
||||
kali
|
||||
|
||||
[amd64]
|
||||
server[1:5:2]
|
||||
|
||||
8
install_dotfiles.yml
Normal file
8
install_dotfiles.yml
Normal file
@@ -0,0 +1,8 @@
|
||||
---
|
||||
- name: Install dotfiles on target
|
||||
hosts: 'kali'
|
||||
|
||||
tasks:
|
||||
- name: Install dotfiles
|
||||
include_role:
|
||||
name: install_dotfiles
|
||||
@@ -1,8 +1,6 @@
|
||||
---
|
||||
roles:
|
||||
- name: jan_matthis.git_dotfiles
|
||||
- name: geerlingguy.dotfiles
|
||||
version: "1.2.1"
|
||||
- name: geerlingguy.docker
|
||||
version: "6.1.0"
|
||||
- name: geerlingguy.git
|
||||
|
||||
@@ -1,3 +1,22 @@
|
||||
dotfiles_repo_source: "git@github.com:eneller/.dotfiles"
|
||||
dotfiles_repo_commit: "headless"
|
||||
dotfiles_repo_destination: ".dotfiles"
|
||||
# The git source of your dotfiles. Will be cloned as a bare repository.
|
||||
# Make sure you have set up git correctly before using.
|
||||
dotfiles_repo_source: "https://github.com/eneller/.dotfiles.git"
|
||||
|
||||
# can be branch name or commit hash, used for ansible.builtin.git version
|
||||
dotfiles_repo_version: "headless"
|
||||
|
||||
# Will become the parent-directory of your dotfiles
|
||||
dotfiles_dest: "{{ ansible_user_dir }}"
|
||||
|
||||
# The folder name to use for the bare repository
|
||||
dotfiles_git_dir: "{{ ansible_user_dir}}/.dotfiles"
|
||||
|
||||
# Decide whether to back up already existing dotfiles that would conflict with your repo.
|
||||
# Will overwrite them if false
|
||||
dotfiles_do_backup: true
|
||||
|
||||
# Uses a temporary directory to run git ls-files if {{ dotfiles_do_backup }} is true
|
||||
dotfiles_tmp_dir: "/tmp/dotfiles"
|
||||
|
||||
# An alias to access the bare repo for internal use
|
||||
dotfiles_alias: "git --git-dir={{ dotfiles_git_dir }} --work-tree={{ dotfiles_dest }}"
|
||||
@@ -1,29 +1,54 @@
|
||||
- name: Check for existing dotfiles repository
|
||||
ansible.builtin.stat:
|
||||
path: "{{ dotfiles_repo_destination }}HEAD"
|
||||
path: "{{ dotfiles_git_dir }}/HEAD"
|
||||
register: dotfiles_repo_head
|
||||
changed_when: false
|
||||
changed_when: false # this never applies changes
|
||||
when: dotfiles_do_backup
|
||||
|
||||
- name: Clone into /tmp
|
||||
ansible.builtin.git:
|
||||
dest: /tmp/dotfiles
|
||||
dest: "{{ dotfiles_tmp_dir }}"
|
||||
repo: "{{ dotfiles_repo_source }}"
|
||||
version: "{{ dotfiles_repo_commit }}"
|
||||
version: "{{ dotfiles_repo_version }}"
|
||||
when: not dotfiles_repo_head.stat.exists
|
||||
|
||||
- name: Back up existing dotfiles
|
||||
ansible.builtin.shell:
|
||||
chdir: /tmp/dotfiles
|
||||
cmd: |
|
||||
git ls-files | while read -r line; do
|
||||
mv $HOME/$line $HOME/$line.bak
|
||||
done
|
||||
# when: # TODO only if bare repo doesnt already exist
|
||||
|
||||
- name: Get list of dotfiles
|
||||
ansible.builtin.command:
|
||||
chdir: "{{ dotfiles_tmp_dir }}"
|
||||
cmd: git ls-files
|
||||
register: dotfiles_lsfiles # needs to be used with .stdout_lines for iteratio
|
||||
when: not dotfiles_repo_head.stat.exists
|
||||
|
||||
- name: Back up dotfiles that would be overwritten by checkout
|
||||
ansible.builtin.command:
|
||||
cmd: "mv {{ dotfiles_dest }}/{{ item }} {{ dotfiles_dest }}/{{ item }}.bak"
|
||||
args:
|
||||
creates: "{{ dotfiles_dest }}/{{ item }}.bak"
|
||||
removes: "{{ dotfiles_dest }}/{{ item }}"
|
||||
with_items: "{{ dotfiles_lsfiles.stdout_lines }}"
|
||||
when: not dotfiles_repo_head.stat.exists
|
||||
|
||||
- name: Initialize dotfiles repository in user home
|
||||
ansible.builtin.git:
|
||||
bare: true
|
||||
update: true
|
||||
dest: "{{ ansible_user_directory }}/{{ dotfiles_repo_destination }}"
|
||||
force: true # this is okay here because we backed up already existing files
|
||||
dest: "{{ dotfiles_git_dir }}"
|
||||
repo: "{{ dotfiles_repo_source }}"
|
||||
version: "{{ dotfiles_repo_commit }}"
|
||||
version: "{{ dotfiles_repo_version }}"
|
||||
|
||||
# TODO improve these cmd tasks, i dont really know how though
|
||||
# i dont know why this checkout is necessary, was expecting the previous task to do this
|
||||
- name: Configure git repository
|
||||
ansible.builtin.command:
|
||||
cmd: |
|
||||
{{ dotfiles_alias }}
|
||||
checkout {{ dotfiles_repo_version }}
|
||||
--force
|
||||
|
||||
- name: Configure git repository
|
||||
ansible.builtin.command:
|
||||
cmd: |
|
||||
{{ dotfiles_alias }}
|
||||
config status.showUntrackedFiles no
|
||||
|
||||
Reference in New Issue
Block a user