generated from nicolabelluti/template-ansible
Added kernel role
This commit is contained in:
@@ -4,3 +4,4 @@ bc250:
|
|||||||
vars:
|
vars:
|
||||||
ansible_user: deck
|
ansible_user: deck
|
||||||
ansible_ssh_pass: deck
|
ansible_ssh_pass: deck
|
||||||
|
ansible_become_password: "{{ ansible_ssh_pass }}"
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
- name: Test Playbook
|
- name: Test Playbook
|
||||||
hosts: bc250
|
hosts: bc250
|
||||||
roles:
|
roles:
|
||||||
- name: Test Role
|
- name: Install kernel
|
||||||
role: test_role
|
role: kernel
|
||||||
vars:
|
|
||||||
test_role__lorem_ipsum_string: Lorem Ipsum is simply dummy text
|
|
||||||
|
|||||||
@@ -0,0 +1,84 @@
|
|||||||
|
- name: Add the bc250-cachyos pacman repository
|
||||||
|
become: true
|
||||||
|
ansible.builtin.blockinfile:
|
||||||
|
path: /etc/pacman.conf
|
||||||
|
marker: "# {mark} - Ansible managed"
|
||||||
|
prepend_newline: true
|
||||||
|
block: |
|
||||||
|
[bc250-cachyos]
|
||||||
|
SigLevel = Optional TrustAll
|
||||||
|
Server = https://github.com/MastaG/linux-cachyos-bc250/releases/download/repo
|
||||||
|
register: pacman_repo
|
||||||
|
|
||||||
|
# Full upgrade first: installing from a freshly added repo without -Syu
|
||||||
|
# would be a partial upgrade.
|
||||||
|
- name: Perform a full system upgrade
|
||||||
|
become: true
|
||||||
|
community.general.pacman:
|
||||||
|
update_cache: "{{ pacman_repo.changed }}"
|
||||||
|
upgrade: true
|
||||||
|
register: sys_upgrade
|
||||||
|
|
||||||
|
- name: Give the BC-250 kernel priority in BOOT_ORDER
|
||||||
|
become: true
|
||||||
|
ansible.builtin.lineinfile:
|
||||||
|
path: /etc/default/limine
|
||||||
|
regexp: '^BOOT_ORDER='
|
||||||
|
line: 'BOOT_ORDER="*bc250, *lts, *, *fallback, Snapshots"'
|
||||||
|
register: boot_order
|
||||||
|
|
||||||
|
- name: Install the BC-250 kernel and the fallback
|
||||||
|
become: true
|
||||||
|
community.general.pacman:
|
||||||
|
name:
|
||||||
|
- linux-cachyos-bc250
|
||||||
|
- linux-cachyos-bc250-headers
|
||||||
|
- linux-cachyos
|
||||||
|
- linux-cachyos-headers
|
||||||
|
state: present
|
||||||
|
register: kernel_pkg
|
||||||
|
|
||||||
|
- name: Regenerate Limine entries when only BOOT_ORDER changed
|
||||||
|
become: true
|
||||||
|
ansible.builtin.command: limine-mkinitcpio
|
||||||
|
when: boot_order.changed and not kernel_pkg.changed
|
||||||
|
changed_when: true
|
||||||
|
|
||||||
|
- name: Preselect the BC-250 kernel for the next boot
|
||||||
|
become: true
|
||||||
|
ansible.builtin.shell:
|
||||||
|
executable: /bin/bash
|
||||||
|
cmd: |
|
||||||
|
set -eu
|
||||||
|
EFIVAR=$(ls /sys/firmware/efi/efivars/LimineLastBootedEntry-*)
|
||||||
|
[ "$(tail -c +5 "$EFIVAR" | tr -d '\0')" = 'CachyOS/linux-cachyos-bc250' ] && exit 90
|
||||||
|
chattr -i "$EFIVAR"
|
||||||
|
printf '\x07\x00\x00\x00CachyOS/linux-cachyos-bc250\x00' > "$EFIVAR"
|
||||||
|
register: efivar_write
|
||||||
|
changed_when: efivar_write.rc == 0
|
||||||
|
failed_when: efivar_write.rc not in [0, 90]
|
||||||
|
|
||||||
|
- name: Reboot into the new kernel
|
||||||
|
become: true
|
||||||
|
ansible.builtin.reboot:
|
||||||
|
reboot_timeout: 600
|
||||||
|
when: kernel_pkg.changed or boot_order.changed or sys_upgrade.changed
|
||||||
|
|
||||||
|
- name: Re-gather kernel facts after reboot
|
||||||
|
ansible.builtin.setup:
|
||||||
|
filter: ansible_kernel
|
||||||
|
|
||||||
|
# Guards the removal below: never drop deckify unless we are already
|
||||||
|
# running the BC-250 kernel.
|
||||||
|
- name: Make sure the BC-250 kernel is the running one
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that: "'bc250' in ansible_kernel"
|
||||||
|
fail_msg: "Running {{ ansible_kernel }}"
|
||||||
|
|
||||||
|
- name: Remove the deckify kernel
|
||||||
|
become: true
|
||||||
|
community.general.pacman:
|
||||||
|
name:
|
||||||
|
- linux-cachyos-deckify
|
||||||
|
- linux-cachyos-deckify-headers
|
||||||
|
state: absent
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
# Test Role
|
|
||||||
|
|
||||||
A brief description about the role...
|
|
||||||
|
|
||||||
## Variables
|
|
||||||
|
|
||||||
| Name | Is Required? | Default |
|
|
||||||
|:-------------------------------:|:------------:|:-------------:|
|
|
||||||
| `test_role__hello_world_string` | ✔️ | Hello, World! |
|
|
||||||
| `test_role__lorem_ipsum_string` | ❌ | |
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
test_role__hello_world_string: Hello, World!
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
- name: Ping
|
|
||||||
ansible.builtin.ping:
|
|
||||||
|
|
||||||
- name: Print an "Hello, World!"
|
|
||||||
ansible.builtin.debug:
|
|
||||||
msg: "{{ test_role__hello_world_string }}"
|
|
||||||
|
|
||||||
- name: Test the `ansible_managed` variable
|
|
||||||
ansible.builtin.template:
|
|
||||||
dest: /tmp/ansible.txt
|
|
||||||
src: ansible.txt.j2
|
|
||||||
mode: preserve
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
{{ ansible_managed | comment('plain') }}
|
|
||||||
|
|
||||||
{{ test_role__lorem_ipsum_string }}
|
|
||||||
Reference in New Issue
Block a user