change layout for better management

- instead of just `syspkgs` and `srcpkgs` add more lists
  - `appimages`, `flatpkgs` and others as they come up
This commit is contained in:
Matthew Stobbs
2025-02-11 17:51:10 -07:00
parent 9ec814257f
commit 275f5df722
19 changed files with 295 additions and 224 deletions

52
CONTRIBUTING.md Normal file
View File

@@ -0,0 +1,52 @@
# Contributing
## Package definition
Package defintions are just `yaml` tasks in the directory
`tasks/pkgs`, which handle how a package is installed.
Most can be installed using the `syspkgs` list, and are simply
appending the package name to said list based on the system.
If a package can be installed via an entry to `syspkgs` for some,
but not all platforms, handling is done to either inform the user
that the package is not available, or to append the package name
to another installation method such as:
- `appimages` to install the appimage of a package
- `cargopkgs` to install via the rust cargo package manager
- `cargoversioned` to install version lockec cargo packages
- `caskpkgs` to install a homebrew cask
- `flatpkgs` to install flatpaks
- `gopkgs` to install using the `go install` command
- `npmpkgs` to install packages from npm
- `pipxpkgs` to install packages from Python pip
- `srcpkgs` to build packages from source
- `tappkgs` to install packages from home brew taps
Alternative sources of packages can be defined with entries to:
- `fpremotes` to add a flatpak remote
- `brewtaps` to add a homebrew tap
### Adding system level repositories
Many packages exist in their own external repository for the
given system, such as `/etc/yum.repos.d` for RedHat based linux
distros, `/etc/apt/sources.list.d` for Debian based distros and
others. Since you an add the package to `syspkgs` by enabling a
repo, the coresponding task in `tasks/pkgs` should take the
steps needed to enable the repository.
### Packages with multiple instllation methods
Many packages can be installed in different ways, like the
`bitwarden` package. `bitwarden` can be installed as a `syspkg`
on some machines, a `caskpkg` on macOS, an `appimage`, a `flatpak`
or even a `snap`.
For such packages, a default is chosen to install, in the following order
of precedence: `syspkgs`, `flatpkgs`, `snappkgs`, `appimages`.
In that order, `syspkgs` and `caskpkgs` have equal weight, as it applies
to macOS.

View File

@@ -1,23 +1,11 @@
# vim: set filetype=yaml.ansible :
---
- name: "check if task for {{pkg}} exists"
ansible.builtin.command: "test -f {{role_path}}/tasks/pkgs/{{ pkg }}.yml"
- name: "Check if task exists for {{ pkg }}"
ansible.builtin.stat:
path: "{{ role_path }}/tasks/pkgs/{{ pkg }}.yml"
register: cpkg_exists
ignore_errors: true
failed_when: not (cpkg_exists.rc != 0 or cpkg_exists.rc != 1)
- name: "add include task for {{pkg}}"
- name: "Add include task for {{ pkg }}"
when: cpkg_exists.exists
ansible.builtin.include_tasks:
file: "pkgs/{{ pkg }}.yml"
when: cpkg_exists.rc == 0
tags:
- packages
- name: "add {{pkg}} to syspkgs if task doesn't exist: {{assume_missing_is_syspkg}}"
ansible.builtin.set_fact:
syspkgs: "{{ syspkgs + [pkg] }}"
when:
- cpkg_exists.rc != 0
- assume_missing_is_syspkg
tags:
- packages

View File

@@ -0,0 +1,31 @@
# vim: set filetype=yaml.ansible :
---
- name: Install bitwarden appimage
become: "{{ bw_become }}"
become_user: "{% if bw_become %}{{ bw_owner }}{% else %}~{% endif %}"
when:
- bw_instmtd == 'appimage'
block:
- name: Ensure install path exists
ansible.builtin.file:
state: directory
mode: '0755'
path: "{{ bw_instdir }}"
owner: "{{ bw_owner }}"
group: "{{ bw_group }}"
- name: Fetch bitwarden appimage
ansible.builtin.get_url:
mode: '0755'
decompress: false
backup: true
url: bw_appimg.url
dest: "{{ bw_instdir }}/{{ bw_appimg.name }}"
owner: "{{ bw_owner }}"
group: "{{ bw_group }}"
- name: Link bitwarden appimage
ansible.builtin.file:
state: link
src: "{{ bw_instdir }}/{{ bw_appimg.name }}"
path: "{{ bw_instpfx }}/bin/bitwarden"

View File

@@ -1,7 +1,9 @@
# vim: set filetype=yaml.ansible :
---
- name: build and install alacritty
- name: Build and install alacritty
become: true
ansible.builtin.command:
creates: "{{ pkgconfig_alacritty.install_prefix }}/bin/alacritty"
cmd:
- cargo
- install
@@ -11,4 +13,3 @@
- "{{ pkgconfig_alacritty.git_repo }}"
- --tag
- "v{{ pkgconfig_alacritty.version }}"
become: true

View File

@@ -1,28 +0,0 @@
# vim: set filetype=yaml.ansible :
---
- name: Install bitwarden appimage
blocK:
- ansible.builtin.file:
state: directory
mode: '0755'
path: "{{ pkgconfig_bitwarden.install_dir }}"
owner: "{{ pkgconfig_bitwarden.owner }}"
group: "{{ pkgconfig_bitwarden.group }}"
- ansible.builtin.get_url:
mode: '0755'
decompress: false
backup: true
url: "https://vault.bitwarden.com/download/?app=desktop&platform=linux&variant=appimage"
dset: "{{ pkgconfig_bitwarden.install_dir }}/bitwarden.appimage"
owner: "{{ pkgconfig_bitwarden.owner }}"
group: "{{ pkgconfig_bitwarden.group }}"
- ansible.builtin.file:
state: link
src: "{{ pkgconfig_bitwarden.install_dir }}/bitwarden.appimage"
path: "{{ pkgconfig_bitwarden.install_prefix }}/bin/bitwarden"
when:
- pkgconfig_bitwarden.use_appimage
beocome: "{{ pkgconfig_bitwarden.dobecome }}"
become_user: "{% if pkgconfig_bitwarden.dobecome %}{{ pkgconfig_bitwarden.owner }}{% else %}~{% endif %}"

View File

@@ -1,27 +1,27 @@
# vim: set filetype=yaml.ansible :
---
- name: build ghostty from source
- name: Build ghostty from source
block:
- name: create temp path
- name: Create temp path
ansible.builtin.tempfile:
state: directory
prefix: ghostty.
register: d_ghostty_tmp
- name: clone ghostty git repository
- name: Clone ghostty git repository
ansible.builtin.git:
depth: 1
dest: "{{ d_ghostty_tmp.path }}/ghostty"
repo: "{{ pkgconfig_ghostty.git_repo }}"
version: "{{ pkgconfig_ghostty.version }}"
- name: build ghostty
- name: Build ghostty
ansible.builtin.command:
chdir: "{{ d_ghostty_tmp.path }}/ghostty"
cmd: "zig build -D{{ pkgconfig_ghostty.optimize }}"
register: c_ghostty_build
- name: install ghostty
- name: Install ghostty
ansible.file.copy:
src: "{{ d_ghostty_tmp.path }}/ghostty/zig-out/bin/ghostty"
dest: "{{ pkgconfig_ghostty.install_prefix }}/bin/ghostty"

View File

@@ -2,11 +2,20 @@
---
- name: Set needed variables lua language server
ansible.builtin.set_fact:
luals_pkg: "lua-language-server-{{ pkgconfig_luals.version }}-{{ pkgconfig_luals.sysmap[ansible_system] }}-{{ pkgconfig_luals.archmap[ansible_architecture] }}.tar.gz"
luals_sys: pkgconfig_luals.sysmap[ansible_system]
luals_arch: pkgconfig_luals.archmap[ansible_architecture]
luals_ver: pkgconfig_luals.version
luals_instpath: pkgconfig_luals.install_path
luals_instpfx: pkgconfig_luals.install_prefix
luals_burl: pkgconfig_luals.base_url
- name: Set luals archive name
ansible.builtin.set_fact:
luals_pkg: "lua-language-server-{{ luals_ver }}-{{ lualsl_sys }}-{{ luals_arch }}.tar.gz"
- name: Check if lua language server is already installed
ansible.builtin.stat:
path: "{{ pkgconfig_luals.install_path }}/bin/lua-language-server"
path: "{{ luals_instpath }}/bin/lua-language-server"
register: r_luals_stat
- name: Install lua-language-server
@@ -21,20 +30,20 @@
- name: Get latest lua-language-server
ansible.builtin.get_url:
dest: "{{ d_luals_dl_tmp.path }}/{{ luals_pkg }}"
url: "{{ pkgconfig_luals.base_url }}/{{ pkgconfig_luals.version }}/{{ luals_pkg }}"
url: "{{ luals_burl }}/{{ luals_ver }}/{{ luals_pkg }}"
mode: "0644"
decompress: false
- name: Create install_path
ansible.builtin.file:
state: directory
path: "{{ pkgconfig_luals.install_path }}"
path: "{{ luals_instpath }}"
mode: "0755"
become: true
- name: Extract lua language server archive
ansible.builtin.unarchive:
dest: "{{ pkgconfig_luals.install_path }}"
dest: "{{ luals_instpath }}"
src: "{{ d_luals_dl_tmp.path }}/{{ luals_pkg }}"
remote_src: true
become: true
@@ -42,6 +51,6 @@
- name: Link lua language server binary
ansible.builtin.file:
state: link
src: "{{ pkgconfig_luals.install_path }}/bin/lua-language-server"
path: "{{ pkgconfig_luals.install_prefix }}/bin/lua-language-server"
src: "{{ luals_instpath }}/bin/lua-language-server"
path: "{{ luals_instpfx }}/bin/lua-language-server"
become: true

View File

@@ -1,64 +1,45 @@
# vim: set filetype=yaml.ansible :
---
- name: generate package installation lists
- name: Determine OS and set facts for it
block:
- name: Set macOS facts
when: ansible_os_family == 'Darwin'
ansible.builtin.set_fact:
syspkg_become: false
- name: Set Linux facts
when: ansible_system == 'Linux'
ansible.builtin.set_fact:
syspkg_become: true
- name: Generate package installation lists
ansible.builtin.include_tasks:
file: addpkg.yml
loop: "{{ packages | unique }}"
loop_control:
loop_var: pkg
- name: redhat based OS
block:
- name: upgrade dnf packages
ansible.builtin.dnf:
name: "*"
state: latest
become: true
when: full_upgrade
- name: install dnf packages
ansible.builtin.dnf:
- name: Install syspkgs list
become: "{{ syspkg_become }}"
ansible.builtin.package:
name: "{{ syspkgs | unique }}"
state: "{{ install_state }}"
become: true
when:
- syspkgs|length > 0
- name: add flatpak repos
community.general.flatpak_remote:
enabled: true
flatpakrepo_url: "{{ repo.url }}"
method: system
name: "{{ repo.name }}"
state: present
loop: "{{ flatpkg_repo }}"
loop_control:
loop_var: repo
become: true
when:
- flatpkg_repo|length > 0
- flatpkgs|length > 0
- name: install flatpaks
community.general.flatpak:
method: "system"
name: "{{ flatpkgs }}"
state: latest
become: true
when:
- flatpkgs|length > 0
- name: Redhat based OS
when: ansible_os_family == 'RedHat'
- name: debian based OS
block:
- name: upgrade apt packages
ansible.builtin.apt:
name: "*"
state: latest
- name: Install dnf packages
become: true
when: full_upgrade
when:
- syspkgs|length > 0
ansible.builtin.dnf:
name: "{{ syspkgs | unique }}"
state: present
- name: install apt packages
- name: Debian based OS
when: ansible_os_family == 'Debian'
block:
- name: Install apt packages
ansible.builtin.apt:
name: "{{ syspkgs | unique }}"
state: "{{ install_state }}"
@@ -66,66 +47,75 @@
when:
- syspkgs|length > 0
- name: add flatpak repos
community.general.flatpak_remote:
enabled: true
flatpakrepo_url: "{{ repo.url }}"
method: system
name: "{{ repo.name }}"
state: present
loop: "{{ flatpkg_repo | unique }}"
loop_control:
loop_var: repo
become: true
when:
- flatpkg_repo|length > 0
- flatpkgs|length > 0
- name: install flatpaks
community.general.flatpak:
method: "system"
name: "{{ flatpkgs | unique }}"
state: latest
become: true
when:
- flatpkgs|length > 0
when: ansible_os_family == 'Debian'
- name: darwin/macOS based OS
- name: Darwin/macOS based OS
when: ansible_os_family == 'Darwin'
block:
- name: upgrade homebrew packages
- name: Upgrade homebrew packages
community.general.homebrew:
name: "*"
state: latest
when: full_upgrade
- name: tap homebrew taps
- name: Tap homebrew taps
community.general.homebrew_tap:
name: "{{ brewtaps | unique }}"
state: present
when: brewtaps|length > 0
- name: install homebrew packages
- name: Install homebrew packages
community.general.homebrew:
name: "{{ syspkgs | unique }}"
state: "{{ install_state }}"
when: syspkgs|length > 0
- name: install homebrew casks
- name: Install homebrew casks
community.general.homebrew_cask:
name: "{{ caskpkgs | unique }}"
state: "{{ install_state }}"
when: caskpkgs|length > 0
- name: workaround to install homebrew taps
- name: Workaround to install homebrew taps
ansible.builtin.command:
cmd: "brew install {{ tappkg }}"
loop: "{{ tappkgs | unique }}"
loop_control:
loop_var: tappkg
when: ansible_os_family == 'Darwin'
# TODO: fix the need to have this workaround
- name: ensure /usr/local/bin exists
- name: Install flatpaks on Linux Systems
when:
- ansible_system == 'Linux'
- flatpkgs|length > 0
block:
- name: Add flatpak repos
become: true
loop: "{{ fpremotes | unique }}"
loop_control:
loop_var: remote
when:
- fpremotes|length > 0
- flatpkgs|length > 0
community.general.flatpak_remote:
enabled: true
method: system
state: present
flatpakrepo_url: "{{ remote.url }}"
name: "{{ remote.name }}"
- name: Install flatpaks
become: true
loop: "{{ flatpkgs | unique }}"
loop_control:
loop_var: flatpkg
when:
- flatpkgs|length > 0
community.general.flatpak:
state: latest
method: system
name: "{{ flatpkg.name }}"
remote: "{{ flatpkg.remote | default('flathub') }}"
- name: Ensure /usr/local/bin exists
ansible.builtin.file:
state: directory
path: /usr/local/bin
@@ -133,7 +123,7 @@
mode: '0755'
become: true
- name: install srcpkgs
- name: Install srcpkgs
ansible.builtin.include_tasks:
file: "build/{{ srcpkg }}.yml"
loop: "{{ srcpkgs | unique }}"
@@ -141,11 +131,11 @@
loop_var: srcpkg
when: srcpkgs|length > 0
- name: install cargo packages at specific version
- name: Install cargo packages at specific version
community.general.cargo:
name: "{{ cargopkg.name }}"
version: "{{ cargopkg.version }}"
path: "{{ cargopkg.path | default(default_config.install_prefix) }}"
path: "{{ cargopkg.path | default(default_install_prefix) }}"
locked: "{{ cargopkg.locked | default(false) }}"
become: true
when: cargoversioned|length > 0
@@ -164,32 +154,33 @@
loop_var: cargopkg
- name: Install local go packages
loop: "{{ gopkgs | unique }}"
loop_control:
loop_var: gopkg
when: gopkgs|length > 0
environment:
GOROOT: /usr/local/go
PATH: /usr/local/go/bin:$PATH
ansible.builtin.command:
cmd: "go install {{ gopkg }}"
loop: "{{ gopkgs | unique }}"
loop_control:
loop_var: gopkg
when: gopkgs|length > 0
#TODO: figure out how to check if the gopkg is already installed
- name: Install local npm packages
community.general.npm:
global: true
name: "{{ npmpkg }}"
state: latest
loop: "{{ npmpkgs | unique }}"
loop_control:
loop_var: npmpkg
when: npmpkgs|length > 0
community.general.npm:
global: true
name: "{{ npmpkg }}"
state: latest
- name: Install python pipx packages for user
community.general.pipx:
executable: "{% if ansible_os_family == 'Darwin' %}/opt/homebrew/bin/pipx{% else %}/usr/bin/pipx{% endif %}"
name: "{{ pipxpkg }}"
state: latest
loop: "{{ pipxpkgs | unique }}"
loop_control:
loop_var: pipxpkg
when: pipxpkgs|length > 0
community.general.pipx:
executable: "{% if ansible_os_family == 'Darwin' %}/opt/homebrew/bin/pipx{% else %}/usr/bin/pipx{% endif %}"
name: "{{ pipxpkg }}"
state: latest

View File

@@ -1,31 +1,48 @@
# vim: set filetype=yaml.ansible :
---
- ansible.builtin.include_vars:
- name: Read bitwarden configuration
ansible.builtin.include_vars:
file: bitwarden.yml
name: _bitwarden
- ansible.builtin.set_fact:
- name: Set bitwarden configuration
ansible.builtin.set_fact:
pkgconfig_bitwarden: "{{ _bitwarden | ansible.builtin.combine(pkgconfig.bitwarden) }}"
- name: append to flatpkgs
- name: Set bitwarden facts
ansible.builtin.set_fact:
bw:
appimg: pkgconfig_bitwarden.appimage
become: pkgconfig_bitwarden.dobecome
flatpak: pkgconfig_bitwarden.flatpak
group: pkgconfig_bitwarden.group
instdir: pkgconfig_bitwarden.install_dir
instmtd: pkgconfig_bitwarden.install_method
instpfx: pkgconfig_bitwarden.install_prefix
owner: pkgconfig_bitwarden.owner
- name: Append to flatpkgs
when:
- ansible_os_family != 'Darwin'
- bw.instmtd == 'flatpak'
block:
- ansible.builtin.include_tasks:
- name: Ensure flatpak runtime activated
ansible.builtin.include_tasks:
file: pkgs/flatpak.yml
when: flatpak is undefined
- ansible.builtin.set_fact:
flatpkgs: "{{ flatpkgs + [ 'com.bitwarden.desktop' ] }}"
when:
- ansible_os_family != 'Darwin'
- pkgconfig_bitwarden.use_flatpak
- name: append to srcpkgs
- name: Append to flatpkgs
ansible.builtin.set_fact:
syspkgs: "{{ srcpkgs + [ 'bitwarden' ] }}"
flatpkgs: "{{ flatpkgs + [bw.flatpak] }}"
- name: Append to srcpkgs
when:
- ansible_os_family != 'Darwin'
- not pkgconfig_bitwarden.use_flatpak
- bw.instmtd == 'appimage'
ansible.builtin.set_fact:
syspkgs: "{{ appimages + ['bitwarden'] }}"
- name: append to caskpkgs
- name: Append to caskpkgs
when: ansible_os_family == 'Darwin'
ansible.builtin.set_fact:
caskpkgs: "{{ caskpkgs + ['bitwarden'] }}"
when: ansible_os_family == 'Darwin'

View File

@@ -1,11 +1,23 @@
# vim: set filetype=yaml.ansible :
---
- ansible.builtin.include_vars:
- name: Linux specific configuration
when:
- ansible_os_family != 'Darwin'
block:
- name: Load lua-language-server config
ansible.builtin.include_vars:
file: lua-language-server.yml
name: _luals
- ansible.builtin.set_fact:
- name: Combine loaded config with defaults
ansible.builtin.set_fact:
pkgconfig_luals: "{{ _luals | ansible.builtin.combine(pkgconfig.luals) }}"
- name: append to pkgs
- name: Append to pkgs
ansible.builtin.set_fact:
srcpkgs: "{{ srcpkgs + ['lua-language-server'] }}"
- name: Append to syspkgs
when:
- ansible_os_family == 'Darwin'
ansible.builtin.set_fact:
syspkgs: "{{ syspkgs + ['lua-language-server'] }}"

View File

@@ -1,4 +1,4 @@
# vim: set filetype=yaml.ansible :
---
version: 0.15.0
install_prefix: "{{ default_config.install_prefix }}"
install_prefix: "{{ default_install_prefix }}"

View File

@@ -1,9 +1,8 @@
# vim: set filetype=yaml.ansible :
---
install_prefix: "{{ default_config.install_prefix }}"
install_dir: /opt/bitwarden
use_flatpak: true
use_appimage: false
install_prefix: "{{ default_install_prefix }}"
install_dir: /opt/appimage/bitwarden
install_method: flatpak
dobecome: true
owner: root
group: root

View File

@@ -1,4 +1,4 @@
# vim: set filetype=yaml.ansible :
---
version: 1.23.6
install_path: "{{ default_config.install_prefix }}"
install_path: "{{ default_install_prefix }}"

View File

@@ -1,5 +1,5 @@
# vim: set filetype=yaml.ansible :
---
version: 3.13.5
install_prefix: "{{ default_config.install_prefix }}"
install_prefix: "{{ default_install_prefix }}"
install_path: /opt/lua-language-server

View File

@@ -1,39 +1,33 @@
# vim: set filetype=yaml.ansible :
# variables used in ansible_role_package
---
assume_missing_is_syspkg: true
full_upgrade: false
install_state: present
default_config:
install_prefix: /usr/local
become: true
owner: root
group: root
default_install_prefix: /usr/local
packages: [] # list of packages to install
# install lists
brewtaps: []
cargopkgs: []
cargoversioned: []
caskpkgs: []
flatpkgs: []
flatpkg_repo:
# Package install lists
appimages: [] # appimages to install
cargopkgs: [] # rust packages from cargo
cargoversioned: [] # versioned rust packages from cargo
caskpkgs: [] # homebrew casks
flatpkgs: [] # flatpaks
gopkgs: [] # go applications
npmpkgs: [] # npm commands
pipxpkgs: [] # pipx packages
srcpkgs: [] # packages built from source
syspkgs: [] # system package manager packages
tappkgs: [] # homebrew tap packages
# Package source lists
brewtaps: [] # homebrew taps
fpremotes: # flatpak remotes
- name: flathub
url: https://dl.flathub.org/repo/flathub.flatpakrepo
gopkgs: []
npmpkgs: []
packages: []
pipxpkgs: []
srcpkgs: []
syspkgs: []
tappkgs: []
# pkgconfig, loaded from .yml files in vars
# and combined. Configuration can be changed
# when running the role by specifying
# pkgconfig.<pkgname> as a dict
# Static package configuration
# this shouldn't be changed by the user
pkgconfig:
alacritty:
deps:
build_deps:
RedHat:
- cmake
- freetype-devel
@@ -50,10 +44,15 @@ pkgconfig:
- libxkbcommon-dev
- python3
git_repo: https://github.com/alacritty/alacritty.git
bitwarden: {}
bitwarden:
flatpak:
name: com.bitwarden.desktop
remote: flathub
appimage:
name: bitwarden.appimage
url: https://vault.bitwarden.com/download/?app=desktop&platform=linux&variant=appimage
broot:
deps:
build_deps:
Debian:
- build-essential
- libxcb1-dev
@@ -89,7 +88,7 @@ pkgconfig:
- fd-find
flatpak: {}
ghostty:
deps:
build_deps:
Debian:
- libgtk-4-dev
- libadwaita-1-dev
@@ -166,7 +165,7 @@ pkgconfig:
x86_64: x64
neovide:
git_repo: https://github.com/neovide/neovide.git
deps:
build_deps:
RedHat:
- fontconfig-devel
- freetype-devel
@@ -338,7 +337,7 @@ pkgconfig:
Linux: nomad
Darwin: hashicorp/tap/nomad
nushell:
deps:
build_deps:
Darwin:
- openssl
- cmake
@@ -437,7 +436,7 @@ pkgconfig:
Debian:
- zfs-dkms
- zfsutils-linux
deps:
build_deps:
RedHat:
- kernel-devel
- epel-release

View File

@@ -1,4 +1,4 @@
# vim: set filetype=yaml.ansible :
---
version: 0.14.0
install_prefix: "{{ default_config.install_prefix }}"
install_prefix: "{{ default_install_prefix }}"

View File

@@ -1,7 +1,7 @@
# vim: set filetype=yaml.ansible :
---
version: v0.10.3
install_prefix: "{{ default_config.install_prefix }}"
install_prefix: "{{ default_install_prefix }}"
install_dir: /opt/nvim
use_appimage: true
use_syspkg: true

View File

@@ -1,5 +1,5 @@
# vim: set filetype=yaml.ansible :
---
version: 0.13.0
install_prefix: "{{ default_config.install_prefix }}"
install_prefix: "{{ default_install_prefix }}"
install_path: /opt/zig

View File

@@ -1,5 +1,5 @@
# vim: set filetype=yaml.ansible :
---
version: 0.13.0
install_prefix: "{{ default_config.install_prefix }}"
install_prefix: "{{ default_install_prefix }}"
install_path: /opt/zls