chasinglogic.os_packages
Ansible Role: os-packages
This role helps to install packages using variable files.
When and Why to Use This Role
When managing multiple systems, you often need to install OS packages that don't require any extra setup after installation. For example, packages like build-essential
or gcc
for a build server. Creating individual roles for each package can be very tedious. Even if you don't use separate roles for each package, you might find yourself dealing with multiple package lists scattered throughout your roles, which can be hard to keep consistent and up to date.
This role lets you keep package lists in variable files for easy reference and management. It works in mixed environments; if you have deb_packages
specified but Ansible is not running on a system with apt installed, those deb_packages
will simply be ignored—no extra conditions needed.
However, it's not a good idea to use this role for packages that need a lot of configuration after installation, like Nextcloud, NGINX, or Apache. These packages should have their own dedicated role that takes care of all their setup details.
Role Variables
Name | Description | Type | Default | Required |
---|---|---|---|---|
packages_apt_globally_update_cache | Whether to run a global apt update before installing packages. |
boolean | true | no |
generic_packages | A list of packages using the package module in Ansible. Many have the same names across different Linux distributions. |
list | [] | no |
deb_packages | A list of packages specifically for .deb packages, using the correct packaging module for the target system in Ansible. | list | [] | no |
rpm_packages | A list of packages specifically for .rpm packages, using the correct packaging module for the target system in Ansible. | list | [] | no |
pacman_packages | A list of packages to be installed using the pacman module in Ansible. | list | [] | no |
generic_package_specs | A list of package specifications using the package module in Ansible, with consistent names across Linux distributions. |
list | [] | no |
deb_package_specs | A list of package specifications for .deb packages, using the correct module based on the target system. | list | [] | no |
rpm_package_specs | A list of package specifications for .rpm packages, using the correct module based on the target system. | list | [] | no |
pacman_package_specs | A list of package specifications using the pacman module in Ansible. | list | [] | no |
Specifying Dependencies
The variables generic_packages
, deb_packages
, pacman_packages
, and rpm_packages
are simply lists of packages to install, like this:
generic_packages:
- gcc
- tmux
- vim
Using Other States
The variables generic_package_specs
, deb_package_specs
, and others allow for more specific control over package installation. You can use them to remove packages, install the latest version, or get detailed listings of installed packages. Here's how to specify a package with a certain state:
generic_package_specs:
- name: gcc
state: latest
For deb_package_specs
, you can also specify the update_cache
option:
deb_package_specs:
- name: gcc
state: latest
update_cache: yes
Example Playbook
- hosts: all
roles:
- role: os-packages
License
ansible-galaxy install chasinglogic.os_packages