From 178c51628bf4ebc78bd587f985ff83d75f68f6a7 Mon Sep 17 00:00:00 2001 From: Marc Cataford Date: Sat, 28 Sep 2024 23:31:23 -0400 Subject: [PATCH] refactor: split into roles --- README.md | 12 +--- home.yml | 7 ++ playbook.yml | 64 ------------------- .../managed-blocks/files}/extras.vim | 0 .../managed-blocks/files}/gh-dash.yml | 0 .../managed-blocks/files}/shell_extras | 0 .../managed-blocks/files}/starship.toml | 0 roles/managed-blocks/tasks/main.yml | 29 +++++++++ roles/tool-config/tasks/main.yml | 5 ++ roles/ubuntu/tasks/main.yml | 28 ++++++++ setup.sh => run.sh | 2 +- 11 files changed, 72 insertions(+), 75 deletions(-) create mode 100644 home.yml delete mode 100644 playbook.yml rename {files => roles/managed-blocks/files}/extras.vim (100%) rename {files => roles/managed-blocks/files}/gh-dash.yml (100%) rename {files => roles/managed-blocks/files}/shell_extras (100%) rename {files => roles/managed-blocks/files}/starship.toml (100%) create mode 100644 roles/managed-blocks/tasks/main.yml create mode 100644 roles/tool-config/tasks/main.yml create mode 100644 roles/ubuntu/tasks/main.yml rename setup.sh => run.sh (75%) diff --git a/README.md b/README.md index 794708f..5d85828 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,5 @@ # 🥫Environment-in-a-can -Environment tweaks for everyday happiness. +Environment tweaks for (my) everyday happiness. -## Setup - -Just run `./setup.sh`! - -_Note_: This expects `pipx` to be installed on your system. - -## Contributing - -I'm not currently looking for contributions since this is mainly about standardizing my own setup across machines. +Do the thing, it will do the needful: `./run.sh ` diff --git a/home.yml b/home.yml new file mode 100644 index 0000000..1f0ab2d --- /dev/null +++ b/home.yml @@ -0,0 +1,7 @@ +--- +- name: Local environment + hosts: localhost + roles: + - ubuntu + - managed-blocks + - tool-config diff --git a/playbook.yml b/playbook.yml deleted file mode 100644 index 90b6a4a..0000000 --- a/playbook.yml +++ /dev/null @@ -1,64 +0,0 @@ ---- -- name: Local environment - hosts: localhost - - tasks: - - name: Ensure system up-to-date - become: true - apt: - update_cache: true - upgrade: "yes" - - name: Install terminal & shell - apt: - pkg: - - zsh - - tmux - - name: Install OMZsh - shell: | - sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" - args: - creates: "{{ lookup('ansible.builtin.env', 'HOME') }}/.oh-my-zsh" - - name: Install CLI tooling - apt: - pkg: - - shellcheck - - gh - - name: Install gh CLI extensions (gh-dash) - command: gh extension install dlvhdr/gh-dash - - name: Install DB-related tooling - apt: - pkg: - - postgresql - - postgresql-contrib - - name: Add zsh managed block - blockinfile: - path: "{{ lookup('ansible.builtin.env', 'HOME') }}/.zshrc" - marker: "# Marc's env managed block - {mark}" - block: "{{ lookup('ansible.builtin.file', 'files/shell_extras') }}" - - name: Add nvim managed block - blockinfile: - path: "{{ lookup('ansible.builtin.env', 'HOME') }}/.config/nvim/init.vim" - marker: "\" Marc's env managed block - {mark}" - block: "{{ lookup('ansible.builtin.file', 'files/extras.vim') }}" - - name: Add starship managed block - blockinfile: - path: "{{ lookup('ansible.builtin.env', 'HOME') }}/.config/starship.toml" - marker: "# Marc's env managed block - {mark}" - block: "{{ lookup('ansible.builtin.file', 'files/starship.toml') }}" - - name: Ensure gh-dash config directory exists - file: - path: "{{ lookup('ansible.builtin.env', 'HOME') }}/.config/gh-dash" - state: directory - - name: Ensure gh-dash config exists - file: - path: "{{ lookup('ansible.builtin.env', 'HOME') }}/.config/gh-dash/config.yml" - state: touch - - name: Add gh-dash configuration managed block - blockinfile: - path: "{{ lookup('ansible.builtin.env', 'HOME') }}/.config/gh-dash/config.yml" - marker: "# Marc's env managed block - {mark}" - block: "{{ lookup('ansible.builtin.file', 'files/gh-dash.yml') }}" - - name: Configure git - shell: | - git config --global commit.gpgsign true - git config --global fetch.prune true diff --git a/files/extras.vim b/roles/managed-blocks/files/extras.vim similarity index 100% rename from files/extras.vim rename to roles/managed-blocks/files/extras.vim diff --git a/files/gh-dash.yml b/roles/managed-blocks/files/gh-dash.yml similarity index 100% rename from files/gh-dash.yml rename to roles/managed-blocks/files/gh-dash.yml diff --git a/files/shell_extras b/roles/managed-blocks/files/shell_extras similarity index 100% rename from files/shell_extras rename to roles/managed-blocks/files/shell_extras diff --git a/files/starship.toml b/roles/managed-blocks/files/starship.toml similarity index 100% rename from files/starship.toml rename to roles/managed-blocks/files/starship.toml diff --git a/roles/managed-blocks/tasks/main.yml b/roles/managed-blocks/tasks/main.yml new file mode 100644 index 0000000..3ffc387 --- /dev/null +++ b/roles/managed-blocks/tasks/main.yml @@ -0,0 +1,29 @@ +--- +- name: Add zsh managed block + blockinfile: + path: "{{ lookup('ansible.builtin.env', 'HOME') }}/.zshrc" + marker: "# Marc's env managed block - {mark}" + block: "{{ lookup('ansible.builtin.file', 'files/shell_extras') }}" +- name: Add nvim managed block + blockinfile: + path: "{{ lookup('ansible.builtin.env', 'HOME') }}/.config/nvim/init.vim" + marker: "\" Marc's env managed block - {mark}" + block: "{{ lookup('ansible.builtin.file', 'files/extras.vim') }}" +- name: Add starship managed block + blockinfile: + path: "{{ lookup('ansible.builtin.env', 'HOME') }}/.config/starship.toml" + marker: "# Marc's env managed block - {mark}" + block: "{{ lookup('ansible.builtin.file', 'files/starship.toml') }}" +- name: Ensure gh-dash config directory exists + file: + path: "{{ lookup('ansible.builtin.env', 'HOME') }}/.config/gh-dash" + state: directory +- name: Ensure gh-dash config exists + file: + path: "{{ lookup('ansible.builtin.env', 'HOME') }}/.config/gh-dash/config.yml" + state: touch +- name: Add gh-dash configuration managed block + blockinfile: + path: "{{ lookup('ansible.builtin.env', 'HOME') }}/.config/gh-dash/config.yml" + marker: "# Marc's env managed block - {mark}" + block: "{{ lookup('ansible.builtin.file', 'files/gh-dash.yml') }}" diff --git a/roles/tool-config/tasks/main.yml b/roles/tool-config/tasks/main.yml new file mode 100644 index 0000000..027792f --- /dev/null +++ b/roles/tool-config/tasks/main.yml @@ -0,0 +1,5 @@ +--- +- name: Configure git + shell: | + git config --global commit.gpgsign true + git config --global fetch.prune true diff --git a/roles/ubuntu/tasks/main.yml b/roles/ubuntu/tasks/main.yml new file mode 100644 index 0000000..5091ebf --- /dev/null +++ b/roles/ubuntu/tasks/main.yml @@ -0,0 +1,28 @@ +--- +- name: Ensure system up-to-date + become: true + apt: + update_cache: true + upgrade: "yes" +- name: Install terminal & shell + apt: + pkg: + - zsh + - tmux +- name: Install OMZsh + shell: | + sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" + args: + creates: "{{ lookup('ansible.builtin.env', 'HOME') }}/.oh-my-zsh" +- name: Install CLI tooling + apt: + pkg: + - shellcheck + - gh +- name: Install gh CLI extensions (gh-dash) + command: gh extension install dlvhdr/gh-dash +- name: Install DB-related tooling + apt: + pkg: + - postgresql + - postgresql-contrib diff --git a/setup.sh b/run.sh similarity index 75% rename from setup.sh rename to run.sh index 54f7c65..1779863 100755 --- a/setup.sh +++ b/run.sh @@ -6,4 +6,4 @@ if [[ -z "$(command -v pipx)" ]]; then fi pipx install "ansible~=10.0" -ansible-playbook -v --ask-become-pass ./playbook.yml +ansible-playbook -v --ask-become-pass "$1"