How to Install Ansible Galaxy Roles and Collections

Using Ansible doesn’t require you create everything from scratch. Ansible Galaxy encourages users to share pre-configured Ansible roles and collections for popular tasks and applications you can implement within playbooks immediately. These community submitted roles can save time when configuring playbooks for deployment.

Remember, when browsing roles on Ansible Galaxy, it’s important to check stats such as last commit, quality score, community score, and download count. These stats help you understand the quality of submitted content.

Below we’ll cover how to install content from the Ansible Galaxy community with examples:

Install Ansible Galaxy Roles

  1. Visit https://galaxy.ansible.com
  2. Search for a role you wish to use
  3. Select the role name for more details
  4. Open your terminal (or SSH)
  5. Install the Ansible Galaxy role:ansible-galaxy install author.role
    – e.g. ansible-galaxy install geerlingguy.security

    You’ll see the URL for the downloaded role and extraction destination.

  6. Add the role in an Ansible playbook:
Ansible Galaxy Security Role Details
Copy the installation command to your clipboard to get started
tasks:
 name: Include geerlingguy's Security role
    include_role: geerlingguy.security

Install Ansible Galaxy Collections

An Ansible collection is a package of playbooks, roles, modules, and plugins for distribution. Collections show up in Galaxy searches alongside roles. When you select a collection, you’ll have two download options:

  • Install the collection role from your terminal: ansible-galaxy collection install authorname.collectionname
    – e.g. ansible-galaxy collection install awx.awx
  • Select Download Tarball to download the compressed archive to your home folder, and install it from your terminal: ansible-galaxy collection install packagename.tar.gz
    – e.g. ansible-galaxy collection install awx-awx-9.2.0.tar.gz

Here are two ways to implement Ansible collections in your playbooks:

tasks:
 import_role: 
    name: awx.awx

collections:
 name: awx.awx 
tasks:

Learn more about IT automation in our Ansible Education Channel.

Looking to improve performance with your Ansible agent? Manage your Ansible agent with the Cloud Server that fits your needs.

Was this article helpful? Let us know!