• Skip to primary navigation
  • Skip to main content

Uly.me

cloud engineer

  • Home
  • About
  • Archives

patch

Ansible Update Playbook

by Ulysses · Aug 1, 2020

I have an Ansible playbook that will patch all Ansible clients defined in the Ansible hosts file. The following are contents of my hosts file, and the update playbook.

File: /etc/ansible/hosts

[all:vars]
ansible_user='ubuntu'
ansible_become=yes
ansible_become_method=sudo
ansible_python_interpreter='/usr/bin/env python3'
[servers]
server1
server2
server3
[servers:vars]
ansible_python_interpreter=/usr/bin/python3

[all:vars] ansible_user='ubuntu' ansible_become=yes ansible_become_method=sudo ansible_python_interpreter='/usr/bin/env python3' [servers] server1 server2 server3 [servers:vars] ansible_python_interpreter=/usr/bin/python3

File: /etc/ansible/update.yml

---
- hosts: servers
  become: true
  become_user: root
  tasks:
    - name: Update apt repo and cache on all Debian/Ubuntu boxes
      apt: update_cache=yes force_apt_get=yes cache_valid_time=3600

    - name: Upgrade all packages on servers
      apt: upgrade=dist force_apt_get=yes

    - name: Check if a reboot is needed on all servers
      register: reboot_required_file
      stat: path=/var/run/reboot-required get_md5=no

    - name: Reboot the box if kernel updated
      reboot:
        msg: "Reboot initiated by Ansible for kernel updates"
        connect_timeout: 5
        reboot_timeout: 300
        pre_reboot_delay: 0
        post_reboot_delay: 30
        test_command: uptime
      when: reboot_required_file.stat.exist

--- - hosts: servers become: true become_user: root tasks: - name: Update apt repo and cache on all Debian/Ubuntu boxes apt: update_cache=yes force_apt_get=yes cache_valid_time=3600 - name: Upgrade all packages on servers apt: upgrade=dist force_apt_get=yes - name: Check if a reboot is needed on all servers register: reboot_required_file stat: path=/var/run/reboot-required get_md5=no - name: Reboot the box if kernel updated reboot: msg: "Reboot initiated by Ansible for kernel updates" connect_timeout: 5 reboot_timeout: 300 pre_reboot_delay: 0 post_reboot_delay: 30 test_command: uptime when: reboot_required_file.stat.exist

Here’s how I run my Ansible update playbook.

ansible-playbook -i /etc/ansible/hosts /etc/ansible/update.yml

ansible-playbook -i /etc/ansible/hosts /etc/ansible/update.yml

The advantage of using Ansible is, I can run a single playbook to update dozens of servers. It’s also a great tool for rolling out software as well as executing commands to a group of servers.

Filed Under: Linux Tagged With: ansible, hosts, patch, playbook, update

Get-Hotfix

by Ulysses · Dec 10, 2019

How to find out if a Windows Server was last patched.

From Powershell, run this command.

get-hotfix

get-hotfix

From the command line, run this command.

C:\> systeminfo.exe

C:\> systeminfo.exe

Or from the menu, follow these steps.

Open the Windows Settings UI.
Click on Update & security.
Click on the "Update history" link located under the Windows Update tab.

Open the Windows Settings UI. Click on Update & security. Click on the "Update history" link located under the Windows Update tab.

Filed Under: Windows Tagged With: get-hotfix, history, info, patch, systeminfo, update

When Linux Was Last Patched

by Ulysses · Feb 1, 2019

Here’s a handy command to see if Linux was patched recently.

rpm -qa --last | head

rpm -qa --last | head

A typical result would look something like this.

name-of-patch          Sun 20 Jan 2019 05:36:31 PM UTC
name-of-patch          Fri 18 Jan 2019 02:52:51 PM UTC

name-of-patch Sun 20 Jan 2019 05:36:31 PM UTC name-of-patch Fri 18 Jan 2019 02:52:51 PM UTC

Filed Under: Linux Tagged With: latest, patch

Copyright © 2012–2021