restructure repo

This commit is contained in:
DerLinkman
2024-11-22 20:25:38 +01:00
parent 5a0f229511
commit 344c9508ea
17 changed files with 184 additions and 43 deletions

View File

@@ -0,0 +1,9 @@
# Standardwerte, die überschrieben werden können
os_update_auto_upgrade: true
os_also_update_mirror: false
os_update_mirrors:
# Role needs two mirros to use for the sources.list.j2 Template
- "http://mirror.tinc.gmbh/debian" # Enter a main mirror here (not security)
- "http://mirror.tinc.gmbh/debian-security" # Enter a security mirror here
os_update_major_version: false # Can either be true or false | To toggle if systems need to be upgraded to newer codename
os_update_version_codename: "{{ ansible_distribution_release }}" # KEEP UNTOUCHED!! | Used for jinja2 Template fill in as it determines the current codename of system where ansible is run on

View File

@@ -0,0 +1,11 @@
- name: apt cleanup
apt:
clean: yes
autoclean: yes
- name: Reboot system
command: /sbin/reboot
async: 1
poll: 0
ignore_errors: true
when: reboot_required.stdout == "yes"

View File

@@ -0,0 +1,12 @@
- name: Update mirrors if necessary
when: os_also_update_mirror |bool
include_tasks: update_mirrors.yml
ignore_errors: true
- name: Upgrade to new major version if enabled
when: os_update_major_version
include_tasks: update_major_version.yml
ignore_errors: true
- name: Upgrade all packages
include_tasks: upgrade_packages.yml

View File

@@ -0,0 +1,34 @@
- name: Backup existing sources in /etc/apt
copy:
src: "{{ item }}"
dest: "{{ item }}.bak"
remote_src: yes
loop: "{{ lookup('ansible.builtin.fileglob', '/etc/apt/sources.list.d/*.list') + ['/etc/apt/sources.list'] }}"
when: item | file
- name: Update sources.list for new major version
template:
src: sources.list.j2
dest: /etc/apt/sources.list
vars:
os_update_version_codename: "{{ new_version_codename }}" # Variable gets passed by main.yml task
- name: Update additional repositories in /etc/apt/sources.list.d
lineinfile:
path: "{{ item }}"
regexp: '^(deb .* )({{ os_update_version_codename }})'
line: '\1{{ new_version_codename }}'
loop: "{{ lookup('ansible.builtin.fileglob', '/etc/apt/sources.list.d/*.list') }}"
when: item | file
- name: Update apt cache
apt:
update_cache: yes
- name: Perform distribution upgrade
apt:
upgrade: yes
allow_unauthenticated: yes
notify:
- Reboot system
- apt cleanup

View File

@@ -0,0 +1,16 @@
- name: Backup existing sources.list
copy:
src: /etc/apt/sources.list
dest: /etc/apt/sources.list.bak
remote_src: yes
force: yes
- name: Update sources.list with new mirrors
template:
src: sources.list.j2
dest: /etc/apt/sources.list
- name: Update apt cache
apt:
update_cache: yes

View File

@@ -0,0 +1,23 @@
- name: Upgrade all installed packages
apt:
upgrade: full
update_cache: yes
notify:
- apt cleanup
- name: Check if a kernel update is available
shell: |
dpkg -l | grep -E 'linux-image-[0-9]' | awk '{print $2}' | sort | tail -n 1
register: latest_kernel
- name: Check if running kernel matches the latest installed kernel
shell: uname -r | grep -c "{{ latest_kernel.stdout }}"
register: kernel_match
changed_when: false
- name: Mark reboot required if a new kernel is installed
set_fact:
reboot_required: "yes"
notify:
- Reboot system
when: kernel_match.stdout == "0"