Skip to content
TrySitePrice

Ansible apt update all packages on Ubuntu / Debian Linux

Best/Tutorial

Ansible is an automation tool that can be used to manage and automate tasks on multiple servers. To update all packages on Ubuntu or Debian Linux using Ansible, you can use the apt module. Here are the steps to do this:

  1. Install Ansible on your management machine by running the command sudo apt install ansible.
  2. Create an Ansible playbook, which is a file that defines the tasks to be executed. You can create a playbook called update.yml with the following contents:
---
- name: Update all packages on Ubuntu/Debian
 hosts: all
 become: yes
 tasks:
 - name: Update all packages
 apt:
 update_cache: yes
 upgrade: dist
  1. Run the playbook with the ansible-playbook command, replacing <inventory file> with the path to your inventory file.
ansible-playbook -i <inventory file> update.yml
  1. The playbook will connect to all hosts specified in the inventory file and update all packages on the servers.
  2. You can also use the apt-get command to update packages and add -y flag to automatically approve any package updates that require it.
- name: Update all packages on Ubuntu/Debianrn hosts: all
 become: yesrn tasks:
 - name: Update all packagesrn command: apt-get update -yrn - name: Upgrade all packagesrn command: apt-get upgrade -y
  1. Remember to always test the playbook on a small subset of servers or in a test environment before running it on production systems.
rnBy using ansible you can automate the package updates on multiple servers at once, saving you time and effort.