Skip to content

Commit

Permalink
Initramfs prefix all internal variables with role name (#43)
Browse files Browse the repository at this point in the history
Signed-off-by: Ygal Blum <[email protected]>
  • Loading branch information
ygalblum authored Dec 14, 2023
1 parent 5a4319d commit bd2db7d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/initramfs-internal-variable-names.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- initramfs - Rename internal variables with role name prefix
14 changes: 7 additions & 7 deletions roles/initramfs/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@

- name: Get kernel version
ansible.builtin.set_fact:
_kernel_version: "{{ ansible_facts.kernel }}"
initramfs_kernel_version: "{{ ansible_facts.kernel }}"

- name: Create a backup of the current initramfs
ansible.builtin.copy:
remote_src: true
src: /boot/initramfs-{{ _kernel_version }}.img
dest: /boot/initramfs-{{ _kernel_version }}.img.{{ initramfs_backup_extension }}
src: /boot/initramfs-{{ initramfs_kernel_version }}.img
dest: /boot/initramfs-{{ initramfs_kernel_version }}.img.{{ initramfs_backup_extension }}
mode: "0600"

- name: Create a new initramfs with the optional additional modules
# yamllint disable-line rule:line-length
ansible.builtin.command: '/usr/bin/dracut {{ ((initramfs_add_modules | length) > 0) | ternary("-a", "") }} "{{ initramfs_add_modules }}" --kver {{ _kernel_version }} --force'
ansible.builtin.command: '/usr/bin/dracut {{ ((initramfs_add_modules | length) > 0) | ternary("-a", "") }} "{{ initramfs_add_modules }}" --kver {{ initramfs_kernel_version }} --force'
changed_when: true

- name: Reboot the server
Expand All @@ -30,11 +30,11 @@
- name: Restore previous initramfs
ansible.builtin.copy:
remote_src: true
src: /boot/initramfs-{{ _kernel_version }}.img.{{ initramfs_backup_extension }}
dest: /boot/initramfs-{{ _kernel_version }}.img
src: /boot/initramfs-{{ initramfs_kernel_version }}.img.{{ initramfs_backup_extension }}
dest: /boot/initramfs-{{ initramfs_kernel_version }}.img
mode: "0600"

- name: Remove initramfs backup file
ansible.builtin.file:
path: /boot/initramfs-{{ _kernel_version }}.img.{{ initramfs_backup_extension }}
path: /boot/initramfs-{{ initramfs_kernel_version }}.img.{{ initramfs_backup_extension }}
state: absent
12 changes: 6 additions & 6 deletions roles/initramfs/tasks/preflight.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@

- name: Get kernel version
ansible.builtin.set_fact:
_kernel_version: "{{ ansible_facts.kernel }}"
initramfs_kernel_version: "{{ ansible_facts.kernel }}"

- name: Get default kernel
ansible.builtin.command:
cmd: /sbin/grubby --default-kernel
register: _grubby_rc
register: initramfs_grubby_rc
changed_when: false

- name: Parse default kernel version
ansible.builtin.set_fact:
_default_kernel: "{{ ((((_grubby_rc.stdout_lines[0] | split('/'))[2] | split('-'))[1:]) | join('-')) | trim }}"
initramfs_default_kernel: "{{ ((((initramfs_grubby_rc.stdout_lines[0] | split('/'))[2] | split('-'))[1:]) | join('-')) | trim }}"

- name: Check the values
ansible.builtin.assert:
that: _default_kernel == _kernel_version
fail_msg: "Current kernel version '{{ _kernel_version }}' is not the default version '{{ _default_kernel }}'"
success_msg: "Current kernel version {{ _kernel_version }} and default version {{ _default_kernel }} match"
that: initramfs_default_kernel == initramfs_kernel_version
fail_msg: "Current kernel version '{{ initramfs_kernel_version }}' is not the default version '{{ initramfs_default_kernel }}'"
success_msg: "Current kernel version {{ initramfs_kernel_version }} and default version {{ initramfs_default_kernel }} match"

0 comments on commit bd2db7d

Please sign in to comment.