Skip to content

Commit 51dedb9

Browse files
committed
Init role content
1 parent 3f592b9 commit 51dedb9

File tree

4 files changed

+114
-2
lines changed

4 files changed

+114
-2
lines changed

README.md

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,48 @@
1-
# el_patching
2-
Enterprise Linux OS patching with Ansible
1+
# Ansible role - EL Patching
2+
3+
Apply OS patches on Enterprise Linux machines (e.g. RHEL, CentOS, Rocky, Alma, Fedora ). You can decide which patching method you want to use. There are 3 methods:
4+
5+
- `all` - Apply all patches on target host
6+
- `security` - Apply only security patches on target host
7+
- `bugfix` - Apply only bugfix patches on target host
8+
9+
**I strongly advise visit blog post for detailed information and my recommendation. - BLOG POST SOON**
10+
11+
## Requirements
12+
13+
Only dnf must be available on target machine.
14+
15+
## Role Variables
16+
17+
- **Default Variables**. Usually there is no need to change this but rather overwrite value in `host_vars` or `group_vars` if required.
18+
19+
| Variable Name | Default Value | Description
20+
| ----------- | ----------- | ----------- |
21+
| `el_patching_required_packages` | `"yum-utils"` | It is required to install yum-utils as this role verify reboot with `needs-restarting`.
22+
| `el_patching_auto_reboot` | `false` | By default do not reboot target host. Only verify if reboot is required.
23+
| `el_patching_reboot_timeout` | `600` | By default auto reboot is disable but default timeout value is set to 5minutes. Value is in `seconds`.
24+
| `el_patching_method` | `"security"` | By default apply only `security` patches on target host. Possible values `"security"/"bugfix"/"all"`
25+
| `el_patching_check_mode` | `false` | By default do not run tasks in check mode. You can enable check mod to simulate patching and reboot.
26+
27+
## Dependencies
28+
29+
No Dependencies
30+
31+
## Example Playbook
32+
33+
Create the following playbook.
34+
```yaml
35+
- name: Apply OS Patches
36+
hosts: your_patching_inventory_group_or_host
37+
become: true
38+
roles:
39+
- el_patching
40+
```
41+
42+
## License
43+
44+
MIT
45+
46+
## Author Information
47+
48+
Created by [VoidQuark](https://voidquark.com)

defaults/main.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
# defaults file for el_patching
3+
el_patching_required_packages: "yum-utils"
4+
el_patching_reboot_timeout: 600
5+
el_patching_method: "security"
6+
el_patching_auto_reboot: false
7+
el_patching_check_mode: false

meta/main.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
galaxy_info:
2+
author: voidquark
3+
description: Apply Linux OS patches
4+
company: VoidQuark
5+
6+
license: MIT
7+
8+
min_ansible_version: "2.1"
9+
10+
platforms:
11+
- name: Fedora
12+
versions:
13+
- all
14+
- name: EL
15+
versions:
16+
- "8"
17+
- "9"

tasks/main.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
# tasks file for el_patching
3+
4+
- name: Ensure that need-restarting binary is present
5+
ansible.builtin.dnf:
6+
name: "{{ el_patching_required_packages }}"
7+
state: present
8+
9+
- name: Update all packages
10+
ansible.builtin.dnf:
11+
name: "*"
12+
state: latest
13+
check_mode: "{{ el_patching_check_mode }}"
14+
when: el_patching_method == "all"
15+
16+
- name: Apply security patches only
17+
ansible.builtin.dnf:
18+
name: "*"
19+
security: true
20+
state: latest
21+
check_mode: "{{ el_patching_check_mode }}"
22+
when: el_patching_method == "security"
23+
24+
- name: Apply bugfix patches only
25+
ansible.builtin.dnf:
26+
name: "*"
27+
bugfix: true
28+
state: latest
29+
check_mode: "{{ el_patching_check_mode }}"
30+
when: el_patching_method == "bugfix"
31+
32+
- name: Verify if restart is required
33+
ansible.builtin.command:
34+
cmd: needs-restarting --reboothint
35+
register: __el_patching_need_restart
36+
failed_when: __el_patching_need_restart.rc > 1
37+
38+
- name: Reboot
39+
ansible.builtin.reboot:
40+
reboot_timeout: "{{ el_patching_reboot_timeout }}"
41+
check_mode: "{{ el_patching_check_mode }}"
42+
when: el_patching_auto_reboot | bool and __el_patching_need_restart.rc == 1

0 commit comments

Comments
 (0)