Browse code

Add implementation

Robert Cranston authored on 17/08/2018 13:48:21
Showing 4 changed files

... ...
@@ -2,11 +2,50 @@
2 2
 
3 3
 An [Ansible][] [role][] for deploying [dotfile][]s on [Unix-like][]s.
4 4
 
5
+Takes [Git][] repository [URL][]s in the variable `dotfiles`, clones them into
6
+subdirectories of `$HOME/.dotfiles` (overridable with the variable
7
+`dotfiles_dir`) and uses [`stow`][] (which must be present on the target
8
+system!) to [symlink][] the contents into the parent directory of
9
+`dotfiles_dir` (overridable with the variable `dotfiles_target`).
10
+
5 11
 [`ansible-role-dotfiles`]: https://git.rcrnstn.net/rcrnstn/ansible-role-dotfiles
6 12
 [Ansible]: https://docs.ansible.com/ansible
7 13
 [role]: https://docs.ansible.com/ansible/latest/user_guide/playbooks_reuse_roles.html
8 14
 [dotfile]: https://en.wikipedia.org/wiki/Hidden_file_and_hidden_directory#Unix_and_Unix-like_environments
9 15
 [Unix-like]: https://en.wikipedia.org/wiki/Unix-like
16
+[Git]: https://git-scm.com
17
+[URL]: https://en.wikipedia.org/wiki/URL
18
+[symlink]: https://en.wikipedia.org/wiki/Symbolic_link
19
+[`stow`]: https://www.gnu.org/software/stow/
20
+
21
+## Usage
22
+
23
+Example [`requirements.yml`][]:
24
+
25
+```yaml
26
+---
27
+
28
+roles:
29
+  - name: 'dotfiles'
30
+    src: 'https://git.rcrnstn.net/rcrnstn/ansible-role-dotfiles'
31
+    scm: 'git'
32
+```
33
+
34
+Example [playbook][]:
35
+
36
+```yaml
37
+---
38
+
39
+- hosts: 'all'
40
+  roles:
41
+    - role: 'dotfiles'
42
+      dotfiles:
43
+        - 'https://github.com/user/dotfiles-program1'
44
+        - 'https://github.com/user/dotfiles-program2'
45
+```
46
+
47
+[`requirements.yml`]: https://docs.ansible.com/ansible/latest/galaxy/user_guide.html#installing-multiple-roles-from-a-file
48
+[playbook]: https://docs.ansible.com/ansible/latest/user_guide/playbooks.html
10 49
 
11 50
 ## License
12 51
 
13 52
new file mode 100644
... ...
@@ -0,0 +1,4 @@
1
+---
2
+
3
+dotfiles_dir:    '{{ ansible_env.HOME }}/.dotfiles'
4
+dotfiles_target: '{{ dotfiles_dir     }}/..'
0 5
new file mode 100644
... ...
@@ -0,0 +1,20 @@
1
+---
2
+
3
+- name: 'Clone {{ item | basename }}'
4
+  git:
5
+    repo: '{{ item }}'
6
+    dest: '{{ dotfiles_dir }}/{{ item | basename }}'
7
+
8
+- name: 'Stow {{ item | basename }}'
9
+  command:
10
+    argv:
11
+      - 'stow'
12
+      - '--verbose'
13
+      - '--no-folding'
14
+      - '--dir'
15
+      - '{{ dotfiles_dir }}'
16
+      - '--target'
17
+      - '{{ dotfiles_target }}'
18
+      - '{{ item | basename }}'
19
+  register: result
20
+  changed_when: result.stderr != ''
0 21
new file mode 100644
... ...
@@ -0,0 +1,14 @@
1
+---
2
+
3
+- name: 'Dotfiles'
4
+  include_tasks: 'dotfiles.yml'
5
+  loop: '{{ dotfiles }}'
6
+
7
+- name: 'Check stow: {{ dotfiles_target }}'
8
+  command:
9
+    argv:
10
+      - 'chkstow'
11
+      - '--target'
12
+      - '{{ dotfiles_target }}'
13
+  register: result
14
+  changed_when: result.stdout != ''