From bd2db7d3878f9ec9a61e6918cc50f7c235218f75 Mon Sep 17 00:00:00 2001 From: Ygal Blum Date: Thu, 14 Dec 2023 18:06:19 +0200 Subject: [PATCH] Initramfs prefix all internal variables with role name (#43) Signed-off-by: Ygal Blum --- .../initramfs-internal-variable-names.yml | 2 ++ roles/initramfs/tasks/main.yml | 14 +++++++------- roles/initramfs/tasks/preflight.yml | 12 ++++++------ 3 files changed, 15 insertions(+), 13 deletions(-) create mode 100644 changelogs/fragments/initramfs-internal-variable-names.yml diff --git a/changelogs/fragments/initramfs-internal-variable-names.yml b/changelogs/fragments/initramfs-internal-variable-names.yml new file mode 100644 index 0000000..9e63b18 --- /dev/null +++ b/changelogs/fragments/initramfs-internal-variable-names.yml @@ -0,0 +1,2 @@ +minor_changes: +- initramfs - Rename internal variables with role name prefix diff --git a/roles/initramfs/tasks/main.yml b/roles/initramfs/tasks/main.yml index b901b5d..b043d03 100644 --- a/roles/initramfs/tasks/main.yml +++ b/roles/initramfs/tasks/main.yml @@ -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 @@ -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 diff --git a/roles/initramfs/tasks/preflight.yml b/roles/initramfs/tasks/preflight.yml index ced1fa1..079f9a6 100644 --- a/roles/initramfs/tasks/preflight.yml +++ b/roles/initramfs/tasks/preflight.yml @@ -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"