From e63efbcb8a5dac64f5df7cbf7168e8f9b5771be8 Mon Sep 17 00:00:00 2001 From: Anthony Cicchetti Date: Wed, 31 Jul 2019 01:27:13 +0000 Subject: [PATCH] ansible_roles_rework (#2) --- playbooks/common.yml | 4 -- playbooks/fedora.yml | 6 -- playbooks/input.yml | 21 +++++++ playbooks/launch | 33 +++++----- playbooks/main.yml | 54 ++++++++++++++++ playbooks/osx.yml | 5 -- playbooks/roles/alacritty/defaults/main.yml | 2 + .../tasks/main.yml} | 0 playbooks/roles/anyenv/defaults/main.yml | 2 + .../anyenv.yml => anyenv/tasks/main.yml} | 0 playbooks/roles/arch/defaults/main.yml | 2 + playbooks/roles/arch/tasks/main.yml | 57 +++++++++++++++++ playbooks/roles/common/defaults/main.yml | 4 ++ playbooks/roles/common/tasks/main.yml | 61 ++++++++++++------- playbooks/roles/fedora/defaults/main.yml | 2 + playbooks/roles/fedora/tasks/main.yml | 23 ++++--- playbooks/roles/git/defaults/main.yml | 2 + playbooks/roles/git/tasks/main.yml | 9 +++ playbooks/roles/hyper/defaults/main.yml | 2 + .../tasks/hyper.yml => hyper/tasks/main.yml} | 0 playbooks/roles/kerl/defaults/main.yml | 2 + .../tasks/kerl.yml => kerl/tasks/main.yml} | 0 playbooks/roles/macos/defaults/main.yml | 2 + playbooks/roles/{osx => macos}/tasks/main.yml | 0 playbooks/roles/neovim/defaults/main.yml | 2 + .../neovim.yml => neovim/tasks/main.yml} | 0 playbooks/roles/rust/defaults/main.yml | 3 + .../tasks/rust.yml => rust/tasks/main.yml} | 12 ++++ playbooks/roles/sdkman/defaults/main.yml | 2 + playbooks/roles/sdkman/tasks/main.yml | 5 ++ playbooks/roles/tmux/defaults/main.yml | 2 + .../tasks/tmux.yml => tmux/tasks/main.yml} | 0 playbooks/roles/ubuntu/defaults/main.yml | 2 + playbooks/roles/ubuntu/tasks/main.yml | 34 +++++++++-- playbooks/roles/zsh/defaults/main.yml | 2 + playbooks/roles/zsh/tasks/main.yml | 12 ++++ 36 files changed, 304 insertions(+), 65 deletions(-) delete mode 100644 playbooks/common.yml delete mode 100644 playbooks/fedora.yml create mode 100644 playbooks/input.yml create mode 100644 playbooks/main.yml delete mode 100644 playbooks/osx.yml create mode 100644 playbooks/roles/alacritty/defaults/main.yml rename playbooks/roles/{common/tasks/alacritty.yml => alacritty/tasks/main.yml} (100%) create mode 100644 playbooks/roles/anyenv/defaults/main.yml rename playbooks/roles/{common/tasks/anyenv.yml => anyenv/tasks/main.yml} (100%) create mode 100644 playbooks/roles/arch/defaults/main.yml create mode 100644 playbooks/roles/common/defaults/main.yml create mode 100644 playbooks/roles/fedora/defaults/main.yml create mode 100644 playbooks/roles/git/defaults/main.yml create mode 100644 playbooks/roles/git/tasks/main.yml create mode 100644 playbooks/roles/hyper/defaults/main.yml rename playbooks/roles/{common/tasks/hyper.yml => hyper/tasks/main.yml} (100%) create mode 100644 playbooks/roles/kerl/defaults/main.yml rename playbooks/roles/{common/tasks/kerl.yml => kerl/tasks/main.yml} (100%) create mode 100644 playbooks/roles/macos/defaults/main.yml rename playbooks/roles/{osx => macos}/tasks/main.yml (100%) create mode 100644 playbooks/roles/neovim/defaults/main.yml rename playbooks/roles/{common/tasks/neovim.yml => neovim/tasks/main.yml} (100%) create mode 100644 playbooks/roles/rust/defaults/main.yml rename playbooks/roles/{common/tasks/rust.yml => rust/tasks/main.yml} (81%) create mode 100644 playbooks/roles/sdkman/defaults/main.yml create mode 100644 playbooks/roles/sdkman/tasks/main.yml create mode 100644 playbooks/roles/tmux/defaults/main.yml rename playbooks/roles/{common/tasks/tmux.yml => tmux/tasks/main.yml} (100%) create mode 100644 playbooks/roles/ubuntu/defaults/main.yml create mode 100644 playbooks/roles/zsh/defaults/main.yml create mode 100644 playbooks/roles/zsh/tasks/main.yml diff --git a/playbooks/common.yml b/playbooks/common.yml deleted file mode 100644 index 4b1ca99..0000000 --- a/playbooks/common.yml +++ /dev/null @@ -1,4 +0,0 @@ ---- -- hosts: local - roles: - - role: common diff --git a/playbooks/fedora.yml b/playbooks/fedora.yml deleted file mode 100644 index fc7bd01..0000000 --- a/playbooks/fedora.yml +++ /dev/null @@ -1,6 +0,0 @@ ---- -- hosts: local - roles: - - role: fedora - - role: common - diff --git a/playbooks/input.yml b/playbooks/input.yml new file mode 100644 index 0000000..eaad757 --- /dev/null +++ b/playbooks/input.yml @@ -0,0 +1,21 @@ +--- +- name: Ask user for the input + hosts: localhost + tags: always + vars_prompt: + - name: _dev_machine + prompt: "Is this a developer's machine?" + private: no + default: "yes" + - name: _rust_extras + prompt: "Do you want to install rust extras?" + private: no + default: "no" + tasks: + - block: + - name: Set dev machine fact + set_fact: + _dev_machine: "{{ _dev_machine }}" + - name: Set rust extras fact + set_fact: + _rust_extras: "{{ _rust_extras }}" diff --git a/playbooks/launch b/playbooks/launch index 4875f83..37ca2fe 100755 --- a/playbooks/launch +++ b/playbooks/launch @@ -1,19 +1,24 @@ -#!/usr/bin/env zsh +#!/usr/bin/env bash set -ex PATH="$PATH:$HOME/.local/bin" -if [[ `uname` == "Linux" ]]; then - if [[ -f /etc/pacman.conf ]]; then - ansible-playbook -i inventory arch.yml - elif [[ -f /etc/lsb-release ]]; then - ansible-playbook -i inventory ubuntu.yml - elif [[ -f /etc/fedora-release ]]; then - ansible-playbook -i inventory fedora.yml - else - echo "can't autodetermine distro, just running default inventory" - ansible-playbook -i inventory common.yml - fi -else - ansible-playbook -i inventory osx.yml +if [[ $(command -v ansible) ]]; then + printf "ansible already installed" +elif [[ $(uname) == "Linux" ]]; then + if [[ $(command -v pacman) ]]; then + sudo pacman -Sy --noconfirm ansible + elif [[ $(command -v apt) ]]; then + sudo apt install -y ansible python3-apt + # ubuntu doesn't create a /usr/bin/python, so we have to make one ourselves + ln -s /usr/bin/python3 /usr/bin/python + elif [[ $(command -v dnf) ]]; then + sudo dnf install ansible -y + fi +elif [[ $(uname) == "Darwin" ]]; then + # Yeah, raw brew install + /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" + /usr/local/bin/brew install ansible fi + +ansible-playbook -i inventory main.yml diff --git a/playbooks/main.yml b/playbooks/main.yml new file mode 100644 index 0000000..f6ff437 --- /dev/null +++ b/playbooks/main.yml @@ -0,0 +1,54 @@ +--- +- name: Include prompts playbook + import_playbook: input.yml + +- name: Find out what kind of host we are + hosts: all + tasks: + - name: Classify host + group_by: + key: os_{{ ansible_facts['distribution'] }} + +- hosts: os_MacOSX + gather_facts: True + roles: + - role: macos + vars: + - dev_machine: "{{ _dev_machine }}" + - role: common + vars: + - dev_machine: "{{ _dev_machine }}" + - rust_extras: "{{ _rust_extras }}" + +- hosts: os_Fedora + gather_facts: True + roles: + - role: fedora + vars: + dev_machine: "{{ _dev_machine }}" + - role: common + vars: + - dev_machine: "{{ _dev_machine }}" + - rust_extras: "{{ _rust_extras }}" + +- hosts: os_Archlinux + gather_facts: True + roles: + - role: arch + vars: + dev_machine: "{{ _dev_machine }}" + - role: common + vars: + - dev_machine: "{{ _dev_machine }}" + - rust_extras: "{{ _rust_extras }}" + +- hosts: os_Ubuntu + gather_facts: False + roles: + - role: ubuntu + vars: + dev_machine: "{{ _dev_machine }}" + - role: common + vars: + - dev_machine: "{{ _dev_machine }}" + - rust_extras: "{{ _rust_extras }}" diff --git a/playbooks/osx.yml b/playbooks/osx.yml deleted file mode 100644 index d77889a..0000000 --- a/playbooks/osx.yml +++ /dev/null @@ -1,5 +0,0 @@ ---- -- hosts: local - roles: - - role: common - - role: osx diff --git a/playbooks/roles/alacritty/defaults/main.yml b/playbooks/roles/alacritty/defaults/main.yml new file mode 100644 index 0000000..3660559 --- /dev/null +++ b/playbooks/roles/alacritty/defaults/main.yml @@ -0,0 +1,2 @@ +--- +dev_machine: yes diff --git a/playbooks/roles/common/tasks/alacritty.yml b/playbooks/roles/alacritty/tasks/main.yml similarity index 100% rename from playbooks/roles/common/tasks/alacritty.yml rename to playbooks/roles/alacritty/tasks/main.yml diff --git a/playbooks/roles/anyenv/defaults/main.yml b/playbooks/roles/anyenv/defaults/main.yml new file mode 100644 index 0000000..3660559 --- /dev/null +++ b/playbooks/roles/anyenv/defaults/main.yml @@ -0,0 +1,2 @@ +--- +dev_machine: yes diff --git a/playbooks/roles/common/tasks/anyenv.yml b/playbooks/roles/anyenv/tasks/main.yml similarity index 100% rename from playbooks/roles/common/tasks/anyenv.yml rename to playbooks/roles/anyenv/tasks/main.yml diff --git a/playbooks/roles/arch/defaults/main.yml b/playbooks/roles/arch/defaults/main.yml new file mode 100644 index 0000000..3660559 --- /dev/null +++ b/playbooks/roles/arch/defaults/main.yml @@ -0,0 +1,2 @@ +--- +dev_machine: yes diff --git a/playbooks/roles/arch/tasks/main.yml b/playbooks/roles/arch/tasks/main.yml index 8b13789..39d9fb0 100644 --- a/playbooks/roles/arch/tasks/main.yml +++ b/playbooks/roles/arch/tasks/main.yml @@ -1 +1,58 @@ +--- +- name: Update Packages + become: yes + become_method: sudo + pacman: + update_cache: yes + upgrade: yes +- name: Install basics + become: yes + become_method: sudo + pacman: + name: + - zsh + - git + - cmake + - tmux + - gnupg + - neovim + state: latest + +- name: Install Development Tools + when: + - dev_machine == true + become: yes + become_method: sudo + pacman: + name: + - base-devel + - openssl + state: latest + +- name: clone yay from github + when: + - dev_machine == true + become: false + git: + repo: https://aur.archlinux.org/yay.git + dest: /tmp/yay + version: master + update: yes + # notify: makepkg -si + +- name: makepkg --noconfirm -si + when: + - dev_machine == true + become: false + command: makepkg --noconfirm -si + args: + chdir: /tmp/yay + creates: /usr/bin/yay + +- name: Install hstr + when: + - dev_machine == true + command: yay -Sy --noconfirm --needed --cleanafter hstr + args: + creates: /usr/local/bin/hstr diff --git a/playbooks/roles/common/defaults/main.yml b/playbooks/roles/common/defaults/main.yml new file mode 100644 index 0000000..ff17851 --- /dev/null +++ b/playbooks/roles/common/defaults/main.yml @@ -0,0 +1,4 @@ +--- +user_name: "Anthony Cicchetti" +user_email: "anthony@anthonycicchetti.com" +dev_machine: yes diff --git a/playbooks/roles/common/tasks/main.yml b/playbooks/roles/common/tasks/main.yml index e8008b2..9385fe8 100644 --- a/playbooks/roles/common/tasks/main.yml +++ b/playbooks/roles/common/tasks/main.yml @@ -1,28 +1,43 @@ --- -- import_tasks: anyenv.yml -- import_tasks: neovim.yml -- import_tasks: rust.yml -- import_tasks: tmux.yml -- import_tasks: alacritty.yml -- import_tasks: hyper.yml -- import_tasks: kerl.yml +- import_role: + name: anyenv + when: + - dev_machine == true +- import_role: + name: neovim +- import_role: + name: rust + vars: + - rust_extras: "{{ _rust_extras }}" + when: + - dev_machine == true +- import_role: + name: tmux + when: + - dev_machine == true +- import_role: + name: alacritty + when: + - dev_machine == true +- import_role: + name: hyper + when: + - dev_machine == true +- import_role: + name: kerl + when: + - dev_machine == true +- import_role: + name: git + when: + - dev_machine == true +- import_role: + name: zsh +- import_role: + name: sdkman + when: + - dev_machine == true -- name: Install antigen - git: - repo: https://github.com/zsh-users/antigen.git - dest: ~/.antigen - -- name: Symlink zshrc - file: - src: ~/.dotfiles/zsh/zshrc - dest: ~/.zshrc - state: link - force: yes - -- name: Install SDKMan - shell: curl -s https://get.sdkman.io | zsh - args: - creates: ~/.sdkman/bin/sdkman-init.sh - name: Create ~/bin directory file: diff --git a/playbooks/roles/fedora/defaults/main.yml b/playbooks/roles/fedora/defaults/main.yml new file mode 100644 index 0000000..3660559 --- /dev/null +++ b/playbooks/roles/fedora/defaults/main.yml @@ -0,0 +1,2 @@ +--- +dev_machine: yes diff --git a/playbooks/roles/fedora/tasks/main.yml b/playbooks/roles/fedora/tasks/main.yml index 7c52105..7a29f7f 100644 --- a/playbooks/roles/fedora/tasks/main.yml +++ b/playbooks/roles/fedora/tasks/main.yml @@ -6,23 +6,28 @@ name: "*" state: latest -- name: Install neovim +- name: Install basics become: yes become_method: sudo dnf: - name: "neovim" + name: + - zsh + - git + - cmake + - tmux + - gpg + - neovim + - hstr state: latest - name: Install @development-tools + when: + - dev_machine == true become: yes become_method: sudo dnf: - name: "@development-tools" + name: + - "@development-tools" + - openssl-devel state: latest -- name: Install openssl-dev - become: yes - become_method: sudo - dnf: - name: "openssl-devel" - state: latest diff --git a/playbooks/roles/git/defaults/main.yml b/playbooks/roles/git/defaults/main.yml new file mode 100644 index 0000000..3660559 --- /dev/null +++ b/playbooks/roles/git/defaults/main.yml @@ -0,0 +1,2 @@ +--- +dev_machine: yes diff --git a/playbooks/roles/git/tasks/main.yml b/playbooks/roles/git/tasks/main.yml new file mode 100644 index 0000000..363273b --- /dev/null +++ b/playbooks/roles/git/tasks/main.yml @@ -0,0 +1,9 @@ +--- +- name: Set up gitconfig + shell: git config --global user.name "{{user_name}}" && git config --global user.email {{user_email}} + args: + creates: ~/.gitconfig + +- name: Add git pushall alias + shell: git config --global alias.pushall '!git remote | xargs -L1 git push --all' + diff --git a/playbooks/roles/hyper/defaults/main.yml b/playbooks/roles/hyper/defaults/main.yml new file mode 100644 index 0000000..3660559 --- /dev/null +++ b/playbooks/roles/hyper/defaults/main.yml @@ -0,0 +1,2 @@ +--- +dev_machine: yes diff --git a/playbooks/roles/common/tasks/hyper.yml b/playbooks/roles/hyper/tasks/main.yml similarity index 100% rename from playbooks/roles/common/tasks/hyper.yml rename to playbooks/roles/hyper/tasks/main.yml diff --git a/playbooks/roles/kerl/defaults/main.yml b/playbooks/roles/kerl/defaults/main.yml new file mode 100644 index 0000000..3660559 --- /dev/null +++ b/playbooks/roles/kerl/defaults/main.yml @@ -0,0 +1,2 @@ +--- +dev_machine: yes diff --git a/playbooks/roles/common/tasks/kerl.yml b/playbooks/roles/kerl/tasks/main.yml similarity index 100% rename from playbooks/roles/common/tasks/kerl.yml rename to playbooks/roles/kerl/tasks/main.yml diff --git a/playbooks/roles/macos/defaults/main.yml b/playbooks/roles/macos/defaults/main.yml new file mode 100644 index 0000000..3660559 --- /dev/null +++ b/playbooks/roles/macos/defaults/main.yml @@ -0,0 +1,2 @@ +--- +dev_machine: yes diff --git a/playbooks/roles/osx/tasks/main.yml b/playbooks/roles/macos/tasks/main.yml similarity index 100% rename from playbooks/roles/osx/tasks/main.yml rename to playbooks/roles/macos/tasks/main.yml diff --git a/playbooks/roles/neovim/defaults/main.yml b/playbooks/roles/neovim/defaults/main.yml new file mode 100644 index 0000000..3660559 --- /dev/null +++ b/playbooks/roles/neovim/defaults/main.yml @@ -0,0 +1,2 @@ +--- +dev_machine: yes diff --git a/playbooks/roles/common/tasks/neovim.yml b/playbooks/roles/neovim/tasks/main.yml similarity index 100% rename from playbooks/roles/common/tasks/neovim.yml rename to playbooks/roles/neovim/tasks/main.yml diff --git a/playbooks/roles/rust/defaults/main.yml b/playbooks/roles/rust/defaults/main.yml new file mode 100644 index 0000000..fc2c359 --- /dev/null +++ b/playbooks/roles/rust/defaults/main.yml @@ -0,0 +1,3 @@ +--- +dev_machine: yes +rust_extras: no diff --git a/playbooks/roles/common/tasks/rust.yml b/playbooks/roles/rust/tasks/main.yml similarity index 81% rename from playbooks/roles/common/tasks/rust.yml rename to playbooks/roles/rust/tasks/main.yml index f0eefbe..681c468 100644 --- a/playbooks/roles/common/tasks/rust.yml +++ b/playbooks/roles/rust/tasks/main.yml @@ -14,28 +14,40 @@ shell: ~/.cargo/bin/cargo install ripgrep args: creates: ~/.cargo/bin/rg + when: + - rust_extras == true - name: Install exa shell: ~/.cargo/bin/cargo install exa args: creates: ~/.cargo/bin/exa + when: + - rust_extras == true - name: Install just shell: ~/.cargo/bin/cargo install just args: creates: ~/.cargo/bin/just + when: + - rust_extras == true - name: Install cargo-update shell: ~/.cargo/bin/cargo install cargo-update args: creates: ~/.cargo/bin/cargo-install-update + when: + - rust_extras == true - name: Install bat shell: ~/.cargo/bin/cargo install bat args: creates: ~/.cargo/bin/bat + when: + - rust_extras == true - name: Install rls shell: ~/.cargo/bin/rustup component add rls-preview rust-analysis rust-src args: creates: ~/.cargo/bin/rls + when: + - rust_extras == true diff --git a/playbooks/roles/sdkman/defaults/main.yml b/playbooks/roles/sdkman/defaults/main.yml new file mode 100644 index 0000000..3660559 --- /dev/null +++ b/playbooks/roles/sdkman/defaults/main.yml @@ -0,0 +1,2 @@ +--- +dev_machine: yes diff --git a/playbooks/roles/sdkman/tasks/main.yml b/playbooks/roles/sdkman/tasks/main.yml new file mode 100644 index 0000000..4a3b98a --- /dev/null +++ b/playbooks/roles/sdkman/tasks/main.yml @@ -0,0 +1,5 @@ +--- +- name: Install SDKMan + shell: curl -s https://get.sdkman.io | zsh + args: + creates: ~/.sdkman/bin/sdkman-init.sh diff --git a/playbooks/roles/tmux/defaults/main.yml b/playbooks/roles/tmux/defaults/main.yml new file mode 100644 index 0000000..3660559 --- /dev/null +++ b/playbooks/roles/tmux/defaults/main.yml @@ -0,0 +1,2 @@ +--- +dev_machine: yes diff --git a/playbooks/roles/common/tasks/tmux.yml b/playbooks/roles/tmux/tasks/main.yml similarity index 100% rename from playbooks/roles/common/tasks/tmux.yml rename to playbooks/roles/tmux/tasks/main.yml diff --git a/playbooks/roles/ubuntu/defaults/main.yml b/playbooks/roles/ubuntu/defaults/main.yml new file mode 100644 index 0000000..3660559 --- /dev/null +++ b/playbooks/roles/ubuntu/defaults/main.yml @@ -0,0 +1,2 @@ +--- +dev_machine: yes diff --git a/playbooks/roles/ubuntu/tasks/main.yml b/playbooks/roles/ubuntu/tasks/main.yml index fa49617..f4e7c63 100644 --- a/playbooks/roles/ubuntu/tasks/main.yml +++ b/playbooks/roles/ubuntu/tasks/main.yml @@ -2,20 +2,46 @@ become: yes become_method: sudo apt: + force_apt_get: yes name: "*" state: latest -- name: Install neovim +- name: Install essentials become: yes become_method: sudo apt: - name: "neovim" + force_apt_get: yes + name: + - neovim + - git + - zsh + - tmux + - gpg + - software-properties-common state: latest -- name: Install build-essential +- name: Install Development Tools become: yes become_method: sudo apt: - name: "build-essential" + force_apt_get: yes + name: + - build-essential + - cmake + - libssl-dev + - pkg-config state: latest +# - name: Add hstr repo +# become: yes +# become_method: sudo +# command: "add-apt-repository ppa:acicchetti/utils" + +# - name: Install hstr +# become: yes +# become_method: sudo +# apt: +# force_apt_get: yes +# name: hstr +# state: latest +# update_cache: yes diff --git a/playbooks/roles/zsh/defaults/main.yml b/playbooks/roles/zsh/defaults/main.yml new file mode 100644 index 0000000..3660559 --- /dev/null +++ b/playbooks/roles/zsh/defaults/main.yml @@ -0,0 +1,2 @@ +--- +dev_machine: yes diff --git a/playbooks/roles/zsh/tasks/main.yml b/playbooks/roles/zsh/tasks/main.yml new file mode 100644 index 0000000..6ca21b3 --- /dev/null +++ b/playbooks/roles/zsh/tasks/main.yml @@ -0,0 +1,12 @@ +--- +- name: Install antigen + git: + repo: https://github.com/zsh-users/antigen.git + dest: ~/.antigen + +- name: Symlink zshrc + file: + src: ~/.dotfiles/zsh/zshrc + dest: ~/.zshrc + state: link + force: yes