-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdnf_update.yml
More file actions
41 lines (34 loc) · 1.55 KB
/
dnf_update.yml
File metadata and controls
41 lines (34 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
---
- name: RHEL,ROCKY,CENTOS 8 UPDATES using DNF
hosts: '*'
become: yes
vars:
update_excludes: '[]' # "[]" < will not exclude any packages remove "[]" and list specific packages if needed > "kernel-*, kmod, vim, bind"
update_installs: '*' # "*" < will update all packages remove "*" and list specific packages if needed > "kernel-*, kmod, vim, bind"
tasks:
- name: taking notes on the kernel version before we update
debug:
msg: "{{ ansible_kernel }}"
register: pre_update
- name: updating the system
dnf:
name: "{{ update_installs | default('*') }}"
state: latest
exclude: "{{ update_excludes | default([]) }}"
- name: taking notes on the kernel version after we update
shell: (rpm -q --last kernel | awk 'NR==1{sub(/kernel-/,""); print $1}')
register: post_update
- name: capturing dnf history ID in case we need to roll back
shell: dnf history | awk 'NR==4 {print $1}'
register: dnf_history_id
- name: Rebooting because there is a new kernel installed per notes
reboot:
msg: "Reboot initiated by Ansible for kernel updates" #grep in remote var/log/messages for tracking if needed
post_reboot_delay: 30
when: ("{{ansible_kernel}}" != "{{post_update.stdout}}")
- name: display kernel version after updates
debug:
msg: "{{post_update.stdout}}"
- name: DNF history ID
debug:
msg: What packages were altered while running this playbook can be found using DNF history info "{{dnf_history_id.stdout}}"