Skip to content
This repository has been archived by the owner on Feb 28, 2023. It is now read-only.

Commit

Permalink
Make RedHat kernel list more generic
Browse files Browse the repository at this point in the history
  • Loading branch information
JGoutin committed Aug 16, 2021
1 parent a95b10e commit b50572e
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 142 deletions.
2 changes: 0 additions & 2 deletions .ansible-lint
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
---
skip_list:
# Required to list with extra arguments
- '303'
- role-name
46 changes: 46 additions & 0 deletions tasks/debian.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---

- name: Ensure APT cache is up to date
apt:
update_cache: true
changed_when: false
retries: 10
delay: 1
register: _apt_update
until: _apt_update is successful

- name: Get available kernel versions
command: apt-cache showpkg linux-headers-*
changed_when: false
register: apt_kernel_list

- name: Get installed packages
command: dpkg -l
changed_when: false
register: apt_packages_list

- name: Set target kernel version
set_fact: _kernel="{{ apt_kernel_list |
deb_kernel(kernel_version, ansible_kernel,
kernel_variant | default(omit)) }}"

- name: "Ensure kernel {{ _kernel }} packages are installed"
apt:
name: "{{ item.name | deb_kernel_package(_kernel, ansible_architecture) }}"
retries: 10
delay: 1
register: _apt_install
until: _apt_install is successful
when: item.when
with_items:
- name: linux-image
when: true
- name: linux-headers
when: install_kernel_headers | bool

- name: Ensure any other kernel packages are removed
apt:
name: "{{ apt_packages_list | deb_installed_kernel(_kernel, ansible_architecture) }}"
state: absent
purge: true
tags: molecule-idempotence-notest
141 changes: 1 addition & 140 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,145 +1,6 @@
---

- name: Ensure CentOS Vault repositories list is up to date
package:
name: centos-release
state: latest # noqa 403
retries: 10
delay: 1
register: _centos_release
until: _centos_release is successful
when: ansible_distribution == 'CentOS'

- name: Get available kernel versions with YUM
command: yum list --enablerepo=C7.* --showduplicates kernel
changed_when: false
args:
warn: false
retries: 10
delay: 1
until: yum_kernel_list is successful
when:
- ansible_os_family == 'RedHat'
- ansible_distribution_major_version == "7"
register: yum_kernel_list

- name: Set target YUM kernel version
set_fact: _kernel="{{ yum_kernel_list |
rhel_kernel(kernel_version, ansible_kernel) }}"
when: yum_kernel_list is not skipped

- name: "Ensure kernel {{ _kernel }} packages are installed with YUM"
yum:
name: "{{ item.name }}-{{ _kernel }}"
enablerepo: "{{ yum_kernel_list | rhel_repo(kernel_version, ansible_kernel) }}"
allow_downgrade: true
retries: 10
delay: 1
register: _yum_install
until: _yum_install is successful
when:
- ansible_os_family == 'RedHat'
- ansible_distribution_major_version == "7"
- item.when
with_items:
- name: kernel
when: true
- name: kernel-devel
when: install_kernel_headers | bool
- name: kernel-headers
when: install_kernel_headers | bool

- name: Get available kernel versions with DNF
command: dnf list --enablerepo=* --disablerepo=media-* --showduplicates kernel
changed_when: false
args:
warn: false
retries: 10
delay: 1
until: dnf_kernel_list is successful
when:
- ansible_os_family == 'RedHat'
- ansible_distribution_major_version != "7"
register: dnf_kernel_list

- name: Set target DNF kernel version
set_fact: _kernel="{{ dnf_kernel_list |
rhel_kernel(kernel_version, ansible_kernel) }}"
when: dnf_kernel_list is not skipped

- name: "Ensure kernel {{ _kernel }} packages are installed with DNF"
dnf:
name: "{{ item.name }}-{{ _kernel }}"
enablerepo: "{{ dnf_kernel_list | rhel_repo(kernel_version, ansible_kernel) }}"
allow_downgrade: true
retries: 10
delay: 1
register: _dnf_install
until: _dnf_install is successful
when:
- ansible_os_family == 'RedHat'
- ansible_distribution_major_version != "7"
- item.when
with_items:
- name: kernel
when: true
- name: kernel-devel
when: install_kernel_headers | bool
- name: kernel-headers
when: install_kernel_headers | bool

- name: Ensure APT cache is up to date
apt:
update_cache: true
changed_when: false
retries: 10
delay: 1
register: _apt_update
until: _apt_update is successful
when: ansible_os_family == 'Debian'

- name: Get available kernel versions with APT
command: apt-cache showpkg linux-headers-*
changed_when: false
register: apt_kernel_list
when: ansible_os_family == 'Debian'

- name: Get installed packages with APT
command: dpkg -l
changed_when: false
register: apt_packages_list
when: ansible_os_family == 'Debian'

- name: Set target APT kernel version
set_fact: _kernel="{{ apt_kernel_list |
deb_kernel(kernel_version, ansible_kernel,
kernel_variant | default(omit)) }}"
when: apt_kernel_list is not skipped

- name: "Ensure kernel {{ _kernel }} packages are installed with APT"
apt:
name: "{{ item.name | deb_kernel_package(_kernel, ansible_architecture) }}"
retries: 10
delay: 1
register: _apt_install
until: _apt_install is successful
when:
- ansible_os_family == 'Debian'
- item.when
with_items:
- name: linux-image
when: true
- name: linux-headers
when: install_kernel_headers | bool

- name: Ensure any other kernel packages are removed with APT
apt:
name: "{{ apt_packages_list |
deb_installed_kernel(_kernel, ansible_architecture) }}"
state: absent
purge: true
when: ansible_os_family == 'Debian'
tags: molecule-idempotence-notest
- include_tasks: "{{ ansible_os_family | lower() }}.yml"

- name: Get /var/run/reboot-required stat
# Note: Should exist on Debian based OS if reboot is required
Expand Down
42 changes: 42 additions & 0 deletions tasks/redhat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---

- name: Ensure CentOS Vault repositories are up to date
package:
name: centos-release
state: latest # noqa package-latest
retries: 10
delay: 1
register: _centos_release
until: _centos_release is successful
when: ansible_distribution == 'CentOS'

- name: Get available kernel versions
command: "{{ ansible_pkg_mgr }} list --enablerepo=* --disablerepo=media-*,*-media --showduplicates kernel"
changed_when: false
args:
warn: false
retries: 10
delay: 1
until: rhel_kernel_list is successful
register: rhel_kernel_list

- name: Set target kernel version
set_fact: _kernel="{{ rhel_kernel_list | rhel_kernel(kernel_version, ansible_kernel) }}"

- name: "Ensure kernel {{ _kernel }} packages are installed"
package:
name: "{{ item.name }}-{{ _kernel }}"
enablerepo: "{{ rhel_kernel_list | rhel_repo(kernel_version, ansible_kernel) }}"
allow_downgrade: true
retries: 10
delay: 1
register: _rhel_install
until: _rhel_install is successful
when: item.when
with_items:
- name: kernel
when: true
- name: kernel-devel
when: install_kernel_headers | bool
- name: kernel-headers
when: install_kernel_headers | bool

0 comments on commit b50572e

Please sign in to comment.