-
Notifications
You must be signed in to change notification settings - Fork 11
/
dotfiles-and-cli-setup.yml
278 lines (233 loc) · 8.58 KB
/
dotfiles-and-cli-setup.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
# This role installs my [dotfiles](https://github.com/jan-warchol/dotfiles).
# Basically, the dotfiles repository should contain only user configuration
# that is common to all my accounts, and is reasonable to track as plain
# text files. In particular, nothing here should depend on any ansible
# group_vars or host_vars.
#
# Any configs that don't meet these requirements (system-wide settings, GUI
# settings that live in binary files or unwieldy XMLs, etc.) should be
# managed by some other means. In particular, settings that differ between
# accounts live in `user-config` role.
# Requirements: ssh key with access to github configured.
- name: Install dotfiles dependencies
hosts: all
tasks:
- name: install apt dependencies
apt:
name:
- git
- fd-find
become: yes
- name: symlink fdfind to fd
file:
src: /usr/bin/fdfind
dest: /usr/bin/fd
state: link
become: yes
- name: ensure directories exist
file:
dest: "{{ ansible_env.HOME }}/{{ item }}"
state: directory
mode: 0700
loop:
- bin
- .config/htop
- name: download fasd
get_url:
url: https://raw.githubusercontent.com/clvv/fasd/master/fasd
dest: "{{ ansible_env.HOME }}/bin/fasd"
mode: 0755
# required by git configuration
- name: download smartless
get_url:
url: https://raw.githubusercontent.com/jan-warchol/smartless/master/smartless
dest: "{{ ansible_env.HOME }}/bin/smartless"
mode: 0755
# required by git configuration
- name: download script for merging ansible vaults
get_url:
# commit ID pinned for better security
url: "https://raw.githubusercontent.com/building5/ansible-vault-tools/\
1a7c7817dd3052b077fb6809e303e46d7b711df1/ansible-vault-merge.sh"
dest: "{{ ansible_env.HOME }}/bin/ansible-vault-merge"
mode: 0755
# cannot be tracked in dotfiles because it updates every time I change the view
- name: template htop configuration
template:
src: htoprc.j2
dest: "{{ ansible_env.HOME }}/.config/htop/htoprc"
tags: htop
# Officially recommended replacement for deprecated git filter-branch
- name: download git filter-repo
get_url:
url: https://raw.githubusercontent.com/newren/git-filter-repo/master/git-filter-repo
dest: "{{ ansible_env.HOME }}/bin/git-filter-repo"
mode: 0755
- name: Install dotfiles themselves
hosts: all
vars:
dotfiles_repo: jan-warchol/dotfiles.git
roles:
- known-hosts
tasks:
- name: check for dotfiles
stat: path={{ dotfiles_home }}
register: dotfiles
# My dotfiles installation script is not idempotent, so we must skip
# installation tasks if the dotfiles are already present.
# TODO
# Note that I initially clone using https and later change the protocol
# to SSH. This is because my SSH keys may not be present when cloning,
# and because I need different urls for work account SSH configuration.
- name: clone dotfiles
git:
repo: "{{ github_url }}{{ dotfiles_repo }}"
dest: "{{ dotfiles_home }}"
version: devel
force: no
when: dotfiles.stat.exists == false
- name: configure git user email
git_config:
key: user.email
value: [email protected]
repo: "{{ dotfiles_home }}"
- name: install dotfiles
shell: >
{{ dotfiles_home }}/.install-dotfiles.sh
creates=~/.config/dotfiles-git-dir
when: dotfiles.stat.exists == false
register: dotfiles_installation
- name: report installation results
debug: var=dotfiles_installation.stdout_lines
when: dotfiles_installation.changed
- name: clone git tools
git:
repo: "{{ github_url }}jan-warchol/git-tools.git"
dest: "{{ git_tools_path }}"
force: no
- name: template locations file
copy:
content: |
export FZF_HOME={{ fzf_home }}
export FZF_HISTORY={{ fzf_history }}
export FZF_VIM_HISTORY={{ fzf_vim_history }}
export DOTFILES_HOME={{ dotfiles_home }}
export ANSIBLE_SETUP_PATH={{ ansible_setup_path }}
export PASSWORD_STORE_DIR={{ passwordstore_path }}
export GIT_TOOLS={{ git_tools_path }}
dest: ~/.config/bash/00-paths-override.sh
- name: let git ignore changes in README
command: git update-index --assume-unchanged ~/README.md
environment:
GIT_DIR: "{{ dotfiles_home }}"
GIT_WORK_TREE: "{{ ansible_env.HOME }}"
register: git_status
failed_when:
- git_status is failed
- "'Unable to mark file README.md' not in git_status.stderr"
# I don't want README (meant for github) to pollute my actual home dir
- name: hide dotfiles README
shell: mv --backup=numbered ~/README.md ~/.README.md
register: mv_status
changed_when: not mv_status is failed
failed_when:
- mv_status is failed
- "'No such file or directory' not in mv_status.stderr"
- name: Setup Vim
hosts: all
tags: vim
tasks:
- name: add neovim PPA
apt_repository:
repo: ppa:neovim-ppa/stable
codename: "{{ dist_override | default(omit) }}"
filename: "neovim"
become: yes
- name: Install vim and neovim
apt:
name:
- vim-gtk3 # default `vim` package doesn't have clipboard support
- neovim
become: yes
- name: ensure config directories exist
file:
dest: "{{ ansible_env.HOME }}/{{ item }}"
state: directory
with_items:
- .local/share/nvim/site/autoload # for vim-plug in neovim
- .vim/autoload # for vim-plug in vim
- .vim/swap # global dir for swapfiles
- .vim/backup # global dir for backup files
- .vim/colors # for colorschemes
# The nice thing about vim-plug (https://github.com/junegunn/vim-plug)
# is that it can be installed just by downloading one file.
- name: install vim-plug for vim and neovim
get_url:
url: https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
dest: "{{ item }}"
loop:
- "{{ ansible_env.HOME }}/.vim/autoload/plug.vim"
- "{{ ansible_env.HOME }}/.local/share/nvim/site/autoload/plug.vim"
- name: install selenized color palette
get_url:
url: "https://raw.githubusercontent.com/jan-warchol/selenized/\
master/editors/vim/colors/selenized.vim"
dest: "{{ ansible_env.HOME }}/.vim/colors/selenized.vim"
force: yes
- name: install plugins (only first time)
shell: vim +PlugInstall +qall creates={{ ansible_env.HOME }}/.vim/plugged
- name: Install FZF
hosts: all
tags: fzf
tasks:
# fzf isn't available in Ubuntu repos - configure Debian Buster source
# (unless we're already on Debian)
- when: ansible_distribution != "Debian"
become: yes
block:
- name: add ubuntu jammy repo
apt_repository:
repo: deb http://archive.ubuntu.com/ubuntu jammy universe
filename: "ubuntu-jammy-backport"
- name: configure apt preferences
copy:
# important! This file has to be first lexicographically
# or other settings (e.g. `release o=Ubuntu` set in
# official-package-repositories.pref) may override it
dest: /etc/apt/preferences.d/01-fzf-backport.pref
content: |
# prefer fzf version available in Ubuntu Jammy
Package: fzf
Pin: release a=jammy
Pin-Priority: 800
# but don't try to backport other packages
Package: *
Pin: release a=jammy
Pin-Priority: 200
- name: install fzf
apt:
name: fzf
state: latest
update_cache: yes # FIXME should be handled in task adding repo
become: yes
- name: get customized fzf repo
git:
repo: "{{ github_url }}jan-warchol/fzf"
dest: "{{ fzf_home }}"
- name: add upstream to fzf repo
blockinfile:
block: |
[remote "upstream"]
url = https://github.com/junegunn/fzf.git
fetch = +refs/heads/*:refs/remotes/upstream/*
dest: "{{ fzf_home }}/.git/config"
- name: ensure directories exist
file:
dest: "{{ ansible_env.HOME }}/data/fzf/"
state: directory
mode: 0700
- name: ensure fzf history file exists
copy:
dest: "{{ fzf_history }}"
content: ""
force: no