Skip to content

Instantly share code, notes, and snippets.

@erbrito
Last active January 11, 2023 19:00
Show Gist options
  • Save erbrito/fcf91b17165b442f605393fb3ae2e55a to your computer and use it in GitHub Desktop.
Save erbrito/fcf91b17165b442f605393fb3ae2e55a to your computer and use it in GitHub Desktop.
ansible playbook to patch RHEL8
---
- name: Patch server
hosts: all
become: true
vars:
packages_to_update:
- package1
- package2
- package3
lv_max_size: 3
tasks:
- include_role:
name: lvm
vars:
lv_max_size: "{{ lv_max_size }}"
- include_role:
name: upgrade_packages
vars:
packages_to_update: "{{ packages_to_update }}"
---
- name: Patch server
hosts: all
become: true
vars:
packages_to_update:
- package1
- package2
- package3
lv_max_size: 3
tasks:
- name: Check if LVM commands are available
command: which lvcreate
register: lvm_check
ignore_errors: true
- name: Install LVM2 package
yum:
name: lvm2
state: present
when: lvm_check.rc != 0
- name: Show current logical volume size
command: lvs --noheadings --units g -o lv_size,lv_path | grep '/dev/mapper/system-var'
register: lv_size_info
- set_fact:
current_lv_size: "{{ lv_size_info.stdout_lines[0].split()[0] }}"
- name: Increase logical volume size
lvm:
vg: system
lv: system-var
size: +2g
when: current_lv_size|float < lv_max_size
- name: Resize the filesystem
command: resizefs /dev/mapper/system-var
when: lvm_check.rc == 0 and current_lv_size|float < lv_max_size
- name: Upgrade packages
yum:
name: "{{ packages_to_update }}"
state: latest
when: packages_to_update is defined
- name: Upgrade all packages
yum:
name: '*'
state: latest
when: packages_to_update is not defined
- name: Check if LVM commands are available
command: which lvcreate
register: lvm_check
ignore_errors: true
- name: Install LVM2 package
yum:
name: lvm2
state: present
when: lvm_check.rc != 0
- name: Show current logical volume size
command: lvs --noheadings --units g -o lv_size,lv_path | grep '/dev/mapper/system-var'
register: lv_size_info
- set_fact:
current_lv_size: "{{ lv_size_info.stdout_lines[0].split()[0] }}"
- name: Increase logical volume size
lvm:
vg: system
lv: system-var
size: +2g
when: current_lv_size|float < lv_max_size
- name: Resize the filesystem
command: resizefs /dev/mapper/system-var
when: lvm_check.rc == 0 and current_lv_size|float < lv_max_size
---
- name: Upgrade packages
yum:
name: "{{ packages_to_update }}"
state: latest
when: packages_to_update is defined
- name: Upgrade all packages
yum:
name: '*'
state: latest
when: packages_to_update is not defined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment