Skip to content

Commit

Permalink
Initramfs prefix all internal variables with role name
Browse files Browse the repository at this point in the history
Signed-off-by: Ygal Blum <[email protected]>
  • Loading branch information
ygalblum committed Dec 14, 2023
1 parent ddb7367 commit 7672718
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 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
10 changes: 5 additions & 5 deletions roles/initramfs/tasks/preflight.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

- 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:
Expand All @@ -18,10 +18,10 @@

- 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: "{{ ((((_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 7672718

Please sign in to comment.