ansible: refactor tasks into a common role

This commit is contained in:
Fernando Schauenburg 2020-12-18 10:47:13 +01:00
parent 5b30d96507
commit 3542f4a741
43 changed files with 256 additions and 332 deletions

2
.gitattributes vendored
View file

@ -1 +1 @@
roles/ssh/files/config filter=git-crypt diff=git-crypt
roles/common/files/ssh_config filter=git-crypt diff=git-crypt

View file

@ -23,7 +23,7 @@ sudo apt-get install ansible
echo -e "Host git.schauenburg.me\nUser git\nPort 587" >>~/.ssh/config
git clone git@git.schauenburg.me:fernando/dotfiles.git $HOME/.dotfiles
cd $HOME/.dotfiles
ansible-playbook -i hosts.ini dotfiles.yml
ansible-playbook -i inventory dotfiles.yml
gpg -d --output - <(base64 -d .key) | git crypt unlock -
```

View file

@ -1,23 +1,12 @@
- name: Make myself at home :)
hosts: dotfiles
vars_prompt:
- name: git_user
private: no
default: Fernando Schauenburg
- name: git_email
private: no
default: fernando@schauenburg.me
# vars_prompt:
# - name: git_user
# private: no
# default: Fernando Schauenburg
# - name: git_email
# private: no
# default: fernando@schauenburg.me
roles:
- packages
- bin
- bash
- dircolors
- git
- hushlogin
- mintty
- python
- readline
- ssh
- tmux
- vim
- common

View file

@ -1,57 +0,0 @@
- name: Install latest bash with apt
when: ansible_os_family == "Debian"
become: yes
apt:
update_cache: yes
state: latest
name:
- bash
- bash-completion
- name: Install latest bash with homebrew
when: ansible_os_family == "Darwin"
homebrew:
state: latest
name:
- bash
- bash-completion
- name: Remove pre-installed bash configurations which could cause conflicts
file:
path: ~/{{ item }}
state: absent
loop:
- .bash_logout
- .profile
- name: Ensure existence of directories used in bashrc
file:
path: ~/{{ item }}
state: directory
loop:
- .config/bash
- .local/share/bash
- .local/share/bash-completion/completions
- .local/share/less
- name: Deploy bash profile
file:
src: "{{ role_path }}/files/profile"
dest: ~/.config/bash/profile
state: link
force: yes
- name: Make sure bash will find our profile
file:
src: ~/.config/bash/profile
dest: ~/.{{ item }}
state: link
force: yes
loop:
- .bashrc
- .bash_profile

View file

@ -89,7 +89,7 @@ endif
" }}}
" Plugins {{{
call plug#begin('$XDG_CONFIG_HOME/vim/bundle')
call plug#begin('$XDG_DATA_HOME/vim/plugged')
Plug 'altercation/vim-colors-solarized'
Plug 'bronson/vim-trailing-whitespace'
Plug 'elzr/vim-json'

View file

@ -0,0 +1,30 @@
---
- name: bash | remove pre-installed profile
file:
path: "{{ item }}"
state: absent
loop:
- ~/.bash_logout
- ~/.profile
- name: bash | ensure existence of directories used in bashrc
file:
path: "{{ item }}"
state: directory
loop:
- ~/.local/share/bash # for bash history
- ~/.local/share/bash-completion/completions # for custom completions
- ~/.local/share/less # for less history
- name: bash | deploy bash profile
file:
src: "{{ role_path }}/files/bashrc"
dest: "{{ item }}"
state: link
force: yes
loop:
- ~/.bash_profile # executed for login shells
- ~/.bashrc # executed for interactve shells

View file

@ -1,15 +1,16 @@
- name: Create local bin directory
---
- name: bin | create ~/.local/bin
file:
path: ~/.local/bin
state: directory
- name: Deploy local commands
- name: bin | deploy local commands
file:
src: "{{ item }}"
dest: ~/.local/bin/{{ item | basename }}
state: link
force: yes
with_fileglob:
- "{{ role_path }}/files/*"
- "{{ role_path }}/files/bin/*"

View file

@ -1,4 +1,5 @@
- name: Create the dircolors config directory
---
- name: dircolors | create config directory
file:
path: ~/.config/dircolors
state: directory
@ -11,5 +12,5 @@
state: link
force: yes
with_fileglob:
- "{{ role_path }}/files/*"
- "{{ role_path }}/files/dircolors/*"

View file

@ -0,0 +1,26 @@
---
- name: git | create config directories
file:
path: "{{ item }}"
state: directory
loop:
- ~/.config/git
- ~/.local/etc/git
- name: git | deploy config
file:
src: "{{ role_path }}/files/{{ item.src }}"
dest: ~/.config/git/{{ item.dest }}
state: link
force: yes
loop:
- { src: gitconfig, dest: config }
- { src: gitignore, dest: ignore }
- name: git | deploy host-specific config
template:
src: gitconfig.host.j2
dest: ~/.local/etc/git/config.host

View file

@ -0,0 +1,13 @@
---
- name: hushlogin | exists?
stat:
path: ~/.hushlogin
register: hush
- name: hushlogin | create
when: hush.stat.exists == false
file:
path: ~/.hushlogin
state: touch

View file

@ -0,0 +1,15 @@
---
- block:
# - import_tasks: bash.yml
# - import_tasks: bin.yml
# - import_tasks: dircolors.yml
# - import_tasks: git.yml
# - import_tasks: hushlogin.yml
# - import_tasks: mintty.yml
- import_tasks: packages.yml # TODO
# - import_tasks: python.yml
# - import_tasks: readline.yml
# - import_tasks: ssh.yml
# - import_tasks: tmux.yml
# - import_tasks: vim.yml

View file

@ -1,12 +1,13 @@
- name: Create the mintty config directory
---
- name: mintty | create config directory
file:
path: ~/.config/mintty
state: directory
- name: Deploy mintty config
- name: mintty | deploy config
file:
src: "{{ role_path }}/files/config"
src: "{{ role_path }}/files/minttyrc"
dest: ~/.config/mintty/config
state: link
force: yes

View file

@ -0,0 +1,73 @@
---
- name: debian | install apt packages
when: ansible_facts['os_family']|lower == "debian"
become: yes
apt:
state: latest
update_cache: yes
name:
- bash
- bash-completion
- curl
- exa
- exuberant-ctags
- ffmpeg
- git
- git-crypt
- git-lfs
- gpg
- htop
- nmap
- psmisc
- python3
- python3-pip
- shellcheck
- sqlite
- stow
- tmux
- tree
- vifm
- vim
- wget
- youtube-dl
- name: macOS | install homebrew packages
when: ansible_facts['os_family']|lower == "darwin"
homebrew:
state: latest
name:
- bash
- bash-completion
- coreutils
- ctags
- curl
- exa
- exiftool
- ffmpeg
- findutils
- git
- git-crypt
- git-lfs
- gnu-sed
- gpg
- grep
- gzip
- htop
- imagemagick
- jupyter
- make
- nmap
- pstree
- python3
- reattach-to-user-namespace
- shellcheck
- sqlite
- stow
- tmux
- tree
- vifm
- vim
- wget
- youtube-dl

View file

@ -0,0 +1,17 @@
---
- name: python | create config and data directories
file:
path: "{{ item }}"
state: directory
loop:
- ~/.config/python
- ~/.local/share/python # for this history file
- name: python | deploy startup file
file:
src: "{{ role_path }}/files/python-startup.py"
dest: ~/.config/python/startup.py
state: link
force: yes

View file

@ -1,10 +1,11 @@
- name: Create the readline config directory
---
- name: readline | create config directory
file:
path: ~/.config/readline
state: directory
- name: Deploy inputrc
- name: readline | deploy inputrc
file:
src: "{{ role_path }}/files/inputrc"
dest: ~/.config/readline/inputrc

View file

@ -0,0 +1,14 @@
---
- name: ssh | create config diretory
file:
path: ~/.ssh
state: directory
- name: ssh | deploy config
file:
src: "{{ role_path }}/files/ssh_config"
dest: ~/.ssh/config
state: link
force: yes

View file

@ -0,0 +1,17 @@
---
- name: tmux | create config directory
file:
path: ~/.config/tmux
state: directory
- name: tmux | deploy config
file:
src: "{{ role_path }}/files/{{ item }}"
dest: ~/.config/tmux/{{ item }}
state: link
force: yes
loop:
- tmux.conf
- tmux-colors.conf

View file

@ -0,0 +1,26 @@
---
- name: vim | create directories
file:
path: "{{ item }}"
state: directory
loop:
- ~/.config/vim # for vimrc
- ~/.config/vim/autoload # for plugin manager
- ~/.local/share/vim # for viminfo
- ~/.local/share/vim/plugged # for installing uplugins
- name: vim | deploy configuration
file:
src: "{{ role_path }}/files/{{ item.src }}"
dest: "{{ item.dest }}"
state: link
force: yes
loop:
- { src: vimrc, dest: ~/.config/vim/vimrc }
- { src: plug.vim, dest: ~/.config/vim/autoload/plug.vim }
- name: vim | install plugins
shell: vim -es -u ~/.config/vim/vimrc +PlugInstall +qall

View file

@ -1,58 +0,0 @@
- name: Install git with apt
when: ansible_os_family == "Debian"
become: yes
apt:
update_cache: yes
state: latest
name:
- git
- git-crypt
- git-lfs
- name: Install git with homebrew
when: ansible_os_family == "Darwin"
homebrew:
state: latest
name:
- git
- git-crypt
- git-lfs
- name: Create the git config directories
file:
path: "{{ item }}"
state: directory
loop:
- ~/.config/git
- ~/.local/bin
- ~/.local/etc/git
- name: Deploy git config
file:
src: "{{ role_path }}/files/{{ item }}"
dest: ~/.config/git/{{ item }}
state: link
force: yes
loop:
- config
- ignore
- name: Deploy git host-specific config
template:
src: config.host.j2
dest: ~/.local/etc/git/config.host
- name: Deploy additional git commands
file:
src: "{{ item }}"
dest: "~/.local/bin/{{ item | basename }}"
state: link
force: yes
with_fileglob:
- "{{ role_path }}/files/bin/*"

View file

@ -1,5 +0,0 @@
- name: Make sure hushlogin exists
file:
path: ~/.hushlogin
state: touch

View file

@ -1,59 +0,0 @@
- name: Set up Debian machine
when: ansible_os_family == "Debian"
become: yes
block:
- name: Install apt packages
apt:
update_cache: yes
state: latest
name:
- curl
- exa
- exuberant-ctags
- ffmpeg
- gpg
- htop
- nmap
- psmisc
- shellcheck
- sqlite
- stow
- tree
- vifm
- wget
- youtube-dl
- name: Set up macOS machine
when: ansible_os_family == "Darwin"
block:
- name: Install homebrew packages
homebrew:
state: latest
name:
- coreutils
- ctags
- curl
- exa
- exiftool
- ffmpeg
- findutils
- gnu-sed
- gpg
- grep
- gzip
- htop
- imagemagick
- jupyter
- make
- nmap
- pstree
- reattach-to-user-namespace
- shellcheck
- sqlite
- stow
- tree
- vifm
- wget
- youtube-dl

View file

@ -1,34 +0,0 @@
- name: Install python3 with apt
when: ansible_os_family == "Debian"
become: yes
apt:
update_cache: yes
state: latest
name:
- python3
- python3-pip
- name: Install python3 with homebrew
when: ansible_os_family == "Darwin"
homebrew:
name: python3
state: latest
- name: Create the python config and data directories
file:
path: "{{ item }}"
state: directory
loop:
- ~/.config/python
- ~/.local/share/python # for this history file
- name: Deploy python startup file
file:
src: "{{ role_path }}/files/startup.py"
dest: ~/.config/python/startup.py
state: link
force: yes

View file

@ -1,13 +0,0 @@
- name: Create the SSH directory
file:
path: ~/.ssh
state: directory
- name: Deploy SSH config
file:
src: "{{ role_path }}/files/config"
dest: ~/.ssh/config
state: link
force: yes

View file

@ -1,32 +0,0 @@
- name: Install tmux with apt
when: ansible_os_family == "Debian"
become: yes
apt:
name: tmux
state: latest
update_cache: yes
- name: Install tmux with homebrew
when: ansible_os_family == "Darwin"
homebrew:
name: tmux
state: latest
- name: Create the tmux config directory
file:
path: ~/.config/tmux
state: directory
- name: Deploy tmux config
file:
src: "{{ role_path }}/files/{{ item }}"
dest: ~/.config/tmux/{{ item }}
state: link
force: yes
loop:
- tmux.conf
- tmux-colors.conf

View file

@ -1,42 +0,0 @@
- name: Install vim with apt
when: ansible_os_family == "Debian"
become: yes
apt:
name: vim
state: latest
update_cache: yes
- name: Install vim with homebrew
when: ansible_os_family == "Darwin"
homebrew:
name: vim
state: latest
- name: Create the vim cache and config directories
file:
path: "{{ item }}"
state: directory
loop:
- ~/.cache/vim
- ~/.config/vim
- ~/.config/vim/autoload
- name: Deploy vim-plug and vimrc
file:
src: "{{ role_path }}/files/{{ item.src }}"
dest: ~/.config/vim/{{ item.dest }}
state: link
force: yes
loop:
- src: plug.vim
dest: autoload/plug.vim
- src: vimrc
dest: vimrc
- name: Install configured vim plugins
shell: vim -u "~/.config/vim/vimrc" +PlugInstall +qall