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,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 %}