Ansible Package Installations

From bib. source

[…] wouldn’t it be better if people could share roles for commonly-installed applications and services? Enter Ansible Galaxy. Ansible Galaxy, or just ‘Galaxy’, is a repository of community-contributed Ansible content. There are thousands of roles available which can configure and deploy common applications, and they’re available through the ansible-galaxy command. Galaxy offers the ability to add, download and rate roles.

ansible-galaxy command

Essentially, while one can make roles in or on Ansible, roles can, like packages, also be acquired–i.e., installed–from repositories of Ansible content via the ansible-galaxy command (Geerling 2023, 142). The main repository from which to install Ansible content is called Ansible Galaxy, sometimes just shortened to “Galaxy¨ (Ibid). The main things to download and install from there are roles for one’s playbooks (Ibid):

From bib. source

One of the primary functions of the ansible-galaxy command is retrieving roles from Galaxy. Roles must be downloaded before they can be used in playbooks.

In Ansible Galaxy, people can also rate and add roles so long as they are logged in to an account on it (Ibid).

Installing a role via ansible-galaxy could look like this (Ibid):

ansible-galaxy role install geerlingguy.apache

Or, to make it more universal:

ansible-galaxy role install $ANSIBLE_ROLE_NAME

ansible-galaxy requirements file

Alternatively, instead of doing individual manual command-line installations of Ansible roles, one can pass a “requirements¨ file with the r option, that file containing a list of all that to be downloaded and installed by ansible-galaxy (Geerling 2023, 143). While this file can be a regular text file, it can also be written as a YAML file (Ibid). The aforementioned command would look like the following:

ansible-galaxy install -r ${REQUIREMENTS_FILE}

The benefit of the latter is that you can install roles, and other Ansible content, from many repositories and sources, as well as “specify the path into which the roles should be downloaded¨ (Ibid).

The syntax of such a YAML requirements file would look something like the following (Ibid):

---
roles:
  # From Ansible Galaxy, latest version
  - name: geerlingguy.firewall
 
  # From Ansible Galaxy, specifying the version
  - name: geerlingguy.php
    version: 4.3.1
 
  # From Github, with a custom name and version
  - src: https://github.com/geerlingguy/ansible-role-passenger
    name: passenger
    version: 2.0.0
 
  # From a web server, with a custom name
  - src: https://www.example.com/ansible/roles/my-role-name.tar.gz
    name: my-role

Other ansible-galaxy role subcommands

The ansible-galaxy command using the role subcommand can also take the following further subcommands (Geerling 2023, 146):

  • list, which displays a list of installed roles with their version numbers
  • remove, which removes an installed role with the name specified in its argument
  • init, which creates a structured directory tree suitable for Ansible Galaxy submission for the role it newly creates (refer to 20250526174026-Packaging_and_Ansible_Roles)

ad-hoc_command ad-hoc_commands command_line command_lines command_line_interface command_line_interfaces Ansible_Galaxy Galaxy text_file text_files plaintext plaintext_file plaintext_files YAML_Aint_Markup_Language Yet_Another_Markup_Language package_manager package package_management configuration_management configuration role


bibliography

  • “Playbook Organization - Roles, Includes, and Imports.” In Ansible for DevOps: Server and Configuration Management for Humans, 2nd ed., 123–47. Leanpub, 2023.