refactor: split up package installation tasks in accord with splittng of post-installation handlers, for use by separate playbooks

This commit is contained in:
2026-06-10 13:46:18 -04:00
parent af9fc3b4ca
commit 4074eacb1f
3 changed files with 339 additions and 117 deletions

View File

@@ -0,0 +1,163 @@
#SPDX-License-Identifier: MIT-0
---
# tasks file for roles/init-vps
- name: Acquiring home of current user
when: ansible_facts["system"] == "Linux"
ansible.builtin.shell:
cmd: "echo ~{{ ansible_user }}"
register: ansible_user_home
- name: Acquiring current user
when: ansible_facts["system"] == "Linux"
ansible.builtin.shell:
cmd: "echo {{ ansible_user }}"
register: current_user
- name: Creating prerequisite directory tree for installation scripts
become: true
become_user: "{{ current_user.stdout }}"
ansible.builtin.file:
path: "{{ ansible_user_home.stdout }}/.local/bin"
recurse: true
owner: "{{ ansible_user }}"
group: "{{ ansible_user }}"
state: directory
- name: Creating prerequisite directory tree for unarchived archives
become: true
become_user: "{{ current_user.stdout }}"
ansible.builtin.file:
path: "{{ ansible_user_home.stdout }}/downloads/archives/released"
recurse: true
owner: "{{ ansible_user }}"
group: "{{ ansible_user }}"
state: directory
- name: Creating prerequisite directory tree for package installation executables
become: true
become_user: "{{ current_user.stdout }}"
ansible.builtin.file:
path: "{{ ansible_user_home.stdout }}/.local_pkgs"
recurse: true
owner: "{{ ansible_user }}"
group: "{{ ansible_user }}"
state: directory
- name: Installing Linux software
when: ansible_facts["system"] == "Linux"
block:
- name: Installing software using Debian package manager
when: ansible_facts["os_family"] == "Debian"
become: true
block:
- name: Updating package cache
ansible.builtin.apt:
update_cache: true
- name: Registering a package source
when: item.sources != None
ansible.builtin.deb822_repository:
name: "{{ item.name }}"
uris: "{{ item.sources }}"
types: "{{ item.types | default('deb') }}"
suites: "{{ item.suites | default('*') }}"
components: "{{ item.comps | default('*') }}"
signed_by: "{{ item.sigkey }}"
state: present
loop: "{{ ((pkgs.mngr.core | default([]))) }}"
- name: Installing a local package in managed node
when: item.uri != None
ansible.builtin.apt:
deb: "{{ item.uri }}"
state: present
# @TODO add a default value for notify
# notify: "{{ item.name }}"
loop: "{{ (pkgs.mngr.core | default([])) | selectattr('uri', 'search', '\\.deb$') }}"
- name: Updating package cache
ansible.builtin.apt:
update_cache: true
- name: Installing a package
when: item.name != None and item.uri == None
ansible.builtin.package:
name: "{{ item.name }}"
state: latest
# @TODO add a default value for notify
# notify: "{{ item.name }}"
loop: "{{ ((pkgs.mngr.core | default([]))) | rejectattr('uri', 'search', '\\.deb$') }}"
tags:
- get_mngr_pkgs
- name: Installing software by executing installation shell scripts
block:
- name: Acquiring installation shell script
become: true
become_user: "{{ current_user.stdout }}"
when: item.src != None and (((pkgs.script.core | default([]))) | length) > 0
ansible.builtin.uri:
url: "{{ item.src }}"
dest: "{{ ansible_user_home.stdout }}/.local/bin/{{ item.name }}-install.sh"
follow_redirects: safe
owner: "{{ ansible_user }}"
group: "{{ ansible_user }}"
force: true
mode: "744"
# @TODO add a default value for notify
notify: "{{ ((pkgs.script.core | default([])))[idx].name }}"
loop: "{{ (pkgs.script.core | default([])) }}"
loop_control:
index_var: idx
register: install_scripts
tags:
- get_script_pkgs
- name: Installing software by building it from source archives
block:
- name: Acquiring software source archive
become: true
become_user: "{{ current_user.stdout }}"
when: item.src != None
ansible.builtin.get_url:
url: "{{ item.src }}"
dest: "{{ ansible_user_home.stdout }}/downloads/archives/"
owner: "{{ ansible_user }}"
group: "{{ ansible_user }}"
force: true
backup: true
mode: "644"
loop: "{{ (pkgs.archive.core | default([])) }}"
register: archived_builds
- name: Create subdirectories for unarchiving
become: true
become_user: "{{ current_user.stdout }}"
ansible.builtin.file:
path: "{{ ansible_user_home.stdout }}/downloads/archives/released/{{ ((pkgs.archive.core | default([])))[idx].name }}"
owner: "{{ ansible_user }}"
group: "{{ ansible_user }}"
mode: "755"
state: directory
loop: "{{ archived_builds.results }}"
loop_control:
index_var: idx
- name: Unarchiving software build archive
when: item.dest != None and (((pkgs.script.core | default([]))) | length) > 0
ansible.builtin.unarchive:
src: "{{ item.dest }}"
remote_src: true
dest: "{{ ansible_user_home.stdout }}/downloads/archives/released/{{ ((pkgs.archive.core | default([])))[idx].name }}/"
# @TODO add a default value for notify
notify: "{{ ((pkgs.archive.core | default([])))[idx].name }}"
loop: "{{ archived_builds.results }}"
loop_control:
index_var: idx
tags:
- get_archive_pkgs
- name: Installing software from source git repositories
block:
- name: Clone git bare repository
become: true
become_user: "{{ current_user.stdout }}"
when: item.src != None
ansible.builtin.git:
repo: "{{ item.src }}"
dest: "{{ ansible_user_home.stdout }}/repos/.foreign/{{ item.name }}"
version: "{{ item.branch }}"
clone: true
single_branch: true
# @TODO add a default value for notify
notify: "{{ item.name }}"
loop: "{{ (pkgs.git_repos.core | default([])) }}"
register: installation_repos
tags:
- get_git_pkgs

View File

@@ -1,117 +0,0 @@
#SPDX-License-Identifier: MIT-0
---
# tasks file for roles/init-vps
- name: Creating prerequisite directory tree for installation scripts
ansible.builtin.file:
path: "{{ ansible_facts['user_dir'] }}/.local/bin"
recurse: true
state: directory
- name: Creating prerequisite directory tree for unarchived archives
ansible.builtin.file:
path: "{{ ansible_facts['user_dir'] }}/downloads/archives/released"
recurse: true
state: directory
- name: Creating prerequisite directory tree for package installation executables
ansible.builtin.file:
path: "{{ ansible_facts['user_dir'] }}/.local_pkgs"
recurse: true
state: directory
- name: Installing Linux software
when: ansible_facts["system"] == "Linux"
block:
- name: Installing software using Debian package manager
when: ansible_facts["os_family"] == "Debian"
become: true
block:
- name: Registering a package source
when: item.sources != None
ansible.builtin.deb822_repository:
name: "{{ item.name }}"
uris: "{{ item.sources }}"
types: "{{ item.types | default('deb') }}"
suites: "{{ item.suites | default('*') }}"
components: "{{ item.comps | default('*') }}"
signed_by: "{{ item.sigkey }}"
state: present
loop: "{{ ((pkgs.mngr.core | default([])) + (pkgs.mngr.userspace | default([]))) }}"
- name: Installing a local package in managed node
when: item.uri != None
ansible.builtin.apt:
deb: "{{ item.uri }}"
update_cache: true
state: present
notify: "{{ item.name }}"
loop: "{{ ((pkgs.mngr.core | default([])) + (pkgs.mngr.userspace | default([]))) | selectattr('uri', 'search', '\\.deb$') }}"
- name: Installing a package
when: item.name != None and item.uri == None
ansible.builtin.package:
name: "{{ item.name }}"
update_cache: true
state: latest
# notify: "{{ item.name }}" # @TODO create corresponding roles/init-vps handlers
loop: "{{ ((pkgs.mngr.core | default([])) + (pkgs.mngr.userspace | default([]))) | rejectattr('uri', 'search', '\\.deb$') }}"
tags:
- get_mngr_pkgs
- name: Installing software by executing installation shell scripts
block:
- name: Acquiring installation shell script
when: item.src != None
ansible.builtin.get_url:
url: "{{ item.src }}"
dest: "{{ ansible_facts['user_dir'] }}/.local/bin/{{ item.name }}-install.sh"
force: true
backup: true
mode: "744"
loop: "{{ (pkgs.script.core | default([])) + (pkgs.script.userspace | default([])) }}"
register: install_scripts
- name: Executing a shell-scripted installation process
when: item.src != None and (((pkgs.script.core | default([])) + (pkgs.script.userspace | default([]))) | length) > 0
become: true
ansible.builtin.shell:
cmd: "{{ item.dest }}"
notify: "{{ ((pkgs.script.core | default([])) + (pkgs.script.userspace | default([])))[idx].name }}"
loop: "{{ install_scripts.results }}"
loop_control:
index_var: idx
tags:
- get_script_pkgs
# @TODO complete below block task
- name: Installing software by building it from source archives
block:
- name: Acquiring software source archive
when: item.src != None
ansible.builtin.get_url:
url: "{{ item.src }}"
dest: "{{ ansible_facts['user_dir'] }}/downloads/archives/"
force: true
backup: true
mode: "644"
loop: "{{ (pkgs.archive.core | default([])) + (pkgs.archive.userspace | default([])) }}"
register: archived_builds
- name: Unarchiving software build archive
when: item.dest != None and (((pkgs.script.core | default([])) + (pkgs.script.userspace | default([]))) | length) > 0
ansible.builtin.unarchive:
src: "{{ item.dest }}"
remote_src: true
dest: "{{ ansible_facts['user_dir'] }}/downloads/archives/released/{{ ((pkgs.archive.core | default([])) + (pkgs.archive.userspace | default([])))[idx].name }}/"
notify: "{{ ((pkgs.archive.core | default([])) + (pkgs.archive.userspace | default([])))[idx].name }}"
loop: "{{ archived_builds.results }}"
loop_control:
index_var: idx
tags:
- get_archive_pkgs
- name: Installing software from source git repositories
block:
- name: Clone git bare repository
when: item.src != None
ansible.builtin.git:
repo: "{{ item.src }}"
dest: "{{ ansible_facts['user_dir'] }}/repos/.foreign/{{ item.name }}"
version: "{{ item.branch }}"
clone: true
single_branch: true
notify: "{{ item.name }}"
loop: "{{ (pkgs.git_repos.core | default([])) + (pkgs.git_repos.userspace | default([])) }}"
register: installation_repos
tags:
- get_git_pkgs

View File

@@ -0,0 +1,176 @@
#SPDX-License-Identifier: MIT-0
---
# tasks file for roles/init-vps
- name: Acquiring home of current user
when: ansible_facts["system"] == "Linux"
ansible.builtin.shell:
cmd: "echo ~{{ ansible_user }}"
register: ansible_user_home
- name: Acquiring current user
when: ansible_facts["system"] == "Linux"
ansible.builtin.shell:
cmd: "echo {{ ansible_user }}"
register: current_user
- name: Creating prerequisite directory tree for installation scripts
ansible.builtin.file:
path: "{{ ansible_user_home.stdout }}/.local/bin"
recurse: true
owner: "{{ ansible_user }}"
group: "{{ ansible_user }}"
state: directory
- name: Creating prerequisite directory tree for unarchived archives
ansible.builtin.file:
path: "{{ ansible_user_home.stdout }}/downloads/archives/released"
recurse: true
owner: "{{ ansible_user }}"
group: "{{ ansible_user }}"
state: directory
- name: Creating prerequisite directory tree for package installation executables
ansible.builtin.file:
path: "{{ ansible_user_home.stdout }}/.local_pkgs"
recurse: true
owner: "{{ ansible_user }}"
group: "{{ ansible_user }}"
state: directory
- name: Creating prerequisite directory tree for git repos
ansible.builtin.file:
path: "{{ ansible_user_home.stdout }}/repos/.foreign"
recurse: true
owner: "{{ ansible_user }}"
group: "{{ ansible_user }}"
state: directory
- name: Installing Linux software
when: ansible_facts["system"] == "Linux"
block:
- name: Installing software using Debian package manager
when: ansible_facts["os_family"] == "Debian"
become: true
block:
- name: Updating package cache
ansible.builtin.apt:
update_cache: true
- name: Registering a package source
when: item.sources != None
ansible.builtin.deb822_repository:
name: "{{ item.name }}"
uris: "{{ item.sources }}"
types: "{{ item.types | default('deb') }}"
suites: "{{ item.suites | default('*') }}"
components: "{{ item.comps | default('*') }}"
signed_by: "{{ item.sigkey }}"
state: present
loop: "{{ (pkgs.mngr.userspace | default([])) }}"
- name: Installing a local package in managed node
when: item.uri != None
ansible.builtin.apt:
deb: "{{ item.uri }}"
state: present
# @TODO add a default value for notify
# notify: "{{ item.name }}"
loop: "{{ (pkgs.mngr.userspace | default([])) | selectattr('uri', 'search', '\\.deb$') }}"
- name: Updating package cache
ansible.builtin.apt:
update_cache: true
- name: Installing a package
when: item.name != None and item.uri == None
ansible.builtin.package:
name: "{{ item.name }}"
state: latest
# @TODO add a default value for notify
# notify: "{{ item.name }}" # @TODO create corresponding roles/init-vps handlers
loop: "{{ (pkgs.mngr.userspace | default([])) | rejectattr('uri', 'search', '\\.deb$') }}"
tags:
- get_mngr_pkgs
- name: Installing software by executing installation shell scripts
become: true
become_user: "{{ current_user.stdout }}"
block:
- name: Acquiring installation shell script
when: item.src != None and ((pkgs.script.userspace | default([])) | length) > 0
ansible.builtin.uri:
url: "{{ item.src }}"
dest: "{{ ansible_user_home.stdout }}/.local/bin/{{ item.name }}-install.sh"
follow_redirects: safe
owner: "{{ ansible_user }}"
group: "{{ ansible_user }}"
force: true
mode: "744"
# @TODO add a default value for notify
notify: "{{ (pkgs.script.userspace | default([]))[idx].name }}"
loop: "{{ (pkgs.script.userspace | default([])) }}"
loop_control:
index_var: idx
register: install_scripts
tags:
- get_script_pkgs
- name: Installing software by building it from source archives
block:
- name: Acquiring software source archive
become: true
become_user: "{{ current_user.stdout }}"
when: item.src != None
ansible.builtin.get_url:
url: "{{ item.src }}"
dest: "{{ ansible_user_home.stdout }}/downloads/archives/"
owner: "{{ ansible_user }}"
group: "{{ ansible_user }}"
force: true
backup: true
mode: "644"
loop: "{{ (pkgs.archive.userspace | default([])) }}"
register: archived_builds
- name: Create subdirectories for unarchiving
ansible.builtin.file:
path: "{{ ansible_user_home.stdout }}/downloads/archives/released/{{ (pkgs.archive.userspace | default([]))[idx].name }}"
owner: "{{ ansible_user }}"
group: "{{ ansible_user }}"
mode: "755"
state: directory
loop: "{{ archived_builds.results }}"
loop_control:
index_var: idx
- name: Unarchiving software build archive
become: true
become_user: "{{ current_user.stdout }}"
when: item.dest != None and ((pkgs.script.userspace | default([])) | length) > 0
ansible.builtin.unarchive:
src: "{{ item.dest }}"
remote_src: true
dest: "{{ ansible_user_home.stdout }}/downloads/archives/released/{{ (pkgs.archive.userspace | default([]))[idx].name }}/"
owner: "{{ ansible_user }}"
group: "{{ ansible_user }}"
# @TODO add a default value for notify
notify: "{{ (pkgs.archive.userspace | default([]))[idx].name }}"
loop: "{{ archived_builds.results }}"
loop_control:
index_var: idx
tags:
- get_archive_pkgs
- name: Installing software from source git repositories
block:
- name: Clone git bare repository
when: item.src != None
become: true
become_user: "{{ current_user.stdout }}"
ansible.builtin.git:
repo: "{{ item.src }}"
dest: "{{ ansible_user_home.stdout }}/repos/.foreign/{{ item.name }}"
version: "{{ item.branch }}"
clone: true
single_branch: true
loop: "{{ (pkgs.git_repos.userspace | default([])) }}"
register: installation_repos
# - name: Changing ownership of specific repo subdirectory
# become: true
# become_user: "{{ current_user.stdout }}"
# ansible.builtin.file:
# path: "{{ ansible_user_home.stdout }}/repos/.foreign/{{ item.name }}"
# recurse: true
# owner: "{{ ansible_user }}"
# group: "{{ ansible_user }}"
# notify: "{{ item.name }}"
# loop: "{{ (pkgs.git_repos.userspace | default([])) }}"
tags:
- get_git_pkgs
# @TODO add a reboot either here or in any of the handlers potentially notified from here in
# order to update environment (unless found better solution)