Skip to content

Deploying Roles With Ansible Galaxy

Avatar photo

So you have learned about Ansible Roles and the importance of using roles. Ansible Galaxy is a public library where you can find thousands of roles written by other ansible users and administrators. Ansible Galaxy is arranged with a searchable database where you can easily find suitable role which you can re-use in your ansible environment.

See all parts of  Automation with Ansible Guides here.

Login to Ansible Galaxy and explore the portal; you can also find the  docuemention on how to use roles from Ansible Galaxy, how to upload your roles to the library etc.

ansible-galaxy command line

You can use ansible-galaxy ๏ปฟcommand to search, install or get information about the roles from Ansible Galaxy. In below example, we are searching for a role with word java๏ปฟ.

[root@ansible-box ansible]# ansible-galaxy search "java"
Found 775 roles matching your search:
 Name                                                  Description
 ----                                                  -----------
 4ARMED.java8                                          Java 8 Installation for Debian-based OSes
 5KYDEV0P5.skydevops-java                              Installs and configures Oracle Java 1.8.x
 5KYDEV0P5.skydevops-maven                             Install and configure Apache Mvaen 3.x.x
 aaronpederson.python                                  Python is a programming language that lets you work quick
 aaronpederson.webgoat                                 Webgoat - a deliberately insecure JavaEE application to t
 abelboldu.zookeeper                                   Zookeeper cluster role for MidoNet deployments.                                          Java for Linux
 abessifi.fitnesse                                     Install FitNesse acceptance testing framework on GNU/Linu                                         Java for GNU/Linux systems
 abessifi.osb                                          Install and configure Oracle Service Bus
 abessifi.weblogic                                     Install and configure Oracle Weblogic Server
 abn.ec2-api-tools-java                                Install and configure AWS ec2-api-tools on a target node
 adamcin.ansible-zookeeper                             Ansible Zookeeper Role

Or another example with author name

[root@ansible-box galaxy-roles]# ansible-galaxy search elasticsearch --author geerlingguy
Found 5 roles matching your search:
 Name                              Description
 ----                              -----------
 geerlingguy.elasticsearch         Elasticsearch for Linux.
 geerlingguy.elasticsearch-curator Elasticsearch curator for Linux.
 geerlingguy.filebeat              Filebeat for Linux.
 geerlingguy.kibana                Kibana for Linux.
 geerlingguy.logstash              Logstash for Linux.

below command with option info๏ปฟ will display the information about the role, like the author, license, creation date etc.

[root@ansible-box ansible]# ansible-galaxy info geerlingguy.git
Role: geerlingguy.git
        description: Git version control software
        active: True
        commit: 6d4696d59dfb6af69315978a47cb283b3aaaaa9c
        commit_message: Fix deprecation warnings in Ansible 2.5 for state 'present'.
        company: Midwestern Mac, LLC
        created: 2014-03-01T02:53:28.033086Z
        download_count: 86310
        forks_count: 61
        github_branch: master
        github_repo: ansible-role-git
        github_user: geerlingguy
        id: 431
        imported: 2018-04-04T19:50:26.043014-04:00
        is_valid: True
        license: license (BSD, MIT)
        min_ansible_version: 2.4
        modified: 2018-06-30T05:11:01.375198Z
        open_issues_count: 8
        path: [u'/root/.ansible/roles', u'/usr/share/ansible/roles', u'/etc/ansible/roles']
        role_type: ANS
        stargazers_count: 105

And you can install the role with install option. I am creating a new directoty and installing new role there by mentioning the option -p๏ปฟ.

[root@ansible-box ansible]# mkdir galaxy-roles
[root@ansible-box ansible]# cd galaxy-roles/
[root@ansible-box galaxy-roles]# ansible-galaxy install geerlingguy.git -p ./
- downloading role 'git', owned by geerlingguy
- downloading role from
- extracting geerlingguy.git to /root/ansible/galaxy-roles/geerlingguy.git
- geerlingguy.git (2.0.2) was installed successfully

And now we verify the content of the geerlingguy.git role installed.

[root@ansible-box galaxy-roles]# tree 
โ””โ”€โ”€ geerlingguy.git
    โ”œโ”€โ”€ defaults
    โ”‚   โ””โ”€โ”€ main.yml
    โ”œโ”€โ”€ LICENSE
    โ”œโ”€โ”€ meta
    โ”‚   โ””โ”€โ”€ main.yml
    โ”œโ”€โ”€ tasks
    โ”‚   โ”œโ”€โ”€ install-from-source.yml
    โ”‚   โ””โ”€โ”€ main.yml
    โ”œโ”€โ”€ tests
    โ”‚   โ”œโ”€โ”€
    โ”‚   โ”œโ”€โ”€ test-source.yml
    โ”‚   โ””โ”€โ”€ test.yml
    โ””โ”€โ”€ vars
        โ”œโ”€โ”€ Debian.yml
        โ”œโ”€โ”€ Fedora.yml
        โ”œโ”€โ”€ main.yml
        โ””โ”€โ”€ RedHat.yml

You can even install muliple roles with a file as below. The yml file contains the details of roles to be installed using ansible-galaxy.

$ ansible-galaxy install -r roles2install.yml

Once you have installed role, we can simply use it inside our playbook as normal.

- geerlingguy.git

Managing installed roles

You can list and remove those installed roles with same ansible-galaxy command.

[root@ansible-box galaxy-roles]# ansible-galaxy list
- geerlingguy.git, 2.0.2

[root@ansible-box galaxy-roles]# ansible-galaxy remove geerlingguy.git
- successfully removed geerlingguy.git

Using ansible-galaxy to create role

You can use ansible-galaxy init commnd to initilize a role with default directory structure. Using –offline option๏ปฟ can use if you want to do this activitiy without interacting with internet (Ansible Galaxy portal)

[root@ansible-box galaxy-roles]# ansible-galaxy init --offline mynewrole 
- mynewrole was created successfully
[root@ansible-box galaxy-roles]# tree
โ””โ”€โ”€ mynewrole
    โ”œโ”€โ”€ defaults
    โ”‚   โ””โ”€โ”€ main.yml
    โ”œโ”€โ”€ files
    โ”œโ”€โ”€ handlers
    โ”‚   โ””โ”€โ”€ main.yml
    โ”œโ”€โ”€ meta
    โ”‚   โ””โ”€โ”€ main.yml
    โ”œโ”€โ”€ tasks
    โ”‚   โ””โ”€โ”€ main.yml
    โ”œโ”€โ”€ templates
    โ”œโ”€โ”€ tests
    โ”‚   โ”œโ”€โ”€ inventory
    โ”‚   โ””โ”€โ”€ test.yml
    โ””โ”€โ”€ vars
        โ””โ”€โ”€ main.yml

Then you can modify the file contents as usual.

Refer more on ansible-galaxy cli documentation.

See all parts of  Automation with Ansible Guides here.


The views expressed and the content shared in all published articles on this website are solely those of the respective authors, and they do not necessarily reflect the views of the author’s employer or the techbeatly platform. We strive to ensure the accuracy and validity of the content published on our website. However, we cannot guarantee the absolute correctness or completeness of the information provided. It is the responsibility of the readers and users of this website to verify the accuracy and appropriateness of any information or opinions expressed within the articles. If you come across any content that you believe to be incorrect or invalid, please contact us immediately so that we can address the issue promptly.

Avatar photo
Gineesh Madapparambath is the founder of techbeatly and he is the author of the book - ๐—”๐—ป๐˜€๐—ถ๐—ฏ๐—น๐—ฒ ๐—ณ๐—ผ๐—ฟ ๐—ฅ๐—ฒ๐—ฎ๐—น-๐—Ÿ๐—ถ๐—ณ๐—ฒ ๐—”๐˜‚๐˜๐—ผ๐—บ๐—ฎ๐˜๐—ถ๐—ผ๐—ป. He has worked as a Systems Engineer, Automation Specialist, and content author. His primary focus is on Ansible Automation, Containerisation (OpenShift & Kubernetes), and Infrastructure as Code (Terraform). (aka Gini Gangadharan -


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.