Ansible Built-in Module: Package

Ansible Built-in Module: Package

The package module of ansible.builtin is used to manage software packages on Linux-based systems. It is a generic module that supports multiple package managers (such as apt, yum, dnf, zypper, etc.) and can install, update, and remove packages. Its functionality is similar to the ansible.builtin.dnf built-in module, but it supports more package management tools, making it compatible with more Linux distributions.Ansible Built-in Module: Package1. Option Description

Option

Required

Type

Default Value

Description

name

Yes

str/list

None

The name of the package to install, remove, or update. It can be a single package name or a list.

state

No

str

present

The state of the package. It can be present, absent, latest.

manager

No

str

auto

Specifies the type of package manager, such as apt, yum, dnf, zypper, etc. Default is auto-detection.

disable_gpg_check

No

bool

No

If set to yes, disables GPG signature checking.

enablerepo

No

list

None

Enables specified repositories.

disablerepo

No

list

None

Disables specified repositories.

conf_file

No

str

None

Uses the specified configuration file.

releasever

No

str

None

Uses the specified release version.

update_cache

No

bool

No

If set to yes, updates the package cache before installing or updating packages.

Ansible Built-in Module: Package2. Examples

# Install a package using the auto-detected package manager
– name: Install a package
ansible.builtin.package:
name: httpd
state: present

# Install a package specifying the package manager
– name: Install a package using yum
ansible.builtin.package:
name: httpd
state: present
manager: yum

# Remove a package
– name: Remove a package
ansible.builtin.package:
name: httpd
state: absent

# Update all packages
– name: Update all packages
ansible.builtin.package:
name: ‘*’
state: latest

# Enable and disable repositories
– name: Install a package with specific repositories enabled and disabled
ansible.builtin.package:
name: httpd
enablerepo: epel
disablerepo: remi
state: present

# Install a package based on a condition
– name: Install httpd if not installed
ansible.builtin.package:
name: httpd
state: present
when: “‘httpd’ not in ansible_facts.packages”

# Install a specific version of a package based on the release version
– name: Install a specific version of a package
ansible.builtin.package:
name: httpd-2.4.6-90.el7
state: present
releasever: 7

Recommended Articles on Ansible

  • Ansible Built-in Module: get_url

  • Ansible Command Line Guide

  • Ansible Built-in Module: file

  • Ansible Built-in Module: assemble

  • Ansible Built-in Module: authorized_key

  • Ansible Built-in Module: copy

  • Ansible Built-in Module: cron

  • Ansible Built-in Module: file

  • Introduction to Terraform and Ansible

  • Ansible Built-in Module: known_hosts

  • Ansible Built-in Module: yum_repository

  • Ansible Built-in Module: user

  • Ansible Built-in Module: lineinfile

  • Ansible Built-in Module: unarchive

  • Ansible Built-in Module: group

Course Recommendations

  • Introduction to Red Hat RHCE 9.0 Course

  • Analysis of RHCE Certification Value: Salary Levels and Popular Hiring Companies (2025)

  • RHCA | Weisi & Red Hat 2025 Joint Class, Taught by Official Red Hat Instructors!

Ansible Built-in Module: Package

END

1Weisi Network, established in 2002

Professional IT certification training for 23 years, enrolling nationwide!

Click to see more 【Training Course Directory】

Weisi – Main courses include:

*Network Technology: Huawei HCIA/ HCIP/HCIE;Cisco CCNA/CCNP/CCIE

*Linux Technology: Red Hat RHCE/RHCA

*K8S & Containers: CKA/CKS

*Database: ORACLE OCP/ OCM; MySQL; Dameng Database

*Virtualization: VMware VCP/VCAP

*Security Certifications: CISP System/CISSP/ CISA;CCSK;CISAW System

*Management: PMP Project Management; Soft Exam Intermediate/Advanced; ITIL System;Togaf

Other courses include: ACP; Azure…

— Recommended Linux Articles —

[Resource Collection] 200 Common Linux Command Manuals

Ansible Built-in Module: Package

Complete New Chinese Version PDF of “Bird Brother’s Linux Cookbook”

Ansible Built-in Module: Package

40 Simple and Effective Linux Shell Script Examples

Ansible Built-in Module: Package

Essential for Linux Operations, 100 Common Interview Questions

Ansible Built-in Module: Package

Powerful Linux Study Notes, Worth a Look (Includes PDF Download)

Ansible Built-in Module: Package

What Advantages Does Red Hat Certification Have? Quick Look at This Article

Ansible Built-in Module: Package

5 Types of Linux Package Management Tools Chinese Manual! Check It Out!

Ansible Built-in Module: Package

Ansible Built-in Module: Package

System Integration

Certification Training

Buy Equipment, Contact Us

IT Maintenance, Contact Us

IT Training, Contact Us

Leave a Comment