1
0
mirror of https://git.decapod.one/brethil/dotfiles synced 2024-11-24 12:31:31 +01:00
dotfiles/ansible/playbooks/setup.yml
2024-01-03 15:22:01 +01:00

138 lines
3.7 KiB
YAML

---
- name: Setup dotfiles
hosts: all
vars_files:
- ../ansible-packages.yml
vars:
dotfiles_path: "$HOME/.dotfiles"
tasks:
- name: Install required system packages (debian)
apt:
install_recommends: no
update_cache: yes
pkg: "{{ packages + packages_debian }}"
when: ansible_facts['os_family'] == "Debian"
become: true
- name: Install required system packages (arch)
pacman:
update_cache: yes
name: "{{ packages + packages_archlinux }}"
when: ansible_facts['os_family'] == "Archlinux"
become: true
- name: Clone dotfiles repo
git:
repo: https://git.decapod.one/brethil/dotfiles
dest: "{{ dotfiles_path }}"
when: local_development is not defined
- name: directories
file:
dest: "{{ item }}"
state: directory
mode: 0700
loop: "{{ directories }}"
vars:
directories:
- "$HOME/bin"
- "$HOME/projects"
- "$HOME/git"
- "$HOME/.config/git"
- "$HOME/.ssh/"
- "$HOME/.ssh/sockets"
- name: Install antibody
shell: |
set -euo pipefail
curl -sfL https://git.io/antibody | sh -s - -b $HOME/bin/
$HOME/bin/antibody bundle "{{ dotfiles_path }}/antibody_plugins.txt"
args:
executable: /bin/bash
creates: bin/antibody
- name: Set zsh as default shell
user:
name: "{{ ansible_user }}"
shell: /usr/bin/zsh
become: true
- name: Update zshrc
blockinfile:
path: $HOME/.zshrc
marker: "# {mark} brethil dotfiles"
block: |
export DOTFILES={{ dotfiles_path }}
source $DOTFILES/brethil_dotfile.sh
create: true
mode: 600
- name: Update .ssh/config
blockinfile:
path: $HOME/.ssh/config
marker: "# {mark} brethil dotfiles"
insertbefore: "BOF"
block: |
TCPKeepAlive=yes
ServerAliveCountMax=6
## Uncomment to enable compression for all ssh sessions
#Compression=yes
ControlMaster auto
ControlPath ~/.ssh/sockets/%r@%n:%p
ControlPersist yes
Host *
ServerAliveInterval 300
create: true
- name: dotfiles symlinks
file:
src: "{{ dotfiles_path }}/{{ item.key }}"
dest: "{{ item.value }}"
state: link
force: yes
loop: "{{ files | dict2items }}"
vars:
files:
"tmux.conf": "~/.tmux.conf"
"vim/vimrc": "~/.vimrc"
"pdbrc.py": "~/.pdbrc.py"
# "ipython": "~/.ipython" # FIXME: ipython config is more complex
"ansible/ansible.cfg": "~/.ansible.cfg"
"gitignore": "~/.config/git/ignore"
- name: Exec vim undodir migration (if required)
command: |
mv ${HOME}/.vim_runtime/temp_dirs/undodir ${HOME}/.vim/undo
args:
removes: .vim_runtime/temp_dirs/undodir
- name: Install vim plugins
command: |
env DOTFILES={{ dotfiles_path }} vim -c 'PlugInstall|qa!'
args:
creates: .vim/vim-plug
- name: Get git config facts
community.general.git_config:
name: "include.path"
scope: global
register: config_value
- debug:
msg: "Git config include.path={{ config_value }}"
- name: Set up git config include if required
community.general.git_config:
name: "include.path"
value: "{{ dotfiles_path }}/gitconfig"
scope: global
when: config_value is not defined
- name: git global .gitignore
copy:
src: ../../gitignore
dest: ~/.gitignore
mode: "0600"