Files
ansible_role_package/tasks/main.yml
2025-02-11 22:14:04 -07:00

219 lines
5.7 KiB
YAML

# vim: set filetype=yaml.ansible :
---
# create all the facts used throughout the role, but shouldn't be touched
# by the user
- name: Set installation facts
ansible.builtin.set_fact:
app_images: [] # app_images to install
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
brew_taps: [] # homebrew taps
flatpak_remotes: # flatpak remotes, includes flathub by default
- 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
block:
- name: Set macOS facts
when: ansible_os_family == 'Darwin'
ansible.builtin.set_fact:
sys_pkg_become: false
- name: Set Linux facts
when: ansible_system == 'Linux'
ansible.builtin.set_fact:
sys_pkg_become: true
- name: Generate package installation lists
ansible.builtin.include_tasks:
file: addpkg.yml
loop: "{{ packages | unique }}"
loop_control:
loop_var: pkg
- name: Install sys_pkgs list
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: 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'
- flatpaks|length > 0
block:
- name: Add flatpak repos
when:
- flatpak_remotes|length > 0
- flatpaks|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
when:
- flatpaks|length > 0
community.general.flatpak:
state: latest
method: "{{ flatpak_method }}"
name: "{{ flatpak.name }}"
remote: "{{ flatpak.remote | default('flathub') }}"
- name: Ensure /usr/local/bin exists
ansible.builtin.file:
state: directory
path: /usr/local/bin
owner: root
mode: '0755'
become: true
- name: Install src_pkgs
ansible.builtin.include_tasks:
file: "src/{{ src_pkg }}.yml"
loop: "{{ src_pkgs | unique }}"
loop_control:
loop_var: src_pkg
when: src_pkgs|length > 0
- name: Install cargo packages at specific version
when:
- cargo_pkgs|length > 0
become: "{{ not use_local }}"
loop: "{{ cargo_pkgs | unique }}"
loop_control:
loop_var: cargo_pkg
community.general.cargo:
name: "{{ cargo_pkg.cargo.pkg }}"
version: "{{ cargo_pkg.ver }}"
path: "{{ paths.cargo }}"
locked: "{{ cargo_pkg.cargo.locked }}"
- name: Install local go packages
when:
- go_pkgs|length > 0
loop: "{{ go_pkgs | unique }}"
loop_control:
loop_var: go_pkg
environment:
GOROOT: "{{ paths.install }}/go"
PATH: "{{ paths.install }}/go/bin:$PATH"
ansible.builtin.command:
cmd: "go install {{ go_pkg }}"
# TODO: figure out how to check if the go_pkg is already installed
- name: Install local npm packages
loop: "{{ npm_pkgs | unique }}"
loop_control:
loop_var: npm_pkg
when: npm_pkgs|length > 0
community.general.npm:
global: true
name: "{{ npm_pkg }}"
state: latest
- name: Install python pipx packages for user
loop: "{{ pipx_pkgs | unique }}"
loop_control:
loop_var: pipx_pkg
when: pipx_pkgs|length > 0
community.general.pipx:
executable: "{{ pipx_exec }}"
name: "{{ pipx_pkg }}"
state: latest