Update All Packages on Ubuntu Server With Ansible

This blog post, Will show you to update all software packages on a Ubuntu server using an Ansible playbook without rebooting the server.

Apt Module

By default, Ansible comes with the Apt module which allows us to update packages on Ubuntu servers. The module is capable of doing the same things as running the apt command directly on a server.

Inventory file

Below is my inventory file and host vars for the host login configuration. The become options are very important and In my case, I am using the following:

You can also see that I am using SSH authntication to connect to my managed hosts.



The following playbook will install all the available packages on the managed hosts without restarting them.

- hosts: servers
    - name: Update cache 
       update_cache: yes
    - name: Upgrade all packages on servers
        name: "*"
        state: latest

To run the playbook I will use the following command.

sudo ansible-playbook playbooks/update-ubuntu.yml -i hosts

Success! You're on the list.

Leave a comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.