ansible_roles_rework #2

Merged
anthonycicc merged 9 commits from ansible_roles_rework into master 2019-07-30 21:27:14 -04:00
36 changed files with 304 additions and 65 deletions
playbooks
common.ymlfedora.ymlinput.ymllaunchmain.ymlosx.yml
roles
alacritty
defaults
tasks
anyenv
defaults
tasks
arch
defaults
tasks
common
defaults
tasks
fedora
defaults
tasks
git
defaults
tasks
hyper
defaults
tasks
kerl
defaults
tasks
macos
defaults
tasks
neovim
defaults
tasks
rust
defaults
tasks
sdkman
defaults
tasks
tmux
defaults
tasks
ubuntu
defaults
tasks
zsh
defaults
tasks

View file

@ -1,4 +0,0 @@
---
- hosts: local
roles:
- role: common

View file

@ -1,6 +0,0 @@
---
- hosts: local
roles:
- role: fedora
- role: common

21
playbooks/input.yml Normal file
View file

@ -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 }}"

View file

@ -1,19 +1,24 @@
#!/usr/bin/env zsh #!/usr/bin/env bash
set -ex set -ex
PATH="$PATH:$HOME/.local/bin" PATH="$PATH:$HOME/.local/bin"
if [[ `uname` == "Linux" ]]; then if [[ $(command -v ansible) ]]; then
if [[ -f /etc/pacman.conf ]]; then printf "ansible already installed"
ansible-playbook -i inventory arch.yml elif [[ $(uname) == "Linux" ]]; then
elif [[ -f /etc/lsb-release ]]; then if [[ $(command -v pacman) ]]; then
ansible-playbook -i inventory ubuntu.yml sudo pacman -Sy --noconfirm ansible
elif [[ -f /etc/fedora-release ]]; then elif [[ $(command -v apt) ]]; then
ansible-playbook -i inventory fedora.yml sudo apt install -y ansible python3-apt
else # ubuntu doesn't create a /usr/bin/python, so we have to make one ourselves
echo "can't autodetermine distro, just running default inventory" ln -s /usr/bin/python3 /usr/bin/python
ansible-playbook -i inventory common.yml elif [[ $(command -v dnf) ]]; then
sudo dnf install ansible -y
fi fi
else elif [[ $(uname) == "Darwin" ]]; then
ansible-playbook -i inventory osx.yml # 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 fi
ansible-playbook -i inventory main.yml

54
playbooks/main.yml Normal file
View file

@ -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 }}"

View file

@ -1,5 +0,0 @@
---
- hosts: local
roles:
- role: common
- role: osx

View file

@ -0,0 +1,2 @@
---
dev_machine: yes

View file

@ -0,0 +1,2 @@
---
dev_machine: yes

View file

@ -0,0 +1,2 @@
---
dev_machine: yes

View file

@ -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

View file

@ -0,0 +1,4 @@
---
user_name: "Anthony Cicchetti"
user_email: "anthony@anthonycicchetti.com"
dev_machine: yes

View file

@ -1,28 +1,43 @@
--- ---
- import_tasks: anyenv.yml - import_role:
- import_tasks: neovim.yml name: anyenv
- import_tasks: rust.yml when:
- import_tasks: tmux.yml - dev_machine == true
- import_tasks: alacritty.yml - import_role:
- import_tasks: hyper.yml name: neovim
- import_tasks: kerl.yml - 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 - name: Create ~/bin directory
file: file:

View file

@ -0,0 +1,2 @@
---
dev_machine: yes

View file

@ -6,23 +6,28 @@
name: "*" name: "*"
state: latest state: latest
- name: Install neovim - name: Install basics
become: yes become: yes
become_method: sudo become_method: sudo
dnf: dnf:
name: "neovim" name:
- zsh
- git
- cmake
- tmux
- gpg
- neovim
- hstr
state: latest state: latest
- name: Install @development-tools - name: Install @development-tools
when:
- dev_machine == true
become: yes become: yes
become_method: sudo become_method: sudo
dnf: dnf:
name: "@development-tools" name:
- "@development-tools"
- openssl-devel
state: latest state: latest
- name: Install openssl-dev
become: yes
become_method: sudo
dnf:
name: "openssl-devel"
state: latest

View file

@ -0,0 +1,2 @@
---
dev_machine: yes

View file

@ -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'

View file

@ -0,0 +1,2 @@
---
dev_machine: yes

View file

@ -0,0 +1,2 @@
---
dev_machine: yes

View file

@ -0,0 +1,2 @@
---
dev_machine: yes

View file

@ -0,0 +1,2 @@
---
dev_machine: yes

View file

@ -0,0 +1,3 @@
---
dev_machine: yes
rust_extras: no

View file

@ -14,28 +14,40 @@
shell: ~/.cargo/bin/cargo install ripgrep shell: ~/.cargo/bin/cargo install ripgrep
args: args:
creates: ~/.cargo/bin/rg creates: ~/.cargo/bin/rg
when:
- rust_extras == true
- name: Install exa - name: Install exa
shell: ~/.cargo/bin/cargo install exa shell: ~/.cargo/bin/cargo install exa
args: args:
creates: ~/.cargo/bin/exa creates: ~/.cargo/bin/exa
when:
- rust_extras == true
- name: Install just - name: Install just
shell: ~/.cargo/bin/cargo install just shell: ~/.cargo/bin/cargo install just
args: args:
creates: ~/.cargo/bin/just creates: ~/.cargo/bin/just
when:
- rust_extras == true
- name: Install cargo-update - name: Install cargo-update
shell: ~/.cargo/bin/cargo install cargo-update shell: ~/.cargo/bin/cargo install cargo-update
args: args:
creates: ~/.cargo/bin/cargo-install-update creates: ~/.cargo/bin/cargo-install-update
when:
- rust_extras == true
- name: Install bat - name: Install bat
shell: ~/.cargo/bin/cargo install bat shell: ~/.cargo/bin/cargo install bat
args: args:
creates: ~/.cargo/bin/bat creates: ~/.cargo/bin/bat
when:
- rust_extras == true
- name: Install rls - name: Install rls
shell: ~/.cargo/bin/rustup component add rls-preview rust-analysis rust-src shell: ~/.cargo/bin/rustup component add rls-preview rust-analysis rust-src
args: args:
creates: ~/.cargo/bin/rls creates: ~/.cargo/bin/rls
when:
- rust_extras == true

View file

@ -0,0 +1,2 @@
---
dev_machine: yes

View file

@ -0,0 +1,5 @@
---
- name: Install SDKMan
shell: curl -s https://get.sdkman.io | zsh
args:
creates: ~/.sdkman/bin/sdkman-init.sh

View file

@ -0,0 +1,2 @@
---
dev_machine: yes

View file

@ -0,0 +1,2 @@
---
dev_machine: yes

View file

@ -2,20 +2,46 @@
become: yes become: yes
become_method: sudo become_method: sudo
apt: apt:
force_apt_get: yes
name: "*" name: "*"
state: latest state: latest
- name: Install neovim - name: Install essentials
become: yes become: yes
become_method: sudo become_method: sudo
apt: apt:
name: "neovim" force_apt_get: yes
name:
- neovim
- git
- zsh
- tmux
- gpg
- software-properties-common
state: latest state: latest
- name: Install build-essential - name: Install Development Tools
become: yes become: yes
become_method: sudo become_method: sudo
apt: apt:
name: "build-essential" force_apt_get: yes
name:
- build-essential
- cmake
- libssl-dev
- pkg-config
state: latest 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

View file

@ -0,0 +1,2 @@
---
dev_machine: yes

View file

@ -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