[meta] Add dotfiles role
change
commit f8503af47a50762f7e9b838a58037f0b641f0cdd
author Alpha Chen <alpha.chen@gmail.com>
date
parent 3e6b3d63
diff --git a/ansible/roles/dotfiles/files/setup_ssh_keys.rb b/ansible/roles/dotfiles/files/setup_ssh_keys.rb
new file mode 100644
index 00000000..dffc6da2
--- /dev/null
+++ b/ansible/roles/dotfiles/files/setup_ssh_keys.rb
@@ -0,0 +1,25 @@
+require 'fileutils'
+
+include FileUtils
+
+def with_mount(image)
+  out = `hdiutil mount #{image}`
+  mountpoint = out.split(/\s+/).last
+  yield(mountpoint)
+ensure
+  puts `hdiutil unmount #{mountpoint}`
+end
+
+cd File.expand_path('~/.ssh')
+
+with_mount "~/Dropbox/sekritz.sparseimage" do |mountpoint|
+  from = Dir["#{mountpoint}/ssh keys/*"]
+  to = from.map {|file| File.basename(file) }
+  from.zip(to).each do |from, to|
+    next if File.exist?(to)
+
+    cp from, to
+    puts `chmod go-r #{to}`
+    puts `ssh-add -K #{to}`
+  end
+end
diff --git a/ansible/roles/dotfiles/tasks/main.yml b/ansible/roles/dotfiles/tasks/main.yml
index ed97d539..d627092a 100644
--- a/ansible/roles/dotfiles/tasks/main.yml
+++ b/ansible/roles/dotfiles/tasks/main.yml
@@ -1 +1,13 @@
 ---
+- homebrew: name=stow
+- git: repo=https://github.com/kejadlen/dotfiles.git dest=~/.dotfiles
+- command: >
+    chdir={{ ansible_env.HOME }}/.dotfiles 
+    stow --stow --target={{ ansible_env.HOME }} {{ item }}
+  with_items: stow
+- file:
+    src: {{ ansible_env.HOME }}/.dotfiles/{{ item.key }}
+    dest: {{ ansible_env.HOME}}/{{ item.value }}
+    state: link
+  with_dict: ln
+- local_action: command ruby setup_ssh_keys.rb
diff --git a/ansible/roles/dotfiles/vars/main.yml b/ansible/roles/dotfiles/vars/main.yml
new file mode 100644
index 00000000..c7f47cad
--- /dev/null
+++ b/ansible/roles/dotfiles/vars/main.yml
@@ -0,0 +1,10 @@
+stow:
+  - config
+  - git
+  - pentadactyl
+  - ruby
+  - ssh
+  - tmux
+  - vim
+ln:
+  git/.gitignore: .gitignore