From 17ed8354c0450ecbdc8f2c5157ff195375875fa6 Mon Sep 17 00:00:00 2001 From: Matthew Stobbs Date: Thu, 13 Feb 2025 11:06:56 -0700 Subject: [PATCH] working through each file --- handlers/main.yml | 12 ++ tasks/cargo.yml | 9 ++ tasks/facts.yml | 49 +++++++ tasks/homebrew.yml | 0 tasks/linux.yml | 31 +++++ tasks/macos.yml | 18 +++ tasks/main.yml | 195 ++++----------------------- tasks/npm.yml | 8 ++ tasks/pipx.yml | 8 ++ tasks/pkgs/alacritty.yml | 7 +- tasks/pkgs/rust.yml | 10 +- tasks/{pkgs => repos}/terra_repo.yml | 0 12 files changed, 163 insertions(+), 184 deletions(-) create mode 100644 tasks/facts.yml delete mode 100644 tasks/homebrew.yml create mode 100644 tasks/linux.yml create mode 100644 tasks/macos.yml create mode 100644 tasks/npm.yml rename tasks/{pkgs => repos}/terra_repo.yml (100%) diff --git a/handlers/main.yml b/handlers/main.yml index cfe3e7b..bea301b 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -5,3 +5,15 @@ file: addpkg.yml vars: pkg: go + +- name: Depend cargo + vars: + pkg: cargo + ansible.builtin.include_tasks: + file: addpkg.yml + +- name: Depend rust + vars: + pkg: rust + ansible.builtin.include_tasks: + file: addpkg.yml diff --git a/tasks/cargo.yml b/tasks/cargo.yml index e69de29..3c22986 100644 --- a/tasks/cargo.yml +++ b/tasks/cargo.yml @@ -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 }}" diff --git a/tasks/facts.yml b/tasks/facts.yml new file mode 100644 index 0000000..b748b90 --- /dev/null +++ b/tasks/facts.yml @@ -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 diff --git a/tasks/homebrew.yml b/tasks/homebrew.yml deleted file mode 100644 index e69de29..0000000 diff --git a/tasks/linux.yml b/tasks/linux.yml new file mode 100644 index 0000000..121cd37 --- /dev/null +++ b/tasks/linux.yml @@ -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 diff --git a/tasks/macos.yml b/tasks/macos.yml new file mode 100644 index 0000000..adc94d2 --- /dev/null +++ b/tasks/macos.yml @@ -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(' ') }}" diff --git a/tasks/main.yml b/tasks/main.yml index 12034c5..56fc4b5 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -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 diff --git a/tasks/npm.yml b/tasks/npm.yml new file mode 100644 index 0000000..1b6e8ad --- /dev/null +++ b/tasks/npm.yml @@ -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 diff --git a/tasks/pipx.yml b/tasks/pipx.yml index e69de29..29ef20e 100644 --- a/tasks/pipx.yml +++ b/tasks/pipx.yml @@ -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 diff --git a/tasks/pkgs/alacritty.yml b/tasks/pkgs/alacritty.yml index 8567896..9a50439 100644 --- a/tasks/pkgs/alacritty.yml +++ b/tasks/pkgs/alacritty.yml @@ -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] }}" diff --git a/tasks/pkgs/rust.yml b/tasks/pkgs/rust.yml index 8562078..f7710c3 100644 --- a/tasks/pkgs/rust.yml +++ b/tasks/pkgs/rust.yml @@ -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 }}" diff --git a/tasks/pkgs/terra_repo.yml b/tasks/repos/terra_repo.yml similarity index 100% rename from tasks/pkgs/terra_repo.yml rename to tasks/repos/terra_repo.yml