0Pricing
Ansible Academy · Lesson

Install Packages with the package Module

Manage software across distros.

Install Packages with the package Module is a free Ansible Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Ansible Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

One Module, Many Distros

The package module installs software without you naming the package manager. It picks apt, dnf, or yum automatically for the target host.

Install with state present

To install software, give the package a name and set state: present. Ansible installs it only if it is missing.

ansible.builtin.package:
  name: nginx
  state: present

name Is the Package

The name key holds the package as the distro knows it, like nginx or git. Most common names match across distros.

name: git

Remove with state absent

Set state: absent to uninstall a package. The module removes it only if it is currently installed, staying idempotent.

ansible.builtin.package:
  name: telnet
  state: absent

Install a List at Once

Pass a list to name and the module installs every package in one task, which is cleaner and faster than many separate tasks.

ansible.builtin.package:
  name:
    - git
    - curl
    - vim
  state: present

It Is Idempotent

Run the task twice and the second run reports ok, not changed. The package is already there, so nothing happens again.

package Wraps the Native Manager

The package module is a generic wrapper. Under the hood it calls apt on Debian or dnf on Fedora, so you write the task once.

Reach for Specific Modules When Needed

For manager-only features, use apt or dnf directly. They expose options like update_cache that package cannot.

ansible.builtin.apt:
  name: nginx
  update_cache: true

Privilege Escalation Is Usually Needed

Installing software needs root, so add become: true to the task or play. Ansible then runs the package task with sudo.

- name: Install nginx
  become: true
  ansible.builtin.package:
    name: nginx

state present Is Often the Default

Many package modules treat present as the default state. Writing it anyway keeps your intent obvious to the next reader.

Try It Ad-Hoc

You can install ad-hoc without a playbook. This installs git on every host in the web group in one line.

ansible web -b -m package -a "name=git state=present"

Quick Check

You want one task that installs nginx on both Debian and Fedora hosts.

Recap

The package module installs or removes software with present and absent, takes a list, stays idempotent, and works across distros. 📦

Frequently asked questions

Is the “Install Packages with the package Module” lesson free?

Yes — the full text of “Install Packages with the package Module” is free to read here on the web, and the Ansible Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Ansible Academy course, upgrade to CoddyKit PRO.

What will I learn in “Install Packages with the package Module”?

Manage software across distros. You practise Ansible Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Ansible Academy?

No prior experience is required. Ansible Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Install Packages with the package Module” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Ansible Academy lesson?

Yes. Every Ansible Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. What a Module Actually Is
  2. Install Packages with the package Module
  3. Manage Services with systemd
  4. Read the Docs with ansible-doc
← Back to Ansible Academy