Skip to content

Commit

Permalink
a'
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume Frichet committed Apr 1, 2016
1 parent e0b2947 commit 5745aaa
Show file tree
Hide file tree
Showing 23 changed files with 123 additions and 50 deletions.
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Ansible dotfiles

- [ ] OSX defaults, applescript
- [ ] Homebrew casks cli (skipped?)
- [x] Ansible vault
- [ ] SSH config?
- [ ] irssi, mutt

## Install

bin/dot
Expand All @@ -8,9 +14,8 @@

C-a (prefix) + I

## TODO
## Inspiration

- [ ] OS X role (defaults, applescript)
- [ ] Homebrew casks cli (skipped?)
- [ ] SSH (ansible vault?)
- [ ] irssi / mutt
- Puppet [boxen](https://github.com/boxen/our-boxen)
- Chef [workstation](https://github.com/jtimberman/workstation-chef-repo)
- Ansible [battleschool](https://github.com/spencergibb/battleschool)
26 changes: 23 additions & 3 deletions ansible.cfg
Original file line number Diff line number Diff line change
@@ -1,8 +1,28 @@
[defaults]
hostfile = inventory
inventory = hosts

# Additional paths to search for roles in, colon separated
roles_path = roles.galaxy:roles.core:roles
retry_files_enabled = false
filter_plugins = plugins/filters

# Set plugin path directories
filter_plugins = /usr/share/ansible/plugins/filter:plugins/filters
# callback_plugins = plugins/callbacks

# Enable a list of additional callbacks
callback_whitelist = profile_tasks
# stdout_callback = human_log

# By default, a .retry file will be created in ~/ when a playbook fails
retry_files_enabled = false
# retry_files_save_path = ~/.ansible-retry

# Format of string {{ ansible_managed }} available within Jinja2
# templates indicates to users editing templates files will be replaced
# Replacing {file}, {host} and {uid} and strftime codes with proper values
#ansible_managed = Ansible managed: {file} modified on %Y-%m-%d %H:%M:%S by {uid} on {host}
# This short version is better used in templates as it won't flag the file as changed every run
ansible_managed = Ansible managed: {file} on {host}

# 2.1.0
# display_args_to_stdout = true
# display_skipped_host = false
4 changes: 2 additions & 2 deletions group_vars/os_macosx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ homebrew_taps:
# - caskroom/cask

homebrew_packages:
# - ack
- bash
- bash-completion
# - cmake
- coreutils
# - findutils
- findutils
# - moreutils
# - grc
- imagemagick
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion playbooks/debian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

# Update and upgrade apt
- role: apt
tags: [apt, always]
tags: [apt]

# Install apt packages
- role: package
Expand Down
2 changes: 1 addition & 1 deletion playbooks/macosx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

# Homebrew update, upgrade, tap
- role: homebrew
tags: [brew, cask, always]
tags: [brew, cask]

# Install Homebrew packages
- role: package
Expand Down
18 changes: 12 additions & 6 deletions roles.core/backup/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,23 @@
when: backup_enable
register: backup_files

# TODO: use ansible_date_time .date & .time instead of item.stat.mtime
# - debug:
# msg: "{{ item.stat.path | realpath }}"
# with_items: "{{ backup_files.results }}"

# FIXME: do not backup broken symlinks
# stat follow: true -> how to get lnk_source?
# when: not link and item.stat.path != item.item?
- name: "Backup existing {{ role_dir }} files"
vars:
dest: "{{ destination }}/{{ prefix | default('') }}{{ item.item | basename }}"
command: "mv {{ dest }} {{ dest }}.{{ backup_ext | default(item.stat.mtime | datetime) }}~"
ext: "{{ backup_ext | default(ansible_date_time.date + '@' + ansible_date_time.time + '~') }}"
# ext: "{{ backup_ext | default(item.stat.mtime | datetime) }}~"
command: "mv {{ dest }} {{ dest }}.{{ ext }}"
args:
creates: "{{ dest }}.{{ backup_ext | default(item.stat.mtime | datetime) }}~"
# with_items: "{{ stat.results | map(attribute='item') | map(attribute='stat') | list }}"
creates: "{{ dest }}.{{ ext }}"
with_items: "{{ backup_files.results }}"
when: backup_enable and item.stat.exists and
((backup_files and not item.stat.islnk) or
(backup_symlinks and item.stat.islnk and item.stat.lnk_source != item.item)) # source + '/' +
# FIXME: do not backup broken symlinks (stat follow: true?)
(backup_symlinks and item.stat.islnk and item.stat.lnk_source != item.item))
no_log: "{{ not backup_log }}"
3 changes: 3 additions & 0 deletions roles.core/target/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
that:
- "source != inventory_dir"

# - name: Confirm destination
# pause: prompt={{ destination }}

- name: "Ensure {{ role_dir }} targets are directories"
file:
path: "{{ item }}"
Expand Down
12 changes: 12 additions & 0 deletions roles/ack/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
# dependencies:

# - role: package
# packages:
# - ack-grep
# when: "ansible_os_family == 'Debian'"

# - role: package
# packages:
# - ack
# when: "ansible_os_family == 'Darwin'"
8 changes: 8 additions & 0 deletions roles/ack/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
# http://beyondgrep.com/install/
# curl http://beyondgrep.com/ack-2.14-single-file > ~/bin/ack && chmod 0755 !#:3

# - name: Rename ack-grep to ack
# command: "dpkg-divert --local --divert /usr/bin/ack --rename --add /usr/bin/ack-grep"
# become: yes
# when: "ansible_os_family == 'Debian'"
2 changes: 1 addition & 1 deletion roles/apt/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
- name: Update apt cache
apt:
update_cache: yes
cache_valid_time: "{{ apt_cache_time|default('') }}"
cache_valid_time: "{{ apt_cache_time | default('') }}"
when: packages_update
become: yes

Expand Down
1 change: 1 addition & 0 deletions roles/common/templates/npmrc.j2
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
; {{ ansible_managed }}
init.author.name = {{ npm_user }}
init.author.email = {{ npm_email }}
1 change: 1 addition & 0 deletions roles/composer/templates/composer.sh.j2
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
# {{ ansible_managed }}
export PATH=$PATH:{{ composer_home_path }}/vendor/bin
6 changes: 0 additions & 6 deletions roles/git/meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@ dependencies:
packages:
- git

# when: "ansible_os_family == 'Debian'"
# - role: brew
# packages:
# - git
# when: "ansible_os_family == 'Darwin'"

- role: template
role_dir: git

Expand Down
2 changes: 2 additions & 0 deletions roles/git/templates/gitconfig.j2
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# {{ ansible_managed }}

[user]

name = {{ git_name }}
Expand Down
2 changes: 1 addition & 1 deletion roles/homebrew/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# become: yes

- name: Ensure Homebrew is installed
shell: "ruby -e '$(curl -fsSL {{ homebrew_install_script }})'"
command: "ruby -e '$(curl -fsSL {{ homebrew_install_script }})'"
args:
creates: "{{ homebrew_install_path }}/bin/brew"
when: homebrew_install
Expand Down
1 change: 1 addition & 0 deletions roles/irssi/templates/config.j2
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Irssi configuration file
# {{ ansible_managed }}

servers = (
{
Expand Down
1 change: 1 addition & 0 deletions roles/osx/templates/defaults.sh.j2
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env bash
# {{ ansible_managed }}

# darwin.sh

Expand Down
2 changes: 2 additions & 0 deletions roles/osx/templates/terminal.scpt.j2
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# {{ ansible_managed }}

tell application "Terminal"

local allOpenedWindows
Expand Down
2 changes: 1 addition & 1 deletion roles/tmux/templates/tmux.conf.j2
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# .tmux.conf
# {{ ansible_managed }}
# vim: foldenable foldmethod=marker foldmarker={,}

# ! https://github.com/tmux-plugins/tpm
Expand Down
5 changes: 4 additions & 1 deletion roles/vim/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
---
vim_install_plugins: no
# Run :PlugInstall inside vim
vim_install_plugins: yes
# Install plugins even if ~/.vim/plugged already exists
vim_update_plugins: no
35 changes: 16 additions & 19 deletions roles/vim/files/vimrc
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@

set nocompatible

filetype off

function! YCMInstall(info)
" info is a dictionary with 3 fields
" - name: name of the plugin
Expand All @@ -33,20 +31,20 @@ function! YCMInstall(info)
endif
endfunction

function! YCMEnable()
if !exists('g:loaded_youcompleteme')
call plug#load('YouCompleteMe')
if exists('g:loaded_youcompleteme')
call youcompleteme#Enable()
endif
endif
endfunction
" function! YCMEnable()
" if !exists('g:loaded_youcompleteme')
" call plug#load('YouCompleteMe')
" endif
" if exists('g:loaded_youcompleteme')
" call youcompleteme#Enable()
" endif
" endfunction

function! SyntasticEnable()
if !exists('g:loaded_syntastic_plugin')
call plug#load('syntastic')
endif
endfunction
" function! SyntasticEnable()
" if !exists('g:loaded_syntastic_plugin')
" call plug#load('syntastic')
" endif
" endfunction

" augroup VimPlug
" autocmd!
Expand Down Expand Up @@ -76,6 +74,7 @@ Plug 'StanAngeloff/php.vim', { 'for': 'php' }
Plug 'pangloss/vim-javascript', { 'for': 'javascript' }
Plug 'digitaltoad/vim-jade'
Plug 'Valloric/YouCompleteMe', { 'do': function('YCMInstall') }
autocmd! User YouCompleteMe if !has('vim_starting') | call youcompleteme#Enable() | endif
" 'for': ['vim', 'php', 'javascript', 'cpp'] }
Plug 'SirVer/ultisnips'
Plug 'honza/vim-snippets'
Expand All @@ -84,8 +83,6 @@ Plug 'chriskempson/base16-vim'
" Add plugins to &runtimepath
call plug#end()

" Runtime {{{2

" Load matchit.vim, but only if the user hasn't installed a newer version.
if !exists('g:loaded_matchit') && findfile('plugin/matchit.vim', &rtp) ==# ''
runtime macros/matchit.vim
Expand Down Expand Up @@ -435,8 +432,8 @@ set magic

augroup VimReload
autocmd!
autocmd BufWritePost $MYVIMRC nested source $MYVIMRC
autocmd BufWritePost ~/.dotfiles/vim/vimrc nested source %
autocmd BufWritePost $MYVIMRC nested source %
" autocmd BufWritePost ~/.dotfiles/roles/vim/files/vimrc nested source %
augroup END

" Highlight trailing witespaces in red
Expand Down
23 changes: 20 additions & 3 deletions roles/vim/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,30 @@
path: "{{ destination }}/autoload"
state: directory
follow: true
tags: vim-plug

- name: Install vim-plug
get_url:
url: https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
dest: "{{ destination }}/autoload/plug.vim"
tags: vim-plug

# FIXME: timeout deb? python
- name: Install plugins
command: vim +PlugInstall +qall
# g:plug_timeout?
- name: Install vim plugins
command: "vim +PlugInstall +qall"
args:
creates: "{{ false if vim_update_plugins else destination + '/plugged/*' }}"
# command: "vim -E -s +'source {{ destination }}/vimrc' +PlugInstall +qall"
# args:
# creates: "{{ destination }}/plugged/*"
# register: vim_plug_output
# changed_when: >
# vim_plug_output.stdout != '' or
# vim_plug_output.stderr != ''
# failed_when: vim_plug_output.rc != 0
when: vim_install_plugins
tags: vim-plug

# - debug:
# var: vim_plug_output
# tags: vim-plug

0 comments on commit 5745aaa

Please sign in to comment.