Refactor to be a bit more modular
This commit is contained in:
32
kernel_func
32
kernel_func
@@ -1,13 +1,39 @@
|
|||||||
kernel_func () {
|
kernel_func () {
|
||||||
machine_id=$(cat /etc/machine-id)
|
distro="$(awk -F= '/^ID/ {print $NF}' /etc/os-release)"
|
||||||
|
if [[ "${distro}" == arch ]]
|
||||||
|
then
|
||||||
|
package="$(pacman -Q \
|
||||||
|
| grep -vE -- '-(firmware|api|keyring|linux|docs|headers)' \
|
||||||
|
| grep linux | awk '{print $1}')"
|
||||||
current_kernel=$(uname -r)
|
current_kernel=$(uname -r)
|
||||||
|
next_kernel="$(pacman -Q | grep "${package}" \
|
||||||
|
| awk '{print $NF}' | tail -1 | tr -d '\n')"
|
||||||
current_ucode=$(awk -F'[[:space:]]*:[[:space:]]*' '/microcode/ {print $2}' /proc/cpuinfo | uniq)
|
current_ucode=$(awk -F'[[:space:]]*:[[:space:]]*' '/microcode/ {print $2}' /proc/cpuinfo | uniq)
|
||||||
[[ -f /run/next_kernel ]] && next_kernel="$(sudo cat /run/next_kernel)"
|
if whence iucode_tool &> /dev/null
|
||||||
|
then
|
||||||
next_ucode=$(iucode_tool -lqS /lib/firmware/intel-ucode/ | grep -Po 'rev 0x\d+' | tr -d '[rev ]' | tail -1)
|
next_ucode=$(iucode_tool -lqS /lib/firmware/intel-ucode/ | grep -Po 'rev 0x\d+' | tr -d '[rev ]' | tail -1)
|
||||||
if [[ "${current_kernel}" == ${next_kernel} ]] && [[ "${current_ucode}" == ${next_ucode} ]] || [[ -z "${next_kernel}" ]]
|
fi
|
||||||
|
if [[ "${current_kernel}" =~ ${next_kernel} ]]
|
||||||
|
then
|
||||||
|
if [[ -n "${next_ucode}" ]] && [[ "${current_ucode}" == ${next_ucode} ]]
|
||||||
then
|
then
|
||||||
print -P "[%F{#00ff00}OK%f]"
|
print -P "[%F{#00ff00}OK%f]"
|
||||||
else
|
else
|
||||||
print -P "[%F{yellow}needs reboot%f]"
|
print -P "[%F{yellow}needs reboot%f]"
|
||||||
fi
|
fi
|
||||||
|
else
|
||||||
|
print -P "[%F{yellow}needs reboot%f]"
|
||||||
|
fi
|
||||||
|
elif [[ "${distro}" == debian ]]
|
||||||
|
then
|
||||||
|
current_kernel="$(uname -v | awk '{print $5}')"
|
||||||
|
next_kernel="$(dpkg -l | grep -P '^ii\s+linux-image' | awk '{print $3}' \
|
||||||
|
| sort -Vu | tail -1)"
|
||||||
|
if [[ "${current_kernel}" == ${next_kernel} ]]
|
||||||
|
then
|
||||||
|
print -P "[%F{#00ff00}OK%f]"
|
||||||
|
else
|
||||||
|
print -P "[%F{yellow}needs reboot%f]"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|||||||
18
reboot.yml
18
reboot.yml
@@ -1,13 +1,19 @@
|
|||||||
- name: Stop mollyguard if active
|
|
||||||
ansible.builtin.script: stop_mollyguard
|
|
||||||
register: mg
|
|
||||||
- name: Determine if a reboot is necessary
|
- name: Determine if a reboot is necessary
|
||||||
ansible.builtin.command:
|
ansible.builtin.command:
|
||||||
cmd: ~/bin/needs_reboot
|
cmd: ~/bin/needs_reboot
|
||||||
register: needs_reboot
|
register: needs_reboot
|
||||||
|
- name: Stop mollyguard if active
|
||||||
|
become: true
|
||||||
|
ansible.builtin.script: stop_mollyguard
|
||||||
|
register: mg
|
||||||
|
- name: Print mg dict
|
||||||
|
ansible.builtin.debug:
|
||||||
|
var: mg
|
||||||
|
when: needs_reboot.stdout == "yes"
|
||||||
- name: Conditionally reboot
|
- name: Conditionally reboot
|
||||||
|
become: true
|
||||||
ansible.builtin.reboot:
|
ansible.builtin.reboot:
|
||||||
when:
|
when:
|
||||||
- inventory_hostname not in group['controller']
|
- inventory_hostname not in groups['control']
|
||||||
- mgc succeeded
|
- mg.failed is false
|
||||||
- needs_reboot succeeded
|
- needs_reboot.stdout == "yes"
|
||||||
|
|||||||
Reference in New Issue
Block a user