organizing for go pkg installs

This commit is contained in:
Matthew Stobbs
2025-02-12 16:57:28 -07:00
parent a3df5215b8
commit c73ac46bc8
31 changed files with 431 additions and 396 deletions

View File

@@ -1,26 +1,63 @@
# vim: set filetype=yaml.ansible :
---
# create all the facts used throughout the role, but shouldn't be touched
# by the user
- name: Set facts based on use_local == true
when:
- use_local
ansible.builtin.set_fact:
paths: "{{ local_paths }}"
archive_become: false
path_prefix: "{{ lookup(ansible.builtin.env, 'HOME') }}/.local"
flatpak_method: user
- name: Set facts based on use_local == false
when:
- not use_local
ansible.builtin.set_fact:
paths: "{{ sys_paths }}"
archive_become: true
path_prefix: "{{ defaults.path.prefix }}"
flatpak_method: system
- name: Set macOS specific facts
when:
- ansible_system == 'Darwin'
block:
- name: Set homebrew bin path
ansible.builtin.set_fact:
homebrew_bin: "/opt/homebrew/bin"
- name: Set other macOS facts
ansible.builtin.set_fact:
dobecome: "{{ not use_local }}"
pipx_exec: "{{ homebrew_bin }}/pipx"
sys_pkg_become: false
- name: Set Linux specific facts
when:
- ansible_system == 'Linux'
block:
- name: Set Linux facts
ansible.builtin.set_fact:
dobecome: "{{ not use_local }}"
sys_pkg_become: true
- name: Set paths
ansible.builtin.set_fact:
paths:
appimage: "{{ appimage_path | default(path_prefix ~ defaults.path.suffix.appimage) }}"
archive: "{{ archive_path | default(path_prefix ~ defaults.path.suffix.archive) }}"
bin: "{{ bin_path | default(path_prefix ~ defaults.path.suffix.bin) }}"
cargo: "{{ cargo_path | default(path_prefix ~ defaults.path.suffix.cargo) }}"
go: "{{ goroot | default(path_prefix ~ defaults.path.suffix.go) }}"
pipx: "{{ pipx_path | default(path_prefix ~ defaults.path.suffix.pipx) }}"
- name: Set installation facts
ansible.builtin.set_fact:
bin_dir: "{{ paths.install }}/bin"
state_dir: "{{ paths.install }}/state"
# repositories
brew_taps: [] # homebrew taps
flatpak_remotes: # flatpak remotes, includes flathub by default
- name: flathub
url: https://dl.flathub.org/repo/flathub.flatpakrepo
# install lists
app_images: [] # app_images to install
archive_pkgs: [] # packages installed via prebuilt archive
cargo_pkgs: [] # rust packages from cargo
cask_pkgs: [] # homebrew casks
flatpaks: [] # flatpaks
@@ -30,39 +67,16 @@
src_pkgs: [] # packages built from source
sys_pkgs: [] # system package manager packages
tap_pkgs: [] # homebrew tap packages
brew_taps: [] # homebrew taps
flatpak_remotes: # flatpak remotes, includes flathub by default
- name: flathub
url: https://dl.flathub.org/repo/flathub.flatpakrepo
- name: Set macOS specific facts
when:
- ansible_system == 'Darwin'
block:
- name: Set pipx executable
ansible.builtin.set_fact:
pipx_exec: /opt/homebrew/bin/pipx
- name: Set sys_pkg_become to false for homebrew
ansible.builtin.set_fact:
sys_pkg_become: false
- name: Set Linux specific facts
when:
- ansible_system == 'Linux'
block:
- name: Set Linux facts
ansible.builtin.set_fact:
sys_pkg_become: true
- name: Ensure required paths exist
become: "{{ not use_local }}"
loop: "{{ paths + [bin_dir, state_dir] }}"
become: "{{ dobecome }}"
loop: "{{ paths | dict2items }}"
loop_control:
loop_var: path
ansible.builtin.file:
state: directory
mode: '0755'
path: "{{ path }}"
path: "{{ path.value }}"
- name: Read default package configuration
ansible.builtin.include_vars:
@@ -144,12 +158,10 @@
- name: Install flatpaks on Linux Systems
when:
- ansible_system == 'Linux'
- flatpaks|length > 0
block:
- name: Add flatpak repos
when:
- flatpak_remotes|length > 0
- flatpaks|length > 0
become: "{{ not use_local }}"
loop: "{{ flatpak_remotes | unique }}"
loop_control:
@@ -166,61 +178,62 @@
loop: "{{ flatpaks | unique }}"
loop_control:
loop_var: flatpak
when:
- flatpaks|length > 0
community.general.flatpak:
state: latest
method: "{{ flatpak_method }}"
name: "{{ flatpak.name }}"
remote: "{{ flatpak.remote | default('flathub') }}"
- name: Ensure prefix/bin exists
ansible.builtin.file:
state: directory
path: "{{ paths.install }}/bin"
owner: root
mode: '0755'
become: true
- name: Install archive_pkgs
when:
- archive_pkgs|length > 0
loop: "{{ archive_pkgs }}"
loop_control:
loop_var: pkg
ansible.builtin.include_tasks:
file: "archive/{{ pkg }}.yml"
- name: Install src_pkgs
ansible.builtin.include_tasks:
file: "src/{{ src_pkg }}.yml"
when:
- src_pkgs|length > 0
loop: "{{ src_pkgs | unique }}"
loop_control:
loop_var: src_pkg
when: src_pkgs|length > 0
loop_var: pkg
ansible.builtin.include_tasks:
file: "src/{{ pkg }}.yml"
- name: Install cargo packages at specific version
- name: Install cargo packages
when:
- cargo_pkgs|length > 0
become: "{{ not use_local }}"
loop: "{{ cargo_pkgs | unique }}"
loop_control:
loop_var: cargo_pkg
loop_var: pkg
community.general.cargo:
name: "{{ cargo_pkg.cargo.pkg }}"
version: "{{ cargo_pkg.ver }}"
name: "{{ pkg.cargo.pkg }}"
version: "{{ pkg.ver }}"
path: "{{ paths.cargo }}"
locked: "{{ cargo_pkg.cargo.locked }}"
locked: "{{ pkg.cargo.locked }}"
- name: Install local go packages
- name: Install go packages
when:
- go_pkgs|length > 0
loop: "{{ go_pkgs | unique }}"
loop_control:
loop_var: go_pkg
loop_var: pkg
environment:
GOROOT: "{{ paths.install }}/go"
PATH: "{{ paths.install }}/go/bin:$PATH"
ansible.builtin.command:
cmd: "go install {{ go_pkg }}"
# TODO: figure out how to check if the go_pkg is already installed
GOBIN: "{{ paths.bin }}"
PATH: "{{ paths.go }}/bin:$PATH"
ansible.builtin.include_tasks:
file: go.yml
- name: Install local npm packages
when:
- npm_pkgs|length > 0
become: "{{ archive_become }}"
loop: "{{ npm_pkgs | unique }}"
loop_control:
loop_var: npm_pkg
when: npm_pkgs|length > 0
community.general.npm:
global: true
name: "{{ npm_pkg }}"