improved context system

This commit is contained in:
Alice
2024-10-08 20:39:22 +02:00
committed by Morten Olsen
parent c8549b6142
commit 134a64b30a
47 changed files with 264 additions and 338 deletions

View File

@@ -1,9 +0,0 @@
export TMPDIR="${TMPDIR:-/tmp}"
export PATH="$PATH:$HOME/.local/bin"
alias ls=eza
alias cat=bat
alias grep=rg
alias diff=delta
alias less=bat
alias gr='if [ "`git rev-parse --show-cdup`" != "" ]; then cd `git rev-parse --show-cdup`; fi'

View File

@@ -1,3 +0,0 @@
---
dependencies:
- role: base_info

View File

@@ -1,39 +0,0 @@
---
- name: Copy config {{ context }}
tags:
- config
ansible.builtin.file:
mode: "{{ item.mode }}"
path: "{{ home }}/{{ item.path }}"
state: directory
with_community.general.filetree:
- ../files/{{ context }}
loop_control:
label: "{{ item.path }}"
when: item.state == 'directory'
- name: "Copy templates : {{ context }}"
tags:
- config
ansible.builtin.template:
src: "{{ item.src }}"
dest: "{{ home }}/{{ item.path | regex_replace('\\.j2$', '') }}"
mode: "{{ item.mode }}"
with_community.general.filetree:
- ../templates/{{ context }}
loop_control:
label: "{{ item.path }}"
when: item.state == 'file'
- name: Copy config {{ context }}
tags:
- config
ansible.builtin.copy:
src: "{{ item.src }}"
dest: "{{ home }}/{{ item.path }}"
mode: "{{ item.mode }}"
with_community.general.filetree:
- ../files/{{ context }}
loop_control:
label: "{{ item.path }}"
when: item.state == 'file'

View File

@@ -1,34 +0,0 @@
---
- name: "Unload vars : {{ context }}"
ansible.builtin.include_vars: ../vars/empty.yml
tags:
- install
- name: "Load vars : {{ context }}"
ansible.builtin.include_vars: "{{ item }}"
tags:
- install
with_first_found:
- files:
- "{{ ansible_distribution }}-{{ ansible_distribution_release }}.yml"
- "{{ ansible_distribution }}.yml"
- "{{ ansible_os_family }}.yml"
- default.yml
paths: ../vars/{{ context }}
skip: true
- name: "Install dependencies : {{ context }}"
tags:
- install
when: terminal_pkgs
become: "{{ install_with_root }}"
ansible.builtin.package:
name: "{{ terminal_pkgs }}"
- name: "Install casks : {{ context }}"
tags:
- install
when: terminal_casks
community.general.homebrew_cask:
name: "{{ terminal_casks }}"
state: installed

View File

@@ -1,16 +0,0 @@
---
- name: Install context dependencies
ansible.builtin.include_tasks: install.yml
loop: "{{ contexts }}"
loop_control:
loop_var: context
tags:
- config
- name: Configure contexts
ansible.builtin.include_tasks: config.yml
loop: "{{ contexts }}"
loop_control:
loop_var: context
tags:
- config

View File

@@ -1,14 +0,0 @@
---
terminal_pkgs:
- bat
- eza
- direnv
- fzf
- gnupg
- jq
- ripgrep
- neovim
- gh
- tmux
- zoxide
- sshpass

View File

@@ -1,4 +0,0 @@
---
terminal_pkgs: []
terminal_casks: []
terminal_flatpaks: []

View File

@@ -1,5 +0,0 @@
---
terminal_pkgs:
- terraform
- awscli
- copier

View File

@@ -1,8 +1,13 @@
- name: Setting host facts
- name: Setting generic facts
tags: always
ansible.builtin.set_fact:
username: alice
home: "{{ ansible_env.HOME }}"
use_become: true
mac_os: "{{ ansible_distribution == 'MacOSX' }}"
contexts: "{{ ['default'] + (contexts | default([])) }}"
- name: Setting macos facts
tags: always
when: mac_os
ansible.builtin.set_fact:
install_with_root: false

View File

@@ -1,3 +1,4 @@
install_with_root: true
terminal_casks: []
pkgs: []
contexts: {}

View File

@@ -1,5 +1,5 @@
---
- name: Copy config {{ context }}
- name: Setup directories
tags:
- config
ansible.builtin.file:
@@ -7,25 +7,12 @@
path: "{{ home }}/{{ item.path }}"
state: directory
with_community.general.filetree:
- ../files/{{ context }}
- ../files/
loop_control:
label: "{{ item.path }}"
when: item.state == 'directory'
- name: "Copy templates : {{ context }}"
tags:
- config
ansible.builtin.template:
src: "{{ item.src }}"
dest: "{{ home }}/{{ item.path | regex_replace('\\.j2$', '') }}"
mode: "{{ item.mode }}"
with_community.general.filetree:
- ../templates/{{ context }}
loop_control:
label: "{{ item.path }}"
when: item.state == 'file'
- name: Copy config {{ context }}
- name: Copy config
tags:
- config
ansible.builtin.copy:
@@ -33,7 +20,7 @@
dest: "{{ home }}/{{ item.path }}"
mode: "{{ item.mode }}"
with_community.general.filetree:
- ../files/{{ context }}
- ../files
loop_control:
label: "{{ item.path }}"
when: item.state == 'file'

View File

@@ -20,7 +20,7 @@
ansible.builtin.package:
name: "{{ terminal_pkgs }}"
- name: "Install casks : {{ context }}"
- name: "Install casks"
tags:
- install
when: terminal_casks

View File

@@ -1,16 +1,22 @@
---
- name: Install context dependencies
- name: Install dependencies
ansible.builtin.include_tasks: install.yml
loop: "{{ contexts }}"
loop_control:
loop_var: context
tags:
- config
- name: Configure contexts
ansible.builtin.include_tasks: config.yml
loop: "{{ contexts }}"
loop_control:
loop_var: context
- name: Configure
tags:
- config
ansible.builtin.include_tasks: config.yml
- name: Setup contexts
tags:
- git
- config
include_tasks: "setup-context.yml"
vars:
name: "{{ item.key }}"
context: "{{ item.value }}"
loop: "{{ contexts | dict2items }}"
loop_control:
label: "{{ item.key }}"

View File

@@ -0,0 +1,12 @@
- name: Setup context env
tags:
- git
- config
ansible.builtin.template:
src: "../templates/envrc.context.j2"
dest: "{{ context.path }}/.envrc"
mode: "600"
vars:
env: "{{ context.env}}"
name: "{{ name }}"
when: "'env' in context"

View File

@@ -0,0 +1,4 @@
{% for key in env %}
export {{ key }}="{{ env[key] }}"
{% endfor %}

View File

@@ -1,6 +0,0 @@
host github-private
hostname ssh.github.com
user git
port 443
IdentityFile ~/.ssh/keys/github-private.pub
IdentitiesOnly yes

View File

@@ -1 +0,0 @@
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFaIAP/ZJ7+7jeR44e1yIJjfQAB6MN351LDKJAXVF62P

View File

@@ -1,4 +0,0 @@
export NPM_GITHUB_TOKEN="op://jpksggxxmcuwnbwkooktr3iqcy/ut3yag6r7y4bsfrztahp7pcc6q/password"
export NODE_AUTH_TOKEN=$NPM_GITHUB_TOKEN
export GITHUB_TOKEN=$NPM_GITHUB_TOKEN

View File

@@ -1,10 +0,0 @@
[user]
email = morten@olsen.pro
name = Morten Olsen
signingkey = ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFaIAP/ZJ7+7jeR44e1yIJjfQAB6MN351LDKJAXVF62P
[url "git@github-private:morten-olsen/"]
insteadOf = https://github.com/morten-olsen/
[url "ssh://git@giteaa.olsen.cloud:2202/"]
insteadOf = ssh://git@gitea.olsen.cloud:2202/

View File

@@ -1,3 +0,0 @@
@morten-olsen:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=${NODE_AUTH_TOKEN}

View File

@@ -1,6 +0,0 @@
host github-zeronorth
hostname ssh.github.com
user git
port 443
IdentityFile ~/.ssh/keys/github-zeronorth.pub
IdentitiesOnly yes

View File

@@ -1 +0,0 @@
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKDbZITpz5QrVIxPn9gKVWMPK+3W3YZZGszFOQvO/h7M

View File

@@ -1,4 +0,0 @@
export NPM_GITHUB_TOKEN="op://jpksggxxmcuwnbwkooktr3iqcy/ut3yag6r7y4bsfrztahp7pcc6q/password"
export NODE_AUTH_TOKEN=$NPM_GITHUB_TOKEN
export GITHUB_TOKEN="op://Employee/lobazchngpvla4opw4rwzjwnoi/credential"
export AWS_PROFILE="zeronorth"

View File

@@ -1,7 +0,0 @@
[user]
email = morten.olsen@zeronorth.com
name = Morten Olsen
signingkey = ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKDbZITpz5QrVIxPn9gKVWMPK+3W3YZZGszFOQvO/h7M
[url "git@github-zeronorth:"]
insteadOf = https://github.com/

View File

@@ -1,2 +0,0 @@
@0north:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=${NODE_AUTH_TOKEN}

View File

@@ -1,39 +0,0 @@
---
- name: Copy config {{ context }}
tags:
- config
ansible.builtin.file:
mode: "{{ item.mode }}"
path: "{{ home }}/{{ item.path }}"
state: directory
with_community.general.filetree:
- ../files/{{ context }}
loop_control:
label: "{{ item.path }}"
when: item.state == 'directory'
- name: "Copy templates : {{ context }}"
tags:
- config
ansible.builtin.template:
src: "{{ item.src }}"
dest: "{{ home }}/{{ item.path | regex_replace('\\.j2$', '') }}"
mode: "{{ item.mode }}"
with_community.general.filetree:
- ../templates/{{ context }}
loop_control:
label: "{{ item.path }}"
when: item.state == 'file'
- name: Copy config {{ context }}
tags:
- config
ansible.builtin.copy:
src: "{{ item.src }}"
dest: "{{ home }}/{{ item.path }}"
mode: "{{ item.mode }}"
with_community.general.filetree:
- ../files/{{ context }}
loop_control:
label: "{{ item.path }}"
when: item.state == 'file'

View File

@@ -1,33 +0,0 @@
---
- name: "Unload vars : {{ context }}"
ansible.builtin.include_vars: ../vars/empty.yml
tags:
- install
- name: "Load vars : {{ context }}"
ansible.builtin.include_vars: "{{ item }}"
tags:
- install
with_first_found:
- files:
- "{{ ansible_distribution }}-{{ ansible_distribution_release }}.yml"
- "{{ ansible_distribution }}.yml"
- "{{ ansible_os_family }}.yml"
- default.yml
paths: ../vars/{{ context }}
skip: true
- name: "Install dependencies : {{ context }}"
tags:
- install
when: terminal_pkgs
ansible.builtin.package:
name: "{{ terminal_pkgs }}"
- name: "Install casks : {{ context }}"
tags:
- install
when: terminal_casks
community.general.homebrew_cask:
name: "{{ terminal_casks }}"
state: installed

View File

@@ -1,22 +1,28 @@
---
- name: Install context dependencies
ansible.builtin.include_tasks: install.yml
loop: "{{ contexts }}"
loop_control:
loop_var: context
tags:
- config
- name: Install atuin
- name: "Load vars"
ansible.builtin.include_vars: "{{ item }}"
tags:
- install
ansible.builtin.include_role:
name: software_atuin
with_first_found:
- files:
- "{{ ansible_distribution }}-{{ ansible_distribution_release }}.yml"
- "{{ ansible_distribution }}.yml"
- "{{ ansible_os_family }}.yml"
- default.yml
paths: ../vars
skip: true
- name: Configure contexts
ansible.builtin.include_tasks: config.yml
loop: "{{ contexts }}"
loop_control:
loop_var: context
- name: "Install dependencies"
tags:
- config
- install
when: terminal_pkgs
ansible.builtin.package:
name: "{{ terminal_pkgs }}"
- name: "Install casks"
tags:
- install
when: terminal_casks
community.general.homebrew_cask:
name: "{{ terminal_casks }}"
state: installed

View File

@@ -1,4 +0,0 @@
---
terminal_pkgs: []
terminal_casks: []
terminal_flatpaks: []

View File

@@ -1,5 +0,0 @@
---
terminal_pkgs:
- terraform
- awscli
- copier

View File

@@ -22,9 +22,10 @@
- name: Ensure dir
tags: always
ansible.builtin.file:
path: "{{ home }}/.scripts"
path: "{{ home }}/.local/bin"
mode: "0755"
state: directory
- name: Move bin
tags: always
ansible.builtin.copy:
@@ -33,6 +34,12 @@
src: "{{ software_atuin_unpack_file }}"
dest: "{{ home }}/.local/bin/atuin"
- name: Cleanup
tags: always
ansible.builtin.file:
path: "{{ software_atuin_unpack_file }}"
state: absent
- name: Setup config dirctories
tags:
- config

View File

@@ -1 +1,2 @@
install_with_root: true
contexts: {}

View File

@@ -1,3 +1,5 @@
---
dependencies:
- role: base_info
- role: base_terminal
- role: software_ssh

View File

@@ -1,6 +1,7 @@
---
- name: Install dependencies
tags:
- git
- install
become: "{{ install_with_root }}"
ansible.builtin.package:
@@ -10,6 +11,7 @@
- name: Copy config
tags:
- git
- config
ansible.builtin.file:
mode: "{{ item.mode }}"
@@ -21,21 +23,9 @@
label: "{{ item.path }}"
when: item.state == 'directory'
- name: "Copy templates"
tags:
- config
ansible.builtin.template:
src: "{{ item.src }}"
dest: "{{ home }}/{{ item.path | regex_replace('\\.j2$', '') }}"
mode: "{{ item.mode }}"
with_community.general.filetree:
- ../templates
loop_control:
label: "{{ item.path }}"
when: item.state == 'file'
- name: Copy config
- name: "Copy configs"
tags:
- git
- config
ansible.builtin.copy:
src: "{{ item.src }}"
@@ -46,3 +36,24 @@
loop_control:
label: "{{ item.path }}"
when: item.state == 'file'
- name: Setup config
tags:
- git
- config
ansible.builtin.template:
src: "../templates/gitconfig.j2"
dest: "{{ home }}/.gitconfig"
mode: "644"
- name: Setup contexts
tags:
- git
- config
include_tasks: "setup-context.yml"
vars:
name: "{{ item.key }}"
context: "{{ item.value }}"
loop: "{{ contexts | dict2items }}"
loop_control:
label: "{{ item.key }}"

View File

@@ -0,0 +1,43 @@
- name: Setup context git config
tags:
- git
- config
ansible.builtin.template:
src: "../templates/gitconfig.context.j2"
dest: "{{ context.path }}/.gitconfig"
mode: "644"
vars:
git: "{{ context.git }}"
name: "{{ name }}"
when: "'git' in context"
- name: Setup context ssh config
tags:
- git
- config
ansible.builtin.template:
src: "../templates/sshconfig.context.j2"
dest: "{{ home }}/.ssh/config.d/git-{{ name }}"
mode: "644"
vars:
name: "{{ name }}"
when: "'git' in context and 'signing_key' in context.git"
- name: Ensure dir
tags:
- git
- config
ansible.builtin.file:
path: "{{ home }}/.ssh/keys"
state: directory
mode: "0700"
- name: Setup context public key
tags:
- git
- config
ansible.builtin.copy:
content: "{{ context.git.signing_key }}"
dest: "{{ home }}/.ssh/keys/github-{{ name }}.pub"
mode: "0644"
when: "'git' in context and 'signing_key' in context.git"

View File

@@ -0,0 +1,28 @@
[user]
email = {{ git.email }}
name = {{ git.name }}
{% if 'signing_key' in git %}
signingkey = {{ git.signing_key }}
[commit]
gpgsign = true
[gpg]
format = ssh
[gpg "ssh"]
program = "/Applications/1Password.app/Contents/MacOS/op-ssh-sign"
{% endif %}
{% if 'replacements' in git %}
{% for replacement in git.replacements %}
[url "{{ replacement.use }}"]
insteadOf = "{{ replacement.instead_of }}"
{% endfor %}
{% endif %}
[url "git@github-{{name}}:"]
insteadOf = https://github.com/

View File

@@ -1,8 +1,3 @@
[gpg]
format = ssh
[gpg "ssh"]
program = "/Applications/1Password.app/Contents/MacOS/op-ssh-sign"
[alias]
graph = log --graph --color --pretty=format:"%C(yellow)%H%C(green)%d%C(reset)%n%x20%cd%n%x20%cn%C(blue)%x20(%ce)%x20%C(cyan)[gpg:%GK%x20%G?]%C(reset)%n%x20%s%n"
@@ -20,8 +15,6 @@
[difftool "nvimdiff"]
cmd = "nvim -d \"$LOCAL\" \"$REMOTE\""
[commit]
gpgsign = true
[url "https://"]
insteadOf = git://
@@ -43,11 +36,13 @@
process = git-lfs filter-process
required = true
[includeIf "gitdir:~/Projects/zeronorth/"]
path = ~/Projects/zeronorth/.gitconfig
[includeIf "gitdir:~/Projects/private/"]
path = ~/Projects/private/.gitconfig
[push]
autoSetupRemote = true
{% for key in contexts %}
{% if 'git' in contexts[key] %}
[includeIf "gitdir:{{ contexts[key].path }}/"]
path = {{ contexts[key].path }}/.gitconfig
{% endif %}
{% endfor %}

View File

@@ -0,0 +1,6 @@
host github-{{ name }}
hostname ssh.github.com
user git
port 443
IdentityFile ~/.ssh/keys/github-{{ name }}.pub
IdentitiesOnly yes

View File

@@ -9,6 +9,7 @@
- name: Setup config dirctories
tags:
- nvim
- config
ansible.builtin.file:
mode: "{{ item.mode }}"
@@ -22,6 +23,7 @@
- name: Copy config {{ context }}
tags:
- nvim
- config
ansible.builtin.copy:
src: "{{ item.src }}"
@@ -39,12 +41,30 @@
- nvim
ansible.builtin.git:
repo: https://github.com/morten-olsen/nvim
dest: "{{ home }}/.config/nvim"
dest: "{{ home }}/Projects/private/nvim"
accept_newhostkey: true
clone: true
update: true
force: true
- name: Ensure dir
tags:
- config
- nvim
ansible.builtin.file:
path: "{{ home }}/.config"
state: directory
mode: "0755"
- name: Setup nvim link
tags:
- config
- nvim
ansible.builtin.file:
src: "{{ home }}/Projects/private/nvim"
dest: "{{ home }}/.config/nvim"
state: link
- name: Prepare neovim
tags:
- config

View File

@@ -0,0 +1,27 @@
- name: Copy config
tags:
- git
- config
ansible.builtin.file:
mode: "{{ item.mode }}"
path: "{{ home }}/{{ item.path }}"
state: directory
with_community.general.filetree:
- ../files
loop_control:
label: "{{ item.path }}"
when: item.state == 'directory'
- name: "Copy configs"
tags:
- git
- config
ansible.builtin.copy:
src: "{{ item.src }}"
dest: "{{ home }}/{{ item.path }}"
mode: "{{ item.mode }}"
with_community.general.filetree:
- ../files
loop_control:
label: "{{ item.path }}"
when: item.state == 'file'