From cc9072dbc5c793d7f04d8fcada28f8ae64016ead Mon Sep 17 00:00:00 2001 From: Austen Adler Date: Sat, 7 Apr 2018 21:47:15 +0000 Subject: [PATCH] Add ansible, create directory structure --- .gitignore | 1 + hosts | 2 ++ main.yml | 11 +++++++ roles/core/tasks/main.yml | 25 ++++++++++++++++ roles/secure/tasks/main.yml | 32 +++++++++++++++++++++ roles/test/tasks/main.yml | 7 +++++ roles/vim/tasks/main.yml | 31 ++++++++++++++++++++ roles/youcompleteme/tasks/main.yml | 29 +++++++++++++++++++ {i3 => skel/.i3/i3}/G2-status.conf | 0 {i3 => skel/.i3/i3}/MGen-status.conf | 0 {i3 => skel/.i3/i3}/MMLin-status.conf | 0 {i3 => skel/.i3/i3}/run.sh | 0 {zsh => skel/.zsh}/borg.zsh | 0 {zsh => skel/.zsh}/completion.zsh | 0 {zsh => skel/.zsh}/config.zsh | 0 {zsh => skel/.zsh}/history.zsh.bak | 0 {zsh => skel/.zsh}/key-bindings.zsh | 0 {zsh => skel/.zsh}/misc.zsh | 0 {zsh => skel/.zsh}/security.zsh | 0 {zsh => skel/.zsh}/spectrum.zsh | 0 {zsh => skel/.zsh}/styles.zsh | 0 {zsh => skel/.zsh}/sudo.zsh | 0 {zsh => skel/.zsh}/theme-and-appearance.zsh | 0 sync.sh | 6 ++++ 24 files changed, 144 insertions(+) create mode 100644 hosts create mode 100644 main.yml create mode 100644 roles/core/tasks/main.yml create mode 100644 roles/secure/tasks/main.yml create mode 100644 roles/test/tasks/main.yml create mode 100644 roles/vim/tasks/main.yml create mode 100644 roles/youcompleteme/tasks/main.yml rename {i3 => skel/.i3/i3}/G2-status.conf (100%) rename {i3 => skel/.i3/i3}/MGen-status.conf (100%) rename {i3 => skel/.i3/i3}/MMLin-status.conf (100%) rename {i3 => skel/.i3/i3}/run.sh (100%) rename {zsh => skel/.zsh}/borg.zsh (100%) rename {zsh => skel/.zsh}/completion.zsh (100%) rename {zsh => skel/.zsh}/config.zsh (100%) rename {zsh => skel/.zsh}/history.zsh.bak (100%) rename {zsh => skel/.zsh}/key-bindings.zsh (100%) rename {zsh => skel/.zsh}/misc.zsh (100%) rename {zsh => skel/.zsh}/security.zsh (100%) rename {zsh => skel/.zsh}/spectrum.zsh (100%) rename {zsh => skel/.zsh}/styles.zsh (100%) rename {zsh => skel/.zsh}/sudo.zsh (100%) rename {zsh => skel/.zsh}/theme-and-appearance.zsh (100%) create mode 100755 sync.sh diff --git a/.gitignore b/.gitignore index 71bfb3c..2305d09 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ .stfolder +main.retry diff --git a/hosts b/hosts new file mode 100644 index 0000000..75474c8 --- /dev/null +++ b/hosts @@ -0,0 +1,2 @@ +[local] +127.0.0.1 diff --git a/main.yml b/main.yml new file mode 100644 index 0000000..ff1b283 --- /dev/null +++ b/main.yml @@ -0,0 +1,11 @@ +--- +- hosts: local + become: false + vars: + local_path: '/tmp/eee' + roles: + - {role: core, tags: [default]} + - {role: vim, tags: [vim]} + - {role: youcompleteme, tags: [vim,youcompleteme]} + - {role: secure, sudo: yes, tags: [secure]} + - {role: test, tags: [test]} diff --git a/roles/core/tasks/main.yml b/roles/core/tasks/main.yml new file mode 100644 index 0000000..3f33a2a --- /dev/null +++ b/roles/core/tasks/main.yml @@ -0,0 +1,25 @@ +- name: Create directories + file: + path: "{{ local_path }}/{{ item.path }}" + state: directory + with_filetree: "/skel/" + when: item.state == 'directory' +- name: Link files + file: + #src: "/skel/{{ item }}" + src: "{{ item.src }}" + dest: "{{ local_path }}/{{ item.path }}" + state: link + become: no + with_filetree: "/skel/" + when: item.state == 'file' +- name: Clone fzf + git: + repo: "https://gitea.austenwares.com/stonewareslord/fzf.git" + dest: "{{ local_path }}/.fzf" + clone: yes + update: yes + force: yes + become: no +- name: Install fzf + shell: "{{ local_path|quote }}/.fzf/install --bin" diff --git a/roles/secure/tasks/main.yml b/roles/secure/tasks/main.yml new file mode 100644 index 0000000..230112a --- /dev/null +++ b/roles/secure/tasks/main.yml @@ -0,0 +1,32 @@ +- name: Protocol 2 + lineinfile: + path: /etc/ssh/sshd_config + regexp: '^\s*Protocol\s+2' + # insertbefore: '^\s*Match' + insertbefore: BOF + state: 'present' + line: 'Protocol 2' +- name: UseDNS no + lineinfile: + path: /etc/ssh/sshd_config + regexp: '^\s*UseDNS\s+no' + # insertbefore: '^\s*Match' + insertbefore: BOF + state: 'present' + line: 'UseDNS no' +- name: PermitEmptyPasswords no + lineinfile: + path: /etc/ssh/sshd_config + regexp: '^\s*PermitEmptyPasswords\s+no' + # insertbefore: '^\s*Match' + insertbefore: BOF + state: 'present' + line: 'PermitEmptyPasswords no' +- name: PermitRootLogin without-password + lineinfile: + path: /etc/ssh/sshd_config + regexp: '^\s*PermitRootLogin\s+without-password' + # insertbefore: '^\s*Match' + insertbefore: BOF + state: 'present' + line: 'PermitRootLogin without-password' diff --git a/roles/test/tasks/main.yml b/roles/test/tasks/main.yml new file mode 100644 index 0000000..9d8d89d --- /dev/null +++ b/roles/test/tasks/main.yml @@ -0,0 +1,7 @@ +- name: Insert test line + lineinfile: + path: /tmp/file + regexp: '^Listen ' + insertafter: '^#Listen ' + state: 'present' + line: 'Listen 8080' diff --git a/roles/vim/tasks/main.yml b/roles/vim/tasks/main.yml new file mode 100644 index 0000000..1097434 --- /dev/null +++ b/roles/vim/tasks/main.yml @@ -0,0 +1,31 @@ +- name: Link vimrc + file: + #src: "/skel/{{ item }}" + src: "{{ item.src }}" + dest: "{{ local_path }}/{{ item.path }}" + state: link + become: no + with_filetree: "/skel/" + when: item.state == 'file' +- name: Create vim directories + file: + path: "{{ local_path }}/{{ item.path }}" + state: directory + with_filetree: "/skel.vim/" + when: item.state == 'directory' +- name: Install plug + get_url: + url: "https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim" + dest: "{{ local_path }}/.vim/autoload/plug.vim" +- name: Clean plugins + shell: "vim -E -s -c 'source {{ local_path }}/.vimrc' -c PlugClean! -c qa" + # shell: "vim +'silent! PlugClean!' +q!" + ignore_errors: yes +- name: Install plugins + shell: "vim -E -s -c 'source {{ local_path }}/.vimrc' -c PlugInstall! -c qa" + # shell: "vim +'silent! PlugInstall!' +q!" + ignore_errors: yes +- name: Update plugins + shell: "vim -E -s -c 'source {{ local_path }}/.vimrc' -c PlugUpdate! -c qa" + # shell: "vim +'silent! PlugUpdate!' +q!" + ignore_errors: yes diff --git a/roles/youcompleteme/tasks/main.yml b/roles/youcompleteme/tasks/main.yml new file mode 100644 index 0000000..4f583f6 --- /dev/null +++ b/roles/youcompleteme/tasks/main.yml @@ -0,0 +1,29 @@ +- name: Check if cargo is installed + shell: command -v cargo >/dev/null 2>&1 + register: cargo_exists + ignore_errors: yes +- name: Check if go is installed + shell: command -v go >/dev/null 2>&1 + register: go_exists + ignore_errors: yes +# TODO: Figure out how to transform cargo_flag.rc == 0 && echo --racer-completer +- name: Install youcompleteme + shell: + cmd: ./install.py + chdir: "~/.vim/plugged/YouCompleteMe" + when: "go_exists.rc != 0 and cargo_exists.rc != 0" +- name: Install youcompleteme with rust + shell: + cmd: ./install.py --racer-completer + chdir: "~/.vim/plugged/YouCompleteMe" + when: "go_exists.rc != 0 and cargo_exists.rc == 0" +- name: Install youcompleteme with go + shell: + cmd: ./install.py --gocode-completer + chdir: "~/.vim/plugged/YouCompleteMe" + when: "go_exists.rc == 0 and cargo_exists.rc != 0" +- name: Install youcompleteme with rust and go + shell: + cmd: ./install.py --gocode-completer --racer-completer + chdir: "~/.vim/plugged/YouCompleteMe" + when: "go_exists.rc == 0 and cargo_exists.rc == 0" diff --git a/i3/G2-status.conf b/skel/.i3/i3/G2-status.conf similarity index 100% rename from i3/G2-status.conf rename to skel/.i3/i3/G2-status.conf diff --git a/i3/MGen-status.conf b/skel/.i3/i3/MGen-status.conf similarity index 100% rename from i3/MGen-status.conf rename to skel/.i3/i3/MGen-status.conf diff --git a/i3/MMLin-status.conf b/skel/.i3/i3/MMLin-status.conf similarity index 100% rename from i3/MMLin-status.conf rename to skel/.i3/i3/MMLin-status.conf diff --git a/i3/run.sh b/skel/.i3/i3/run.sh similarity index 100% rename from i3/run.sh rename to skel/.i3/i3/run.sh diff --git a/zsh/borg.zsh b/skel/.zsh/borg.zsh similarity index 100% rename from zsh/borg.zsh rename to skel/.zsh/borg.zsh diff --git a/zsh/completion.zsh b/skel/.zsh/completion.zsh similarity index 100% rename from zsh/completion.zsh rename to skel/.zsh/completion.zsh diff --git a/zsh/config.zsh b/skel/.zsh/config.zsh similarity index 100% rename from zsh/config.zsh rename to skel/.zsh/config.zsh diff --git a/zsh/history.zsh.bak b/skel/.zsh/history.zsh.bak similarity index 100% rename from zsh/history.zsh.bak rename to skel/.zsh/history.zsh.bak diff --git a/zsh/key-bindings.zsh b/skel/.zsh/key-bindings.zsh similarity index 100% rename from zsh/key-bindings.zsh rename to skel/.zsh/key-bindings.zsh diff --git a/zsh/misc.zsh b/skel/.zsh/misc.zsh similarity index 100% rename from zsh/misc.zsh rename to skel/.zsh/misc.zsh diff --git a/zsh/security.zsh b/skel/.zsh/security.zsh similarity index 100% rename from zsh/security.zsh rename to skel/.zsh/security.zsh diff --git a/zsh/spectrum.zsh b/skel/.zsh/spectrum.zsh similarity index 100% rename from zsh/spectrum.zsh rename to skel/.zsh/spectrum.zsh diff --git a/zsh/styles.zsh b/skel/.zsh/styles.zsh similarity index 100% rename from zsh/styles.zsh rename to skel/.zsh/styles.zsh diff --git a/zsh/sudo.zsh b/skel/.zsh/sudo.zsh similarity index 100% rename from zsh/sudo.zsh rename to skel/.zsh/sudo.zsh diff --git a/zsh/theme-and-appearance.zsh b/skel/.zsh/theme-and-appearance.zsh similarity index 100% rename from zsh/theme-and-appearance.zsh rename to skel/.zsh/theme-and-appearance.zsh diff --git a/sync.sh b/sync.sh new file mode 100755 index 0000000..396ec9a --- /dev/null +++ b/sync.sh @@ -0,0 +1,6 @@ +#!/bin/bash +ansible-playbook -i hosts main.yml --tags default +# Could also sync vim: +# ansible-playbook -i hosts main.yml --tags default,vim +# Could also secure system +# ansible-playbook -i hosts --ask-become-pass main.yml --tags default,vim,secure