Automating System Updates with Ansible Playbook

Raees Qazi | DevOps Engineer | Learner | Mentor | Creator | Briller Technologies

Hello everyone! ๐Ÿ‘‹
 Today, I’m going to share an exciting Ansible project with you. It’s a simple yet powerful example that shows how to automate system updates using an Ansible Playbook. I’m sure you’ll enjoy this hands-on learning experience.

๐Ÿง  Prerequisites

Before starting the practical part, make sure:

  • You have a master/Ansible control node set up.
  • At least one managed node (target server) is connected to your master/Ansible machine.

⚙️ Project Overview

In this project, we’ll create a playbook that updates and upgrades the system packages.

Important Note:
 Always perform system updates
outside of working hours to avoid downtime or interruptions.

๐Ÿงพ Steps to Create the Playbook

  1. Open a new playbook file in the terminal:
  • vim patch_server.yml

Write the following playbook content:

- name: Patch server
hosts: server2
become: yes

tasks:
- name: Update and upgrade packages
apt:
update_cache: yes
upgrade: dist

- name: Restart the server
reboot:
msg: "Server under patching activity maintenance"
when: ansible_distribution == 'Ubuntu'

Save and exit the file:

:wq

Run the playbook:

  • ansible-playbook patch_server.yml

๐Ÿš€ Result

That’s it! ๐ŸŽ‰
 Your system will now automatically update and reboot using the playbook. You’ve just automated a common sysadmin task with Ansible — pretty cool, right?

๐Ÿ’ฌ Final Thoughts

Automation saves time and reduces human error. Using Ansible for patching ensures consistency across multiple servers with minimal effort.

If you found this guide helpful, don’t forget to share and subscribe for more DevOps tutorials.

๐ŸŒ Online References


Comments