working through each file

This commit is contained in:
Matthew Stobbs
2025-02-13 11:06:56 -07:00
parent c73ac46bc8
commit 17ed8354c0
12 changed files with 163 additions and 184 deletions

View File

@@ -0,0 +1,9 @@
# vim: set filetype=yaml.ansible
---
- name: Install cargo pkg
become: "{{ archive_become }}"
community.general.cargo:
name: "{{ pkg.cargo.pkg }}"
version: "{{ pkg.ver }}"
path: "{{ paths.cargo }}"
locked: "{{ pkg.cargo.locked }}"

49
tasks/facts.yml Normal file
View File

@@ -0,0 +1,49 @@
# vim: set filetype=yaml.ansible :
---
- name: Set facts for installation
ansible.builtin.set_fact:
ext_become: "{{ not use_local }}" # if use_local is true, don't use sudo for external packages
path_prefix: "{% if use_local %}{{ lookup(ansible.builtin.env, 'HOME') }}{% else %}{{ defaults.path.prefix }}{% endif %}"
- name: Set Linux specific facts
when:
- ansible_system == 'Linux'
ansible.builtin.set_fact:
app_images: [] # app_images to install
flatpak_method: "{% if use_local %}user{% else %}system{% endif %}"
flatpak_remotes: # flatpak remotes, includes flathub by default
- name: flathub
url: https://dl.flathub.org/repo/flathub.flatpakrepo
flatpaks: [] # flatpak packages to install
snap_pkgs: [] # snpacraft.io packages
sys_pkg_become: true # Linux package managers require sudo access
- name: Set macOS specific facts
when:
- ansible_distribution == 'MacOSX'
ansible.builtin.set_fact:
brew_taps: [] # homebrew taps to add
cask_pkgs: [] # homebrew casks
pipx_exec: "/opt/homebrew/bin/pipx"
sys_pkg_become: false # homebrew doesn't require sudo access
tap_pkgs: [] # homebrew tap packages
- 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 OS independant facts
ansible.builtin.set_fact:
archive_pkgs: [] # packages installed via prebuilt archive
cargo_pkgs: [] # rust packages from cargo
go_pkgs: [] # go applications
npm_pkgs: [] # npm commands
pipx_pkgs: [] # pipx packages
src_pkgs: [] # packages built from source
sys_pkgs: [] # system package manager packages, homebrew on macOS, dnf for RedHat based, apt for Debian Based

View File

31
tasks/linux.yml Normal file
View File

@@ -0,0 +1,31 @@
# vim: set filetype=yaml.ansible :
---
- name: Install flatpaks on Linux Systems
when:
- flatpaks|length > 0
block:
- name: Add flatpak remotes
when:
- flatpak_remotes|length > 0
become: "{{ ext_become }}"
loop: "{{ flatpak_remotes | unique }}"
loop_control:
loop_var: remote
community.general.flatpak_remote:
enabled: true
flatpakrepo_url: "{{ remote.url }}"
method: "{{ flatpak_method }}"
name: "{{ remote.name }}"
state: present
- name: Install flatpaks
become: "{{ ext_become }}"
loop: "{{ flatpaks | unique }}"
loop_control:
loop_var: flatpak
community.general.flatpak:
method: "{{ flatpak_method }}"
name: "{{ flatpak.name }}"
remote: "{{ flatpak.remote | default('flathub') }}"
state: present

18
tasks/macos.yml Normal file
View File

@@ -0,0 +1,18 @@
# vim: set filetype=yaml.ansible :
---
- name: Tap homebrew taps
community.general.homebrew_tap:
name: "{{ brew_taps | unique }}"
state: present
when: brew_taps|length > 0
- name: Install homebrew casks
community.general.homebrew_cask:
name: "{{ cask_pkgs | unique }}"
state: present
when: cask_pkgs|length > 0
# TODO: fix the need to have this workaround
- name: Workaround to install homebrew taps
ansible.builtin.command:
cmd: "brew install {{ (tap_pkgs | unique) | join(' ') }}"

View File

@@ -1,75 +1,11 @@
# vim: set filetype=yaml.ansible :
---
- name: Set facts based on use_local == true
when:
- use_local
ansible.builtin.set_fact:
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:
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:
# 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
go_pkgs: [] # go applications
npm_pkgs: [] # npm commands
pipx_pkgs: [] # pipx packages
src_pkgs: [] # packages built from source
sys_pkgs: [] # system package manager packages
tap_pkgs: [] # homebrew tap packages
ansible.builtin.include_tasks:
file: facts.yml
- name: Ensure required paths exist
become: "{{ dobecome }}"
become: "{{ ext_become }}"
loop: "{{ paths | dict2items }}"
loop_control:
loop_var: path
@@ -86,103 +22,29 @@
name: pkgconfig
- name: Generate package installation lists
ansible.builtin.include_tasks:
file: addpkg.yml
loop: "{{ packages | unique }}"
loop_control:
loop_var: pkg
ansible.builtin.include_tasks:
file: addpkg.yml
- name: Install sys_pkgs list
- name: Install sys_pkgs list using system package manager
become: "{{ sys_pkg_become }}"
ansible.builtin.package:
name: "{{ sys_pkgs | unique }}"
state: present
- name: Redhat based OS
when: ansible_os_family == 'RedHat'
block:
- name: Install dnf packages
become: true
when:
- sys_pkgs|length > 0
ansible.builtin.dnf:
name: "{{ sys_pkgs | unique }}"
state: present
- name: Debian based OS
when: ansible_os_family == 'Debian'
block:
- name: Install apt packages
ansible.builtin.apt:
name: "{{ sys_pkgs | unique }}"
state: "{{ install_state }}"
become: true
when:
- sys_pkgs|length > 0
- name: Linux based OS
when: ansible_system == 'Linux'
ansible.builtin.include_tasks:
file: linux.yml
- name: Darwin/macOS based OS
when: ansible_os_family == 'Darwin'
block:
- name: Upgrade homebrew packages
community.general.homebrew:
name: "*"
state: latest
when: full_upgrade
- name: Tap homebrew taps
community.general.homebrew_tap:
name: "{{ brew_taps | unique }}"
state: present
when: brew_taps|length > 0
- name: Install homebrew packages
community.general.homebrew:
name: "{{ sys_pkgs | unique }}"
state: "{{ install_state }}"
when: sys_pkgs|length > 0
- name: Install homebrew casks
community.general.homebrew_cask:
name: "{{ cask_pkgs | unique }}"
state: "{{ install_state }}"
when: cask_pkgs|length > 0
- name: Workaround to install homebrew taps
ansible.builtin.command:
cmd: "brew install {{ tap_pkg }}"
loop: "{{ tap_pkgs | unique }}"
loop_control:
loop_var: tap_pkg
# TODO: fix the need to have this workaround
- name: Install flatpaks on Linux Systems
when:
- ansible_system == 'Linux'
block:
- name: Add flatpak repos
when:
- flatpak_remotes|length > 0
become: "{{ not use_local }}"
loop: "{{ flatpak_remotes | unique }}"
loop_control:
loop_var: remote
community.general.flatpak_remote:
enabled: true
method: "{{ flatpak_method }}"
state: present
flatpakrepo_url: "{{ remote.url }}"
name: "{{ remote.name }}"
- name: Install flatpaks
become: true
loop: "{{ flatpaks | unique }}"
loop_control:
loop_var: flatpak
community.general.flatpak:
state: latest
method: "{{ flatpak_method }}"
name: "{{ flatpak.name }}"
remote: "{{ flatpak.remote | default('flathub') }}"
when: ansible_distribution == 'MacOSX'
ansible.builtin.include_tasks:
file: macos.yml
- name: Install archive_pkgs
when:
@@ -193,7 +55,7 @@
ansible.builtin.include_tasks:
file: "archive/{{ pkg }}.yml"
- name: Install src_pkgs
- name: Build and install source packages
when:
- src_pkgs|length > 0
loop: "{{ src_pkgs | unique }}"
@@ -205,15 +67,11 @@
- name: Install cargo packages
when:
- cargo_pkgs|length > 0
become: "{{ not use_local }}"
loop: "{{ cargo_pkgs | unique }}"
loop_control:
loop_var: pkg
community.general.cargo:
name: "{{ pkg.cargo.pkg }}"
version: "{{ pkg.ver }}"
path: "{{ paths.cargo }}"
locked: "{{ pkg.cargo.locked }}"
ansible.builtin.include_tasks:
file: cargo.yml
- name: Install go packages
when:
@@ -230,21 +88,16 @@
- name: Install local npm packages
when:
- npm_pkgs|length > 0
become: "{{ archive_become }}"
loop: "{{ npm_pkgs | unique }}"
loop_control:
loop_var: npm_pkg
community.general.npm:
global: true
name: "{{ npm_pkg }}"
state: latest
loop_var: pkg
ansible.builtin.include_tasks:
file: npm.yml
- name: Install python pipx packages for user
loop: "{{ pipx_pkgs | unique }}"
loop_control:
loop_var: pipx_pkg
loop_var: pkg
when: pipx_pkgs|length > 0
community.general.pipx:
executable: "{{ pipx_exec }}"
name: "{{ pipx_pkg }}"
state: latest
ansible.builtin.include_tasks:
file: pipx.yml

8
tasks/npm.yml Normal file
View File

@@ -0,0 +1,8 @@
# vim: set filetype=yaml.ansible :
---
- name: Install npm pkg
become: "{{ archive_become }}"
community.general.npm:
global: true
name: "{{ pkg }}"
state: present

View File

@@ -0,0 +1,8 @@
# vim: set filetype=yaml.ansible :
---
- name: Install pipx pkg
become: "{{ archive_become }}"
community.general.pipx:
executable: "{{ pipx_exec }}"
name: "{{ pipx_pkg }}"
state: latest

View File

@@ -3,12 +3,9 @@
- name: Linux based installation
when: ansible_system == 'Linux'
block:
- name: Install rust and cargo
ansible.builtin.include_tasks:
file: "pkgs/rust.yml"
when: pkgconfig_rust is undefined
- name: Append to pkgs
notify:
- Depend cargo
ansible.builtin.set_fact:
syspkgs: "{{ syspkgs + alacritty.deps }}"
srcpkgs: "{{ cargopkgs + [alacritty] }}"

View File

@@ -1,11 +1,5 @@
# vim: set filetype=yaml.ansible :
---
- ansible.builtin.include_vars:
file: rust.yml
name: _rust
- ansible.builtin.set_fact:
pkgconfig_rust: "{{ _rust | ansible.builtin.combine(pkgconfig.rust) }}"
- name: append to pkgs
- name: Append to pkgs
ansible.builtin.set_fact:
syspkgs: "{{ syspkgs + pkgconfig_rust.pkgs[ansible_system] }}"
syspkgs: "{{ syspkgs + pkgconfig.rust.pkgs }}"