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