From e39c3b70461ef2418ec132222814e1d666f8afe3 Mon Sep 17 00:00:00 2001 From: Matthew Stobbs Date: Sun, 15 Feb 2026 17:57:05 -0700 Subject: [PATCH] working on cleanup and fixing a few format issues - modifying how installs are done --- tasks/facts.yml | 8 ++- tasks/helpers/cargo_build.yml | 51 ++++++----------- tasks/helpers/clean_install.yml | 17 +++++- tasks/helpers/git.yml | 12 ++-- tasks/helpers/install.yml | 40 +++++++++++++ tasks/internal/remove_empty_dir.yml | 16 ++++++ tasks/main.yml | 5 +- tasks/pkgs/air.yml | 19 +++---- tasks/pkgs/alacritty.yml | 27 ++++----- vars/main.yml | 58 +------------------ vars/pkglist.yml | 87 ++++++++++++++++++++++++++--- 11 files changed, 201 insertions(+), 139 deletions(-) create mode 100644 tasks/helpers/install.yml create mode 100644 tasks/internal/remove_empty_dir.yml diff --git a/tasks/facts.yml b/tasks/facts.yml index 1f41fa8..bd218cd 100644 --- a/tasks/facts.yml +++ b/tasks/facts.yml @@ -19,12 +19,18 @@ path_archive: "{{ install_prefix }}/archive" path_bin: "{{ install_prefix }}/bin" path_cargo: "{{ install_prefix }}/cargo" - path_git: "{{ install_prefix }}/git" + path_source: "{{ install_prefix }}/source" path_go: "{{ install_prefix }}/go" path_pipx: "{{ install_prefix }}/pipx" store_path: "{{ ansible_facts['user_dir'] }}/.cache/ansible_role_package" path_lib: "{{ install_prefix }}/lib" +- name: Set install_become_group from install_become_user + block: + - name: Get install_become_user userinfo + ansible.builtin.getent: + database: passwd + key: "{{ install_become_user }}" - name: Set Linux specific facts when: diff --git a/tasks/helpers/cargo_build.yml b/tasks/helpers/cargo_build.yml index 830ed9c..6dd2ba8 100644 --- a/tasks/helpers/cargo_build.yml +++ b/tasks/helpers/cargo_build.yml @@ -4,48 +4,29 @@ block: - name: Fetch git repo vars: - git: - path: "{{ d_cache.path }}/{{ cargo_build.name }}" - repo: "{{ cargo_build.repo }}" - depth: "{{ cargo_build.depth | default(1) }}" - force: "{{ cargo_build.force_git | default(true) }}" - recursive: "{{ cargo_build.recursive | default(true) }}" - version: "{{ cargo_build.version | default(omit) }}" - ansible.builtin.include_tasks: - file: helpers/git.yml + path: "{{ path_source }}/{{ cargo_build.source_dir }}" + repo: "{{ cargo_build.repo }}" + depth: "{{ cargo_build.depth | default(1) }}" + force: "{{ cargo_build.force_git | default(true) }}" + recursive: "{{ cargo_build.recursive | default(true) }}" + version: "{{ cargo_build.version | default(omit) }}" + ansible.builtin.include_tasks: helpers/git.yml - name: Build cargo release ansible.builtin.command: - chdir: "{{ d_cache.path }}/{{ cargo_build.name }}" + chdir: "{{ path_source }}/{{ cargo_build.source_dir }}" argv: "{{ [cargo, build] + cargo_build.build_flags }}" + - name: Clean existing install + vars: + files: "{{ cargo_build.files }}" + ansible.builtin.include_tasks: helpers/clean.yml + - name: Install cargo release block: - name: Create missing directories become: "{{ install_become }}" become_user: "{{ install_become_user }}" - loop: "{{ cargo_build.files }}" - loop_control: - loop_var: file - ansible.builtin.file: - state: directory - path: "{{ install_prefix }}/{{ file.to | dirname }}" - mode: '0755' - owner: "{{ cargo_build.owner | default(ansible_user_id) }}" - group: "{{ cargo_build.group | default(ansible_user_gid) }}" - - - name: Install release files - become: "{{ install_become }}" - become_user: "{{ install_become_user }}" - loop: "{{ cargo_build.files }}" - loop_control: - loop_var: file - ansible.builtin.copy: - backup: false - remote_src: true - src: "{{ d_cache.path }}/{{ cargo_build.name }}/{{ file.from }}" - dest: "{{ install_prefix }}/{{ file.to }}" - owner: "{{ cargo_build.owner | default(ansible_user_id) }}" - group: "{{ cargo_build.group | default(ansible_user_gid) }}" - mode: "{{ file.mode | default('0644') }}" - force: "{{ file.force | default(true) }}" + vars: + source_dir: "{{ cargo_build.source_dir }}" + ansible.builtin.include_tasks: helpers/install.yml diff --git a/tasks/helpers/clean_install.yml b/tasks/helpers/clean_install.yml index cdda8f8..f5abb20 100644 --- a/tasks/helpers/clean_install.yml +++ b/tasks/helpers/clean_install.yml @@ -1,10 +1,21 @@ # vim: set filetype=yaml.ansible : --- - name: Remove file list - become: true - loop: "{{ file_list }}" + become: "{{ install_become }}" + become_user: "{{ install_become_user }}" + loop: "{{ files }}" loop_control: loop_var: file + when: + - file.to is defined ansible.builtin.file: state: absent - path: "{{ file }}" + path: "{{ install_prefix }}/{{ file.to }}" + +- name: Check for and remove empty directories + loop: "{{ files }}" + loop_control: + loop_var: dir + when: + - file.directory is defined + ansible.builtin.include_tasks: internal/remove_empty_dir.yml diff --git a/tasks/helpers/git.yml b/tasks/helpers/git.yml index 575fe35..e6629a3 100644 --- a/tasks/helpers/git.yml +++ b/tasks/helpers/git.yml @@ -2,9 +2,9 @@ --- - name: Clone git repository ansible.builtin.git: - depth: "{{ git.depth | default(1) }}" - dest: "{{ git.path }}" - force: "{{ git.force | default(true) }}" - recursive: "{{ git.recursive | default(true) }}" - repo: "{{ git.repo }}" - version: "{{ git.version | default(omit) }}" + dest: "{{ path }}" + repo: "{{ repo }}" + depth: "{{ depth | default(1) }}" + force: "{{ force | default(true) }}" + recursive: "{{ recursive | default(true) }}" + version: "{{ version | default(omit) }}" diff --git a/tasks/helpers/install.yml b/tasks/helpers/install.yml new file mode 100644 index 0000000..df3fbd9 --- /dev/null +++ b/tasks/helpers/install.yml @@ -0,0 +1,40 @@ +# vim: set filetype=yaml.ansible : +# +## Helper: install.yml +## Description: install files defined in dict +## Variables: +## _Note_ This is mutually exclusive to having a 'to' key +## - directory: path prefixed by {{ install_prefix }} of a directory to +## be created +## mode: _optional_, _default_ '0755' +## +## _Note_ This is mutually exclusive to having a 'directory' key +## - to: where to install file to, prefixed with {{ install_prefix }} +## from: source file from build path root for package +## mode: _optional_, _default_ '0644'## +## +## Notes: This is only used when copying files or creating directories +## for installing. If a source package doesn't require you to manually +## copy anthing (go install, as an example), don't use this. +--- +- name: Create directories + become: "{{ install_become }}" + become_user: "{{ install_become_user }}" + loop: "{{ pkg_clean }}" + loop_control: + loop_var: dir + when: + - dir.directory is defined + ansible.builtin.file: + state: directory + mode: '0755' + path: "{{ install_prefix }}/{{ dir.directory }}" + +- name: Copy installable files + become: "{{ install_become }}" + become_user: "{{ install_become_user }}" + loop: "{{ pkg_clean }}" + ansible.builtin.copy: + dest: "{{ install_prefix }}/{{ file.to }}" + mode: "{{ file.mode | default('0644') }}" + src: "{{ file.builddir | default(omit) }}/" diff --git a/tasks/internal/remove_empty_dir.yml b/tasks/internal/remove_empty_dir.yml new file mode 100644 index 0000000..724848c --- /dev/null +++ b/tasks/internal/remove_empty_dir.yml @@ -0,0 +1,16 @@ +# vim: set filetype=yaml.ansible : +--- +- name: Check if dir is empty + ansible.builtin.find: + paths: + - "{{ dir }}" + file_type: any + hidden: true + register: fd_empty + +- name: Remove empty dir + when: + - fd_empty.matched|int == 0 + ansible.builtin.file: + path: "{{ dir }}" + state: absent diff --git a/tasks/main.yml b/tasks/main.yml index c2937d6..d6008bf 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -26,7 +26,7 @@ - "{{ path_archive }}" - "{{ path_bin }}" - "{{ path_cargo }}" - - "{{ path_git }}" + - "{{ path_source }}" - "{{ path_pipx }}" loop_control: loop_var: path @@ -70,6 +70,9 @@ ansible.builtin.include_tasks: file: "pkgs/{{ pkg }}.yml" +- name: Clean installations that require it + ansible.builtin.include_tasks: "helpers/clean_install.yml" + - name: Install go if required when: - pkg_go|length > 0 diff --git a/tasks/pkgs/air.yml b/tasks/pkgs/air.yml index c0296ac..75644dd 100644 --- a/tasks/pkgs/air.yml +++ b/tasks/pkgs/air.yml @@ -15,7 +15,7 @@ when: - air_install_method is undefined ansible.builtin.set_fact: - air_install_method: "{{ install_method if install_method in air_install_methods else air_install_methods[0] }}" + air_install_method: "{{ install_method if install_method in air.install_methods else air.install_methods[0] }}" - name: Set air build facts when: @@ -27,6 +27,7 @@ url: "{{ air_install_url }}@{{ air_version }}" bin: "{{ path_bin }}/air" # }}} +# {{{ air build and install steps - name: Append air to pkg_go when: - air_install_method == 'source' @@ -34,23 +35,19 @@ - name: Clean existing air install when: - clean_install - loop: "{{ air_build_files }}" - loop_control: - loop_var: air_file - ansible.builtin.file: - state: absent - path: "{{ install_prefix }}/{{ air_file }}" + ansible.builtin.set_fact: + pkg_clean: "{{ pkg_clean + air.install_files }}" - name: Configure pkg dependencies - loop: "{{ air_pkg_deps }}" + loop: "{{ air.pkg_deps }}" loop_control: - loop_var: air_pkg_dep - ansible.builtin.include_tasks: "{{ air_pkg_dep }}" + loop_var: pkg + ansible.builtin.include_tasks: "pkgs/{{ pkg }}.yml" - name: Add air to install list ansible.builtin.set_fact: pkg_go: "{{ pkg_go + [air_go_pkg] }}" - +# }}} - name: Finalize air configuration ansible.builtin.set_fact: __configured: "{{ __configured | combine( { 'air': true } ) }}" diff --git a/tasks/pkgs/alacritty.yml b/tasks/pkgs/alacritty.yml index cdb68eb..b82037c 100644 --- a/tasks/pkgs/alacritty.yml +++ b/tasks/pkgs/alacritty.yml @@ -17,7 +17,7 @@ when: - alacritty_install_method is undefined ansible.builtin.set_fact: - alacritty_install_method: "{{ install_method if install_method in alacritty_install_methods else alacritty_install_methods[0] }}" + alacritty_install_method: "{{ install_method if install_method in alacritty.install_methods else alacritty.install_methods[0] }}" - name: Configure alacritty source install when: @@ -25,20 +25,13 @@ block: - name: Set alacritty build facts ansible.builtin.set_fact: - alacritty_build_deps: "{{ alacritty_build_deps[ansible_os_family] }}" alacritty_src_install: + build_deps: "{{ alacritty.build_deps[ansible_facts['os_family']] }}" build_flags: "{{ alacritty_cargo_build_flags }}" - name: "{{ alacritty_pkgname }}" + source_dir: "{{ alacritty.install_files.source_dir }}" repo: "{{ alacritty_git_repo }}" version: "{{ alacritty_version }}" - files: - - from: target/release/alacritty - to: bin/alacritty - mode: '0755' - - from: extra/logo/alacritty-term.svg - to: share/pixmaps/Alacritty.svg - - from: extra/linux/Alacritty.desktop - to: share/applications/Alacritty.desktop + files: "{{ alacritty.install_files.files }}" - name: Set alacritty install extra build deps when: @@ -49,13 +42,13 @@ when: - ansible_distribution_major_version == 7 ansible.builtin.set_fact: - alacritty_build_deps: "{{ alacritty_build_deps + ['xcb-util-devel', '@Development Tools'] }}" + alacritty_build_deps: "{{ build_deps + ['xcb-util-devel', '@Development Tools'] }}" - name: Add extra dependencies for EL8 when: - ansible_distribution_major_version == 8 ansible.builtin.set_fact: - alacritty_build_deps: "{{ alacritty_build_deps + ['@Development Tools'] }}" + alacritty_build_deps: "{{ build_deps + ['@Development Tools'] }}" # }}} - name: Append alacritty installation @@ -65,14 +58,14 @@ - alacritty_method == 'source' block: - name: Configure pkg dependencies - loop: "{{ alacritty_pkg_deps }}" + loop: "{{ alacritty.pkg_deps }}" loop_control: - loop_var: alacritty_pkg_dep - ansible.builtin.include_tasks: "{{ alacritty_pkg_dep }}" + loop_var: pkg + ansible.builtin.include_tasks: "pkgs/{{ pkg }}.yml" - name: Append build dependencies and cargo config ansible.builtin.set_fact: - pkg_sys: "{{ pkg_sys + alacritty_build_deps }}" + pkg_sys: "{{ pkg_sys + build_deps }}" pkg_cargo_build: "{{ pkg_cargo_build + [alacritty_src_install] }}" - name: Append alacritty to pkg_sys diff --git a/vars/main.yml b/vars/main.yml index 9140051..766265b 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -28,6 +28,7 @@ pkg_appimage: [] # appimages to install pkg_archive: [] # packages installed via prebuilt archive pkg_cargo: [] # rust packages from cargo using `cargo install` pkg_cargo_build: [] # rust packages using `cargo build` before install +pkg_clean: [] # list of files to remove before running archive and source installations pkg_flatpak: [] # flatpak packages to install pkg_go: [] # go applications pkg_npm: [] # npm commands @@ -45,71 +46,14 @@ __var_to_env: {} # dict of variables to add to your env # Per package variables # {{{ air air_version: latest -air_build_files: - - bin/air air_install_url: github.com/air-verse/air -air_pkg_deps: - - pkgs/go.yml # }}} # {{{ alacritty alacritty_version: v0.16.1 alacritty_git_repo: https://github.com/alacritty/alacritty alacritty_pkgname: alacritty -alacritty_pkg_deps: - - pkgs/git.yml - - pkgs/cargo.yml -alacritty_build_files: - - bin/alacritty - - share/pixmaps/Alacritty.svg - - share/applications/Alacritty.desktop alacritty_cargo_build_flags: - --release -alacritty_build_deps: - RedHat: - - cmake - - fontconfig-devel - - freetype-devel - - g++ - - libxcb-devel - - libxkbcommon-devel - - desktop-file-utils - Debian: - - cmake - - g++ - - pkg-config - - libfontconfig1-dev - - libxcb-xfixes0-dev - - libxkbcommon-dev - - python3 - - libfreetype6-dev - - desktop-file-utils - Alpine: - - cmake - - pkgconf - - freetype-dev - - fontconfig-dev - - python3 - - libxcb-dev - - g++ - - libxkbcommon-dev - - desktop-file-utils - Archlinux: - - cmake - - freetype2 - - fontconfig - - pkg-config - - make - - libxcb - - libxkbcommon - - python - - desktop-file-utils - FreeBSD: - - cmake - - freetype2 - - fontconfig - - pkgconf - - python3 - - desktop-file-utils # }}} # {{{ ansible ansible_install_methods: diff --git a/vars/pkglist.yml b/vars/pkglist.yml index 641fff0..00c7da6 100644 --- a/vars/pkglist.yml +++ b/vars/pkglist.yml @@ -5,14 +5,85 @@ ## Restrictions for package install methods. ## The first item is the default method. If only ## one method exists, all others are ignored. -air_install_methods: - - source -alacritty_install_methods: - - source - - system -ansible_lint_install_methods: - - pipx - - system +air: # {{{ + install_methods: + - source + install_files: + - to: bin/air + pkg_deps: + - go +# }}} +alacritty: # {{{ + install_methods: + - source + - system + install_files: + source_dir: alacritty + files: + - from: target/release/alacritty + to: bin/alacritty + mode: '0755' + - from: extra/logo/alacritty-term.svg + to: share/pixmaps/Alacritty.svg + mode: '0644' + - from: extra/linux/Alacritty.desktop + to: share/applications/Alacritty.desktop + mode: '0644' + pkg_deps: + - git + - cargo + sys_build_deps: + RedHat: + - cmake + - fontconfig-devel + - freetype-devel + - g++ + - libxcb-devel + - libxkbcommon-devel + - desktop-file-utils + Debian: + - cmake + - g++ + - pkg-config + - libfontconfig1-dev + - libxcb-xfixes0-dev + - libxkbcommon-dev + - python3 + - libfreetype6-dev + - desktop-file-utils + Alpine: + - cmake + - pkgconf + - freetype-dev + - fontconfig-dev + - python3 + - libxcb-dev + - g++ + - libxkbcommon-dev + - desktop-file-utils + Archlinux: + - cmake + - freetype2 + - fontconfig + - pkg-config + - make + - libxcb + - libxkbcommon + - python + - desktop-file-utils + FreeBSD: + - cmake + - freetype2 + - fontconfig + - pkgconf + - python3 + - desktop-file-utils +# }}} +ansible_lint: # {{{ + install_methods: + - pipx + - system +# }}} ansible_install_methods: - system ansible_ls_install_methods: