From c552125b121b62aae1e9cf83be233d96d4fe1127 Mon Sep 17 00:00:00 2001 From: Morten Olsen Date: Mon, 7 Oct 2024 15:04:35 +0200 Subject: [PATCH] update --- .vagrant/bundler/global.sol | 1 + .vagrant/machines/default/libvirt/vagrant_cwd | 1 + .vagrant/rgloader/loader.rb | 12 +++++ Dockerfile | 13 +++-- Vagrantfile | 9 ++++ inventory.yml | 5 ++ playbooks/image.yml | 5 ++ .../roles/desktop/vars/default/default.yml | 2 +- playbooks/roles/dev/tasks/config.yml | 26 ++++++++++ playbooks/roles/dev/tasks/install.yml | 33 +++++++++++++ playbooks/roles/dev/tasks/main.yml | 16 +++++++ playbooks/roles/dev/vars/default/default.yml | 4 ++ playbooks/roles/dev/vars/empty.yml | 4 ++ playbooks/roles/info/tasks/main.yml | 2 +- playbooks/roles/system/tasks/main.yml | 9 +--- .../files/default/.config/atuin/config.toml | 2 + .../roles/terminal/files/default/.ssh/config | 2 +- playbooks/roles/terminal/meta/main.yml | 1 + playbooks/roles/terminal/tasks/config.yml | 12 +++++ playbooks/roles/terminal/tasks/main.yml | 48 ++++++++++++++----- playbooks/roles/terminal/tasks/nvim.yml | 22 +++++++++ .../roles/terminal/vars/default/default.yml | 4 +- playbooks/roles/update/tasks/main.yml | 4 ++ playbooks/setup.yml | 2 +- requirements.yml | 4 ++ 25 files changed, 210 insertions(+), 33 deletions(-) create mode 100644 .vagrant/bundler/global.sol create mode 100644 .vagrant/machines/default/libvirt/vagrant_cwd create mode 100644 .vagrant/rgloader/loader.rb create mode 100644 Vagrantfile create mode 100644 playbooks/image.yml create mode 100644 playbooks/roles/dev/tasks/config.yml create mode 100644 playbooks/roles/dev/tasks/install.yml create mode 100644 playbooks/roles/dev/tasks/main.yml create mode 100644 playbooks/roles/dev/vars/default/default.yml create mode 100644 playbooks/roles/dev/vars/empty.yml create mode 100644 playbooks/roles/terminal/files/default/.config/atuin/config.toml create mode 100644 playbooks/roles/terminal/tasks/nvim.yml create mode 100644 playbooks/roles/update/tasks/main.yml create mode 100644 requirements.yml diff --git a/.vagrant/bundler/global.sol b/.vagrant/bundler/global.sol new file mode 100644 index 0000000..3b4b853 --- /dev/null +++ b/.vagrant/bundler/global.sol @@ -0,0 +1 @@ +{"dependencies":[["racc",["~> 1.4"]],["nokogiri",["~> 1.6"]],["diffy",[">= 0"]],["rexml",[">= 0"]],["xml-simple",[">= 0"]],["mime-types-data",["~> 3.2015"]],["mime-types",[">= 0"]],["formatador",[">= 0.2","< 2.0"]],["excon",["~> 0.71"]],["builder",[">= 0"]],["fog-core",["~> 2"]],["json",[">= 0"]],["ruby-libvirt",[">= 0.7.0"]],["fog-xml",["~> 0.1.1"]],["multi_json",["~> 1.10"]],["fog-json",[">= 0"]],["fog-libvirt",[">= 0.6.0"]],["vagrant-libvirt",["= 0.12.2"]],["vagrant-qemu",["= 0.3.6"]]],"checksum":"d29c877f7d936a4ed482393f2146efe63cd2dcecac3c1ae41fbb8ca2d854a211","vagrant_version":"2.4.1"} \ No newline at end of file diff --git a/.vagrant/machines/default/libvirt/vagrant_cwd b/.vagrant/machines/default/libvirt/vagrant_cwd new file mode 100644 index 0000000..142fa18 --- /dev/null +++ b/.vagrant/machines/default/libvirt/vagrant_cwd @@ -0,0 +1 @@ +/Users/alice/Projects/private/system \ No newline at end of file diff --git a/.vagrant/rgloader/loader.rb b/.vagrant/rgloader/loader.rb new file mode 100644 index 0000000..b6c81bf --- /dev/null +++ b/.vagrant/rgloader/loader.rb @@ -0,0 +1,12 @@ +# Copyright (c) HashiCorp, Inc. +# SPDX-License-Identifier: BUSL-1.1 + +# This file loads the proper rgloader/loader.rb file that comes packaged +# with Vagrant so that encoded files can properly run with Vagrant. + +if ENV["VAGRANT_INSTALLER_EMBEDDED_DIR"] + require File.expand_path( + "rgloader/loader", ENV["VAGRANT_INSTALLER_EMBEDDED_DIR"]) +else + raise "Encoded files can't be read outside of the Vagrant installer." +end diff --git a/Dockerfile b/Dockerfile index 8a76bf8..50a6ab9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,8 @@ -FROM debian:bookworm +FROM fedora WORKDIR /app -RUN apt-get update && apt-get install -y \ - python3 \ - python3-pip \ - && rm -rf /var/lib/apt/lists/* -COPY requirements.txt /app -RUN pip3 install -r requirements.txt +RUN yum update -y && yum install -y \ + ansible +COPY requirements.yml /app +RUN ansible-galaxy collection install -r requirements.yml COPY . /app +RUN ansible-playbook /app/playbooks/image.yml diff --git a/Vagrantfile b/Vagrantfile new file mode 100644 index 0000000..b3fda91 --- /dev/null +++ b/Vagrantfile @@ -0,0 +1,9 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : +Vagrant.configure("2") do |config| + config.vm.provider "virtualbox" + config.vm.box = "archlinux/archlinux" + config.vm.provision "ansible" do |ansible| + ansible.playbook = "playbooks/setup.yml" + end +end diff --git a/inventory.yml b/inventory.yml index 810bdab..a1a3067 100644 --- a/inventory.yml +++ b/inventory.yml @@ -1,3 +1,8 @@ +images: + hosts: + docker-dev: + contexts: + - privat desktops: hosts: zn-macbook: diff --git a/playbooks/image.yml b/playbooks/image.yml new file mode 100644 index 0000000..a11bd52 --- /dev/null +++ b/playbooks/image.yml @@ -0,0 +1,5 @@ +--- +- name: Setup host + hosts: localhost + roles: + - role: terminal diff --git a/playbooks/roles/desktop/vars/default/default.yml b/playbooks/roles/desktop/vars/default/default.yml index 94f2bd2..cdd9c5f 100644 --- a/playbooks/roles/desktop/vars/default/default.yml +++ b/playbooks/roles/desktop/vars/default/default.yml @@ -1,5 +1,5 @@ --- -_desktop_casks: +desktop_casks: - 1password - 1password-cli - kitty diff --git a/playbooks/roles/dev/tasks/config.yml b/playbooks/roles/dev/tasks/config.yml new file mode 100644 index 0000000..97033c1 --- /dev/null +++ b/playbooks/roles/dev/tasks/config.yml @@ -0,0 +1,26 @@ +--- +- 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' diff --git a/playbooks/roles/dev/tasks/install.yml b/playbooks/roles/dev/tasks/install.yml new file mode 100644 index 0000000..21c52e7 --- /dev/null +++ b/playbooks/roles/dev/tasks/install.yml @@ -0,0 +1,33 @@ +--- +- 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: desktop_pkgs + ansible.builtin.package: + name: "{{ dev_pkgs }}" + +- name: "Install casks : {{ context }}" + tags: + - install + when: dev_casks + community.general.homebrew_cask: + name: "{{ dev_casks }}" + state: installed diff --git a/playbooks/roles/dev/tasks/main.yml b/playbooks/roles/dev/tasks/main.yml new file mode 100644 index 0000000..5719976 --- /dev/null +++ b/playbooks/roles/dev/tasks/main.yml @@ -0,0 +1,16 @@ +--- +- 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 diff --git a/playbooks/roles/dev/vars/default/default.yml b/playbooks/roles/dev/vars/default/default.yml new file mode 100644 index 0000000..6e0cd55 --- /dev/null +++ b/playbooks/roles/dev/vars/default/default.yml @@ -0,0 +1,4 @@ +--- +dev_pkgs: + - rustup + - python3 diff --git a/playbooks/roles/dev/vars/empty.yml b/playbooks/roles/dev/vars/empty.yml new file mode 100644 index 0000000..ea9617d --- /dev/null +++ b/playbooks/roles/dev/vars/empty.yml @@ -0,0 +1,4 @@ +--- +dev_pkgs: [] +dev_casks: [] +dev_flatpaks: [] diff --git a/playbooks/roles/info/tasks/main.yml b/playbooks/roles/info/tasks/main.yml index 66e9d36..eed4128 100644 --- a/playbooks/roles/info/tasks/main.yml +++ b/playbooks/roles/info/tasks/main.yml @@ -2,7 +2,7 @@ tags: always ansible.builtin.set_fact: username: alice - home: /Users/alice + home: "{{ ansible_env.HOME }}" use_become: true mac_os: "{{ ansible_distribution == 'MacOSX' }}" contexts: "{{ ['default'] + (contexts | default([])) }}" diff --git a/playbooks/roles/system/tasks/main.yml b/playbooks/roles/system/tasks/main.yml index 494cbae..fcd451e 100644 --- a/playbooks/roles/system/tasks/main.yml +++ b/playbooks/roles/system/tasks/main.yml @@ -1,11 +1,6 @@ -- name: Install core dependencies - tags: always - ansible.builtin.package: - name: - - zsh - - name: Create group when: not mac_os + become: true tags: always ansible.builtin.group: name: "{{ username }}" @@ -13,10 +8,10 @@ - name: Create user when: not mac_os + become: true tags: always ansible.builtin.user: name: "{{ username }}" update_password: "on_create" create_home: yes - shell: /usr/bin/zsh group: "{{ username }}" diff --git a/playbooks/roles/terminal/files/default/.config/atuin/config.toml b/playbooks/roles/terminal/files/default/.config/atuin/config.toml new file mode 100644 index 0000000..2deb563 --- /dev/null +++ b/playbooks/roles/terminal/files/default/.config/atuin/config.toml @@ -0,0 +1,2 @@ +style = "compact" +keymap_mode = "vim-normal" diff --git a/playbooks/roles/terminal/files/default/.ssh/config b/playbooks/roles/terminal/files/default/.ssh/config index ef602aa..bfa79ad 100644 --- a/playbooks/roles/terminal/files/default/.ssh/config +++ b/playbooks/roles/terminal/files/default/.ssh/config @@ -4,7 +4,7 @@ Include ~/.ssh/config.d/* Host * Controlmaster auto - Controlpath ${TMPDIR}/ssh-%r@%h:%p + Controlpath /tmp/ssh-%r@%h:%p IdentityAgent "~/Library/Group Containers/2BUA8C4S2C.com.1password/t/agent.sock" ForwardAgent yes diff --git a/playbooks/roles/terminal/meta/main.yml b/playbooks/roles/terminal/meta/main.yml index 6ec6c73..75f605c 100644 --- a/playbooks/roles/terminal/meta/main.yml +++ b/playbooks/roles/terminal/meta/main.yml @@ -2,3 +2,4 @@ dependencies: - role: info - role: system + # - elliotweiser.osx-command-line-tools diff --git a/playbooks/roles/terminal/tasks/config.yml b/playbooks/roles/terminal/tasks/config.yml index 99eb265..4d15b2c 100644 --- a/playbooks/roles/terminal/tasks/config.yml +++ b/playbooks/roles/terminal/tasks/config.yml @@ -1,4 +1,16 @@ --- +- name: Copy config {{ context }} + tags: + - config + ansible.builtin.file: + 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 diff --git a/playbooks/roles/terminal/tasks/main.yml b/playbooks/roles/terminal/tasks/main.yml index b701f36..b14961a 100644 --- a/playbooks/roles/terminal/tasks/main.yml +++ b/playbooks/roles/terminal/tasks/main.yml @@ -1,4 +1,19 @@ --- +- name: Install core dependencies + tags: + - install + ansible.builtin.package: + name: + - zsh + +- name: Set shell + become: true + tags: + - config + ansible.builtin.user: + name: "{{ username }}" + shell: /usr/bin/zsh + - name: Install context dependencies ansible.builtin.include_tasks: install.yml loop: "{{ contexts }}" @@ -7,13 +22,16 @@ tags: - config -- name: Configure contexts - ansible.builtin.include_tasks: config.yml - loop: "{{ contexts }}" - loop_control: - loop_var: context +- name: Clone nvm tags: - - config + - install + ansible.builtin.git: + accept_newhostkey: true + clone: true + force: true + recursive: false + repo: https://github.com/nvm-sh/nvm + dest: "{{ home }}/.nvm" - name: Install node and set version tags: @@ -24,12 +42,16 @@ args: executable: /bin/bash -- name: Configure neovim +- name: Setup nvim + tags: + - config + - nvim + include_tasks: "nvim.yml" + +- name: Configure contexts + ansible.builtin.include_tasks: config.yml + loop: "{{ contexts }}" + loop_control: + loop_var: context tags: - config - ansible.builtin.git: - repo: https://github.com/morten-olsen/nvim - dest: "{{ home }}/.config/nvim" - accept_newhostkey: true - clone: true - update: true diff --git a/playbooks/roles/terminal/tasks/nvim.yml b/playbooks/roles/terminal/tasks/nvim.yml new file mode 100644 index 0000000..42bcdb7 --- /dev/null +++ b/playbooks/roles/terminal/tasks/nvim.yml @@ -0,0 +1,22 @@ +--- +- name: Configure neovim + tags: + - config + - nvim + ansible.builtin.git: + repo: https://github.com/morten-olsen/nvim + dest: "{{ home }}/.config/nvim" + accept_newhostkey: true + clone: true + update: true + force: true + +- name: Prepare neovim + tags: + - config + - nvim + register: nviminstall + changed_when: "nviminstall.stdout != ''" + ansible.builtin.shell: nvim --headless +q + args: + executable: /bin/bash diff --git a/playbooks/roles/terminal/vars/default/default.yml b/playbooks/roles/terminal/vars/default/default.yml index e10c3d5..c9c97d1 100644 --- a/playbooks/roles/terminal/vars/default/default.yml +++ b/playbooks/roles/terminal/vars/default/default.yml @@ -1,6 +1,6 @@ --- terminal_pkgs: - - atuin + #- atuin - bat - eza - direnv @@ -10,7 +10,7 @@ terminal_pkgs: - ripgrep - neovim - gh - - starship + #- starship - tmux - zoxide - git diff --git a/playbooks/roles/update/tasks/main.yml b/playbooks/roles/update/tasks/main.yml new file mode 100644 index 0000000..0fc3113 --- /dev/null +++ b/playbooks/roles/update/tasks/main.yml @@ -0,0 +1,4 @@ +- name: Update neovim lazy + ansible.builtin.run: 'nvim --headless "+Lazy! sync" +qa' + args: + executable: /bin/bash diff --git a/playbooks/setup.yml b/playbooks/setup.yml index 0ce66b8..b5e9ab8 100644 --- a/playbooks/setup.yml +++ b/playbooks/setup.yml @@ -1,6 +1,6 @@ --- - name: Setup host - hosts: all + hosts: desktops roles: - role: terminal - role: desktop diff --git a/requirements.yml b/requirements.yml new file mode 100644 index 0000000..a0dcad8 --- /dev/null +++ b/requirements.yml @@ -0,0 +1,4 @@ +--- +roles: + - name: elliotweiser.osx-command-line-tools + - name: andrewrothstein.starship