AnsiblePilot — Master Ansible Automation

AnsiblePilot is the leading resource for learning Ansible automation, DevOps, and infrastructure as code. Browse over 1,400 tutorials covering Ansible modules, playbooks, roles, collections, and real-world examples. Whether you are a beginner or an experienced engineer, our step-by-step guides help you automate Linux, Windows, cloud, containers, and network infrastructure.

Popular Topics

About Luca Berton

Luca Berton is an Ansible automation expert, author of 8 Ansible books published by Apress and Leanpub including "Ansible for VMware by Examples" and "Ansible for Kubernetes by Example", and creator of the Ansible Pilot YouTube channel. He shares practical automation knowledge through tutorials, books, and video courses to help IT professionals and DevOps engineers master infrastructure automation.

Ansible Rolling Update Debian/Ubuntu: apt Module Guide (Examples) — Video Tutorial

How to perform rolling updates on Debian and Ubuntu with Ansible apt module. Update packages, handle reboots, and manage serial deployments with examples.

Watch Video

Watch "Ansible Rolling Update Debian/Ubuntu: apt Module Guide (Examples)" on YouTube

What You'll Learn

Full Tutorial Content

How to perform Rolling Update with Ansible in Debian-like systems? I'm going to show you a live Playbook and some simple Ansible code. I'm Luca Berton and welcome to today's episode of Ansible Pilot Ansible Rolling Update packages in Debian-like systems Today we're talking about rolling updates on Debian-like systems using Ansible module apt. We already talked about this module for installing packages but we would like to consider another use case. This module allows you to manage packages with the apt package manager. Parameters - name _string_ - state _string_ - update_cache _boolean_ - upgrade _no/safe/full/dist_ The parameter list is pretty wide but today we are focus on these four options for our use case. The "name" parameter could be a package or we could select all the packages of the system with the "\*" star symbol. The state for this case needs to be "latest" so we target the latest version for every package. The "update_cache" is useful to forces the update of repository metadata before the installation. Another useful option is "upgrade" with four alternatives: - default is a no, - if safe, performs an aptitude safe-upgrade, - if full, performs an aptitude full-upgrade, - if dist performs an apt-get dist-upgrade. Demo Let's jump in a real-life Playbook of Rolling Update on Debian-like systems with Ansible Playbook. - apt-nginx.yml ```yaml --- - name: rolling update Playbook hosts: all become: true tasks: - name: ensure pkg updated ansible.builtin.apt: name: nginx state: latest update_cache: true ``` - apt-system.yml ```yaml --- - name: rolling update Playbook hosts: all become: true tasks: - name: ensure system updated ansible.builtin.apt: name: "*" state: latest update_cache: true ``` [code with ❤️ in GitHub](https://github.com/lucab85/ansible-pilot/tree/master/rolling%20update%20Debian-like%20systems) Conclusion Now you know better how to troubleshoot the most common Ansible error about privilege escalation. Complete Rolling Update Playbook for Debian/Ubuntu ```yaml --- - name: Rolling update for Debian/Ubuntu servers hosts: webservers serial: 1 max_fail_percentage: 0 become: true pre_tasks: - name: Remove from load balancer ansible.builtin.uri: url: "http://lb.example.com/api/servers/{{ inventory_hostname }}/disable" method: POST delegate_to: localhost - name: Wait for connections to drain ansible.builtin.pause: seconds: 30 tasks: - name: Update apt cache ansible.builtin.apt: update_cache: true cache_valid_time: 0 - name: Upgrade all packages ansible.builtin.apt: upgrade: dist register: update_result - name: Show update summary ansible.builtin.debug: msg: "Packages updated: {{ update_result.stdout_lines | select('match', '^Inst') | list | length }}" when: update_result.stdout_lines

About This Tutorial

Read the full written article: Ansible Rolling Update Debian/Ubuntu: apt Module Guide (Examples)

Topics Covered

Related Video Tutorials