From 2654e28869da55e564d24c1feb69d038dceb3ca6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hannes=20K=C3=B6rber?= Date: Fri, 17 Aug 2018 19:44:31 +0200 Subject: [PATCH] Enable templating for dotfiles --- _machines/notebook01.yml | 6 +++++ _machines/tb-hak.yml | 6 +++++ dotfiles.yml | 16 ++++++++++-- git/{gitconfig => gitconfig.j2} | 4 +-- i3/{config => config.j2} | 6 ++--- i3/{i3status.conf => i3status.conf.j2} | 0 playbook.yml | 36 ++++++++++++++++++++++++++ x/{Xresources => Xresources.j2} | 4 +-- zsh/{zprofile => zprofile.j2} | 6 +++++ zsh/{zshrc => zshrc.j2} | 4 +++ 10 files changed, 79 insertions(+), 9 deletions(-) create mode 100644 _machines/notebook01.yml create mode 100644 _machines/tb-hak.yml rename git/{gitconfig => gitconfig.j2} (96%) rename i3/{config => config.j2} (98%) rename i3/{i3status.conf => i3status.conf.j2} (100%) rename x/{Xresources => Xresources.j2} (92%) rename zsh/{zprofile => zprofile.j2} (93%) rename zsh/{zshrc => zshrc.j2} (82%) diff --git a/_machines/notebook01.yml b/_machines/notebook01.yml new file mode 100644 index 0000000..5b6ed5a --- /dev/null +++ b/_machines/notebook01.yml @@ -0,0 +1,6 @@ +font_size: 9 +letter_space: 0 +mail: hannes.koerber@haktec.de +git_gpg_sign: true +gpg_agent: true +ssh_agent: true diff --git a/_machines/tb-hak.yml b/_machines/tb-hak.yml new file mode 100644 index 0000000..4e1e3a0 --- /dev/null +++ b/_machines/tb-hak.yml @@ -0,0 +1,6 @@ +font_size: 10 +letter_space: 0 +mail: hannes.koerber@tradebyte.com +git_gpg_sign: false +gpg_agent: false +ssh_agent: false diff --git a/dotfiles.yml b/dotfiles.yml index 55bb41c..138793f 100644 --- a/dotfiles.yml +++ b/dotfiles.yml @@ -1,16 +1,25 @@ +empty_directories: + - .i3 dotfiles: - from: autostart to: .autostart - from: git/gitconfig to: .gitconfig + template: true - from: gnupg/dirmngr.conf to: .gnupg/dirmngr.conf - from: gnupg/gpg-agent.conf to: .gnupg/gpg-agent.conf - from: gnupg/gpg.conf to: .gnupg/gpg.conf - - from: i3 - to: .i3 + - from: i3/config + to: .i3/config + template: true + - from: i3/i3status.conf + to: .i3/i3status.conf + template: true + - from: i3/scripts + to: .i3/scripts - from: tmux/tmux.conf to: .tmux.conf - from: vim/vimrc @@ -19,11 +28,14 @@ dotfiles: to: .vimrc - from: x/Xresources to: .Xresources + template: true - from: x/xinitrc to: .xinitrc - from: zsh/zprofile to: .zprofile + template: true - from: zsh/zshrc to: .zshrc + template: true - from: zsh/zshrc.d to: .zshrc.d diff --git a/git/gitconfig b/git/gitconfig.j2 similarity index 96% rename from git/gitconfig rename to git/gitconfig.j2 index 77ffdbc..040738e 100644 --- a/git/gitconfig +++ b/git/gitconfig.j2 @@ -1,6 +1,6 @@ [user] name = Hannes Körber - email = hannes.koerber@haktec.de + email = {{ machine.mail }} signingkey = 0x078A167A8741BD30 [github] user = hakoerber @@ -67,7 +67,7 @@ commitBeforeMerge = false detachedHead = false [commit] - gpgSign = true + gpgSign = {{ machine.git_gpg_sign|bool }} cleanup = strip status = true [status] diff --git a/i3/config b/i3/config.j2 similarity index 98% rename from i3/config rename to i3/config.j2 index c96e536..5a0a571 100644 --- a/i3/config +++ b/i3/config.j2 @@ -18,7 +18,7 @@ # The default terminal set $terminal "urxvt -title terminal" - set $calc "urxvt256c -title term -e $SHELL -i -c calc" + set $calc "urxvt -title calc -e $SHELL -i -c calc" set $scriptdir ~/.i3/scripts @@ -279,7 +279,7 @@ assign [class="^Keepassx$"] $workspace8 floating_minimum_size 0 x 0 floating_maximum_size 0 x 0 - font pango:Inconsolata 10 + font pango:Inconsolata {{ machine.font_size }} ################################################################################ ### COLOR SETTINGS ############################################################# @@ -353,7 +353,7 @@ bar { id bar-0 - font pango:Inconsolata, FontAwesome 10 + font pango:Inconsolata, FontAwesome {{ machine.font_size }} colors { background #222222 diff --git a/i3/i3status.conf b/i3/i3status.conf.j2 similarity index 100% rename from i3/i3status.conf rename to i3/i3status.conf.j2 diff --git a/playbook.yml b/playbook.yml index a63d446..8dd55ca 100644 --- a/playbook.yml +++ b/playbook.yml @@ -2,11 +2,22 @@ connection: local become: false tasks: + - name: read machine-specific variables + include_vars: + file: _machines/{{ ansible_hostname }}.yml + name: machine + tags: + - always + - set_fact: distro: "{{ ansible_distribution|lower }}" + tags: + - always - set_fact: user: "{{ ansible_user_id }}" + tags: + - always - name: configure sudoers lineinfile: @@ -153,6 +164,16 @@ - name: load dotfile list include_vars: file: dotfiles.yml + tags: + - dotfiles + + - name: create empty directories for dotfiles + file: + state: directory + path: ~/{{ item }} + with_items: "{{ empty_directories }}" + tags: + - dotfiles - name: link this folder to ~/.dotfiles file: @@ -160,6 +181,8 @@ force: true path: "{{ ansible_user_dir }}/.dotfiles" src: "{{ playbook_dir }}" + tags: + - dotfiles - name: link dotfiles file: @@ -167,7 +190,20 @@ force: true path: "{{ ansible_user_dir }}/{{ item.to }}" src: ~/.dotfiles/{{ item.from }} + when: not item.template|default(false) with_items: "{{ dotfiles }}" + tags: + - dotfiles + + - name: deploy dotfiles templates + template: + src: ~/.dotfiles/{{ item.from }}.j2 + dest: "{{ ansible_user_dir }}/{{ item.to }}" + force: true + when: item.template|default(false) + with_items: "{{ dotfiles }}" + tags: + - dotfiles - name: create directories file: diff --git a/x/Xresources b/x/Xresources.j2 similarity index 92% rename from x/Xresources rename to x/Xresources.j2 index 8f0f729..cd42b39 100644 --- a/x/Xresources +++ b/x/Xresources.j2 @@ -2,8 +2,8 @@ Xcursor.theme: Vanilla-DMZ URxvt.scrollBar: false -URxvt.font: xft:Inconsolata:size=10 -URxvt.letterSpace: -1 +URxvt.font: xft:Inconsolata:size={{ machine.font_size }} +URxvt.letterSpace: {{ machine.letter_space }} URxvt.perl-ext: default,matcher,selection-to-clipboard,font-size,resize-font URxvt.url-launcher: /usr/bin/xdg-open diff --git a/zsh/zprofile b/zsh/zprofile.j2 similarity index 93% rename from zsh/zprofile rename to zsh/zprofile.j2 index d7f3ed8..5dff422 100644 --- a/zsh/zprofile +++ b/zsh/zprofile.j2 @@ -51,6 +51,12 @@ fi # because gpg-agent is somehow broken for ssh, use the usual ssh-agent eval $(ssh-agent -s) +{% if distro == 'fedora' %} +alias urxvt=urxvt256c +{% endif %} + +alias vim="nvim" + # exec startx breaks some logind fuckery, without exec it works if [[ -z $DISPLAY ]] ; then if (( $XDG_VTNR == 1 )) ; then diff --git a/zsh/zshrc b/zsh/zshrc.j2 similarity index 82% rename from zsh/zshrc rename to zsh/zshrc.j2 index 77e1e71..9821a5e 100644 --- a/zsh/zshrc +++ b/zsh/zshrc.j2 @@ -2,12 +2,16 @@ _zshdir="$HOME/.zshrc.d" +{% if machine.gpg_agent %} export GPG_TTY=$(tty) gpg-connect-agent updatestartuptty /bye >/dev/null +{% endif %} +{% if machine.ssh_agent %} if $(ssh-add -l 2>/dev/null | grep -q "no identities") ; then ssh-add fi +{% endif %} for file in "${_zshdir}"/* ; do if [[ -e "$file" ]] ; then