reorganizing configuration

- static package configuration in `vars/pkgs`
  - loaded into the variable `pkgconfig` as part of `tasks/main.yml`
This commit is contained in:
Matthew Stobbs
2025-02-12 12:52:55 -07:00
parent 9250145116
commit a3df5215b8
23 changed files with 259 additions and 226 deletions

7
tasks/config/air.yml Normal file
View File

@@ -0,0 +1,7 @@
# vim: set filetype=yaml.ansible :
---
- name: Set configuration for air
ansible.builtin.set_fact:
air:
ver: "{{ pkgconfig.air.version }}"
pkg: "{{ pkgconfig.air.git_repo }}@{{ pkgconfig.air.version }}"

View File

@@ -1,4 +1,22 @@
# vim: set filetype=yaml.ansible :
---
version: 1.23.6
install_path: "{{ default_install_prefix }}"
- name: Set go configuration
ansible.builtin.set_fact:
do_install_go: false # defaults to false to save on having to set facts needlessly
go:
ver: "{{ pkgconfig.go.version }}"
arch: "{{ pkgconfig_go.archmap[ansible_architecture] }}"
sys: "{{ ansible_system | lower }}"
ext: "{{ pkgconfig.go.extmap[ansible_system] }}"
- name: Set go composite facts
ansible.builtin.set_fact:
go:
ver: "{{ go.ver }}"
arch: "{{ go.arch }}"
sys: "{{ go.sys }}"
ext: "{{ go.ext }}"
archive: "go{{ go.ver }}.{{ go.sys }}-{{ go.arch }}.{{ pkgconfig_go.extmap[ansible_system] }}"
sum: "{{ pkgconfig.go.sums[go.ver][ansible_system][go.arch] }}"
url: "{{ pkgconfig.go.base_url }}/{{ go.archive }}"
inst_path: "{{ paths.install }}/go"

View File

@@ -2,8 +2,24 @@
---
# 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 }}"
flatpak_method: user
- name: Set facts based on use_local == false
when:
- not use_local
ansible.builtin.set_fact:
paths: "{{ sys_paths }}"
flatpak_method: system
- name: Set installation facts
ansible.builtin.set_fact:
bin_dir: "{{ paths.install }}/bin"
state_dir: "{{ paths.install }}/state"
app_images: [] # app_images to install
cargo_pkgs: [] # rust packages from cargo
cask_pkgs: [] # homebrew casks
@@ -19,39 +35,42 @@
- name: flathub
url: https://dl.flathub.org/repo/flathub.flatpakrepo
- name: Set facts based on use_local == true
when:
- use_local
ansible.builtin.set_fact:
paths: "{{ local_paths }}"
flatpak_method: user
- name: Set facts based on use_local == false
when:
- not use_local
ansible.builtin.set_fact:
paths: "{{ sys_paths }}"
flatpak_method: system
- name: Set macOS specific facts
when:
- ansible_distribution == 'MacOSX'
ansible.builtin.set_fact:
pipx_exec: /opt/homebrew/bin/pipx
- name: Determine OS and set facts for it
- ansible_system == 'Darwin'
block:
- name: Set macOS facts
when: ansible_os_family == 'Darwin'
- 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
when: ansible_system == 'Linux'
ansible.builtin.set_fact:
sys_pkg_become: true
- name: Ensure required paths exist
become: "{{ not use_local }}"
loop: "{{ paths + [bin_dir, state_dir] }}"
loop_control:
loop_var: path
ansible.builtin.file:
state: directory
mode: '0755'
path: "{{ path }}"
- name: Read default package configuration
ansible.builtin.include_vars:
dir: pkgs
extensions:
- yml
name: pkgconfig
- name: Generate package installation lists
ansible.builtin.include_tasks:
file: addpkg.yml
@@ -155,10 +174,10 @@
name: "{{ flatpak.name }}"
remote: "{{ flatpak.remote | default('flathub') }}"
- name: Ensure /usr/local/bin exists
- name: Ensure prefix/bin exists
ansible.builtin.file:
state: directory
path: /usr/local/bin
path: "{{ paths.install }}/bin"
owner: root
mode: '0755'
become: true

View File

@@ -1,9 +1,7 @@
# vim: set filetype=yaml.ansible :
---
- ansible.builtin.include_tasks:
file: pkgs/go.yml
when: pkgconfig_go is undefined
- name: add to gopkgs
- name: Add to go_pkgs
notify:
- Depend go
ansible.builtin.set_fact:
gopkgs: "{{ gopkgs + ['github.com/air-verse/air@latest'] }}"
go_pkgs: "{{ go_pkgs + [air.pkg] }}"

View File

@@ -1,11 +1,5 @@
# vim: set filetype=yaml.ansible :
---
- ansible.builtin.include_vars:
file: go.yml
name: _go
- ansible.builtin.set_fact:
pkgconfig_go: "{{ _go | ansible.builtin.combine(pkgconfig.go) }}"
- name: append to pkgs
- name: Append to pkgs
ansible.builtin.set_fact:
srcpkgs: "{{ srcpkgs + [ 'go' ] }}"
src_pkgs: "{{ src_pkgs + ['go'] }}"

View File

@@ -1,52 +1,40 @@
# vim: set filetype=yaml.ansible :
---
- name: check go version
ansible.builtin.command:
cmd: "go version"
register: r_go_version
ignore_errors: true
- name: Check if archive already exists
ansible.builtin.stat:
path: "{{ paths.archive }}/{{ go_archive }}"
register: stat_go_archive
- name: install/update go
- name: Install/update go
when:
- not stat_go_archive.exists
block:
- name: set go arch
ansible.builtin.set_fact:
arch: "{{ pkgconfig_go.archmap[ansible_architecture] }}"
- name: set go archive filename
ansible.builtin.set_fact:
go_archive: "go{{ pkgconfig_go.version }}.{{ ansible_system | lower }}-{{ arch }}.{{ pkgconfig_go.extmap[ansible_system] }}"
- name: create temp path
ansible.builtin.tempfile:
state: directory
prefix: go_dl.
register: d_go_dl_tmp
- name: download go archive
become: true
- name: Download go archive
become: "{{ sys_pkg_become }}"
ansible.builtin.get_url:
dest: "{{ d_go_dl_tmp.path }}/{{ go_archive }}"
url: "https://go.dev/dl/{{ go_archive }}"
checksum: "{{ pkgconfig_go.sums[pkgconfig_go.version][ansible_system][arch] }}"
dest: "{{ paths.cache }}/{{ go_archive }}"
url: "{{ go.url }}"
checksum: "{{ go.sum }}"
decompress: false
mode: '0644'
- name: ensure go install dir exists
become: true
- name: Ensure go install dir exists
become: "{{ sys_pkg_become }}"
ansible.builtin.file:
path: "{{ pkgconfig_go.install_path }}"
path: "{{ go.inst_path }}"
state: directory
mode: '0755'
- name: extract go package
- name: Extract go package
become: "{{ sys_pkg_become }}"
ansible.builtin.unarchive:
dest: "{{ pkgconfig_go.install_path }}"
dest: "{{ paths.archive }}/go"
src: "{{ d_go_dl_tmp.path }}/{{ go_archive }}"
remote_src: true
when: ansible_system == 'Linux'
become: true
- name: install go macOS use pkg file
- name: Install go macOS use pkg file
ansible.builtin.command:
cmd: "installer -pkg {{ d_go_dl_tmp.path }}/{{ go_archive }} -target /"
when: ansible_system == 'Darwin'
become: true
when: pkgconfig_go.version not in r_go_version.stdout