If you try to write every automation script from scratch for the EX294 exam, you will run out of time and sanity. Ansible Galaxy solves this by giving you a public marketplace of pre-built, battle-tested automation roles that you can download, install, and manage in seconds. Learning to use Galaxy is not optional — it is directly tested on the exam, and in real jobs it saves you from reinventing the wheel every time you need to configure a web server, a database, or a firewall.
Jump to a section
A simple way to picture Using Ansible Galaxy for Role Management
You have 34 friends coming over for a pizza party next Saturday. You want every pizza to taste exactly the same, but you also don't want to make the dough from scratch every time. You need a solution that lets you pull a ready-made recipe card from a library, tweak the toppings, and then bake 34 identical pizzas without rewriting the instructions each time.
That is exactly what Ansible Galaxy does for IT automation. Ansible Galaxy is an online library containing thousands of pre-written role recipe cards. A role is a complete, reusable automation package — it includes all the tasks, variables, files, templates, and dependencies needed to configure a specific service, like installing and setting up a web server. When you use the ansible-galaxy command to download a role from Galaxy, you are grabbing that recipe card. Once downloaded, you can install the role locally on your control node (the master machine that runs Ansible commands), and then manage it — update it, remove it, or pin it to a specific version — the same way you might sort and keep your physical recipe cards in a filing cabinet. Without Galaxy, you would have to write every automation task from scratch. With Galaxy, you stand on the shoulders of thousands of community bakers who have already perfected the recipes.
Ansible Galaxy is a public repository — a central website and command-line tool — where the Ansible community publishes roles for free. A role is a structured directory of automation content: it bundles together tasks (the individual action steps that Ansible executes, like 'install Apache'), handlers (special tasks that run only when notified, like 'restart the firewall'), variables (configurable values, such as the port number for a service), templates (files with placeholders that get filled in dynamically), and default files. Each role is designed to do one thing well, such as configuring a web server, a database server, or a monitoring agent.
Before Galaxy existed, administrators had to write all their automation in flat playbooks. A playbook is a YAML file (a human-readable data format) that lists hosts and tasks. As playbooks grew, they became hard to read and harder to reuse. If you wanted to set up a web server for three different projects, you had to copy and paste the same tasks into three separate playbooks. If you found a bug, you had to fix it in all three places. Roles solved this by packaging automation into reusable components that you can share across projects and teams.
To download a role from Galaxy, you use the command ansible-galaxy install followed by the role's name, for example: ansible-galaxy install geerlingguy.nginx. This command reaches out to the Galaxy server (galaxy.ansible.com), downloads the role, and places it into a default directory called ~/.ansible/roles (the tilde represents your home directory). You can change this directory by editing the roles_path setting in your ansible.cfg configuration file. Once the role is installed, you reference it in a playbook like this:
- hosts: webservers
roles:
- geerlingguy.nginxWhen Ansible runs this playbook, it automatically finds the role in the roles_path, executes all the tasks inside it, and applies those configurations to the servers in the webservers group. This saves you from writing the dozens of tasks needed to install Nginx, configure virtual hosts, and set up firewalls.
Managing roles works through three main operations: listing, updating, and removing. Use ansible-galaxy list to see which roles you have installed locally and what versions they are. Use ansible-galaxy install username.rolename --force to force an update to the latest version from Galaxy. Use ansible-galaxy remove username.rolename to delete the role from your system entirely. You can also specify a role file — a YAML file that lists multiple roles and their versions — using the -r flag, so you can install an entire set of dependencies for a project with a single command. Version pinning is crucial: you can write ansible-galaxy install geerlingguy.nginx,v3.0.0 to lock a specific version, preventing unexpected changes when the upstream role updates.
Why does this exist? Because writing automation from scratch for every service is slow, error-prone, and hard to maintain. Galaxy democratises automation: a junior administrator can download and use a role written by a senior engineer at a different company. It also enforces best practices, because the most popular roles are reviewed by the community and tested across many environments. What it replaces is the practice of storing all automation logic in monolithic playbooks, which were fragile and difficult to reuse.
For the EX294 exam, you must know the exact syntax of the ansible-galaxy command, the location of installed roles, how to specify version constraints, and how to use the requirements.yml file. You do not need to write roles from scratch on the exam — you only need to manage pre-existing ones.
Search for a role on Galaxy
Open a browser and go to galaxy.ansible.com, or use `ansible-galaxy search nginx` from the terminal. This step finds the exact namespace.rolename you need, e.g., 'geerlingguy.nginx'.
Install the role on the control node
Run `ansible-galaxy install geerlingguy.nginx,v3.0.0`. This downloads the role and places it in the default roles directory (~/.ansible/roles). The comma between the name and version is the exact syntax the exam expects.
Verify the installation
Run `ansible-galaxy list` and check that 'geerlingguy.nginx' appears in the output. This confirms the role is available for use in playbooks.
Reference the role in a playbook
Write a playbook YAML file that includes the line `roles: - geerlingguy.nginx` under the hosts section. When you run `ansible-playbook`, Ansible will locate the role in the roles_path and execute its tasks on the target servers.
Update the role to a newer version
Run `ansible-galaxy install geerlingguy.nginx,v3.1.0 --force` to replace the existing role with the new version. The `--force` flag is essential — without it, the install command skips the role because it already exists.
Remove the role when no longer needed
Run `ansible-galaxy remove geerlingguy.nginx`. This deletes the role's directory from the control node, freeing up disk space and preventing accidental use in future playbooks.
At a medium-sized e-commerce company, the server team manages 200 Linux servers spread across three data centres. Every new web server needs to have exactly the same configuration: the Nginx web server with specific modules, a custom firewall rule set, log rotation settings, and a monitoring agent. The senior engineer creates a role called 'company.nginx-standard' and publishes it to a private section of Ansible Galaxy (or uses a mirror like automation hub).
When a junior admin is asked to set up a new server, they do not log in and type commands manually. Instead, they open a terminal on the control node and run the following commands:
ansible-galaxy install company.nginx-standard — this downloads the role from the company's private Galaxy instance, placing it in the shared roles directory /etc/ansible/roles.
They create a simple playbook named webserver-baseline.yml that contains only: - hosts: new-server-group and roles: - company.nginx-standard.
They run ansible-playbook webserver-baseline.yml and the server is configured in under two minutes.
Later, when the security team requires a new firewall rule, the senior engineer updates the role, bumps the version number to 2.1.0, and publishes it. The junior admin updates their local setup by running ansible-galaxy install company.nginx-standard,v2.1.0 --force. This push-button update model eliminates configuration drift — the problem of servers slowly becoming different from each other because of manual changes.
In a larger enterprise, the team uses a requirements.yml file that lists all roles needed for the entire infrastructure. This file is stored in the Git repository alongside the playbooks. When a new team member clones the repository, they run ansible-galaxy install -r requirements.yml and instantly have every role needed. This is exactly how CI/CD pipelines (automated software testing and deployment systems) work: the pipeline runs the install command before any automation jobs.
The key outcome is speed and consistency. What used to take a human two hours of repetitive typing now takes a machine 90 seconds. The company saves money, reduces human error, and ensures every server is compliant with security policies. For the EX294 exam, you will not be asked to manage a real company's servers, but you will be asked to simulate these exact steps in the exam environment.
The EX294 exam tests your ability to use ansible-galaxy as a command-line tool to download, install, list, and remove roles from Ansible Galaxy. This is a hands-on practical exam, so you will be at a terminal, not answering multiple-choice questions, but the concepts behind the commands are still critical.
The examiners love to test the following specific operations and concepts:
Installing a role from Galaxy with a specific version constraint: ansible-galaxy install geerlingguy.nginx,v3.0.0. They will give you a role name and a version number, and you must type the exact syntax. The comma before the version is mandatory — no space.
Listing installed roles to verify the installation: ansible-galaxy list. They may ask you to confirm that a role is present.
Removing a role: ansible-galaxy remove geerlingguy.nginx. If you try to remove a role that is not installed, the command will fail silently (it will not error, but it will say nothing). This is a trap: you must parse the command's output carefully.
Using the --roles-path option to install roles into a non-default directory. For example: ansible-galaxy install geerlingguy.nginx --roles-path /home/student/roles. The exam environment often sets a custom roles path, and you must use the --roles-path flag to target that directory.
Creating and using a requirements.yml file (also valid with .yaml extension). This file contains a list of roles to install. The exam might give you a file with three roles and ask you to install them all with one command: ansible-galaxy install -r requirements.yml. You must know that the roles are listed under a roles: key in the YAML file.
Pinning roles to specific versions in requirements.yml. Example format:
- - src: geerlingguy.nginx
version: 3.0.0
The exam often includes a version property that you must preserve exactly.
Common traps on the exam:
Confusing ansible-galaxy with ansible-playbook. The galaxy command manages roles; the playbook command runs them. If you type ansible-playbook install geerlingguy.nginx, it will fail with a 'no such option' error.
Forgetting to include the colon in a requirements.yml entry under roles:. The syntax is roles:, not roles.
Installing a role without the --force flag when it already exists. Without --force, the install command will skip the role and not update it. If the exam asks you to install the latest version of an already-installed role, you must add --force.
Using the wrong role name format. Role names from Galaxy always include the author's namespace, like geerlingguy.nginx or robertdebock.redis. Omitting the namespace causes a 'role not found' error.
Mistaking the server URL. The exam uses a mirrored instance of Galaxy at a URL they will provide (usually http://galaxy.example.com). You must use the --server flag if the default server is incorrect.
Key definitions to memorise:
Role: A self-contained unit of automation that includes tasks, handlers, variables, templates, and files, all organised in a standard directory structure.
Galaxy: The public repository and command-line tool for discovering and distributing Ansible roles.
requirements.yml: A YAML file that declares a list of roles with optional version specifications, used to install multiple roles at once.
Namespace: The author's identifier on Galaxy (e.g., 'geerlingguy' in 'geerlingguy.nginx').
src: The source of the role, usually the namespace.role_name string on Galaxy.
version: The specific release tag or branch of the role to install (e.g., '3.0.0').
scm: Source control manager (e.g., git), optionally specified if the role is from a Git repository rather than Galaxy.
The exam expects you to be fluent with these commands without looking at man pages. Practise each one at least five times in your study environment until the syntax is muscle memory.
Ansible Galaxy is a public repository of pre-written roles that you download and install locally using the ansible-galaxy command.
The command `ansible-galaxy install geerlingguy.nginx,v3.0.0` installs a specific version of the nginx role from Galaxy, using a comma (not an equals sign) before the version.
Use `ansible-galaxy list` to see all roles installed on your control node and `ansible-galaxy remove rolename` to delete one.
The `--roles-path` flag lets you install roles into a custom directory instead of the default ~/.ansible/roles.
A requirements.yml file installed with `ansible-galaxy install -r requirements.yml` lets you install multiple roles and pin their versions together.
Roles are not auto-updated; you must run `ansible-galaxy install --force` to get the latest version of an already-installed role.
The `ansible-galaxy` command only manages roles on the control node — it does not copy roles to managed servers automatically.
In a playbook, you reference a role by its simple name under the `roles:` key, and Ansible finds it in the roles_path directory.
These come up on the exam all the time. Here's how to tell them apart.
ansible-galaxy install
Downloads roles to the control node
Manages local role storage
Does not execute any tasks on remote servers
ansible-playbook
Executes tasks on remote managed servers
Reads playbooks and roles from the control node
Does not download or install any new content
Role (downloaded via Galaxy)
Created and maintained by the community
Updates are published by the original author
Can be installed with a single command
Role (written manually)
Created by you or your team
Updates require manual editing of files
Must be written, tested, and stored locally
Default roles_path (~/.ansible/roles)
Located in the user's home directory
Not shared among multiple users by default
Does not require root permissions to write
Custom roles_path (e.g., /etc/ansible/roles)
Located in a system-wide directory
Accessible to all users and CI/CD pipelines
Requires root or sudo permissions to write
requirements.yml with src and version
Installs multiple roles at once
Versions are pinned in a reusable file
File can be committed to version control
Inline install with version on command line
Installs one role at a time
Version specified only for that run
No trace of the version after the command completes
Mistake
Ansible Galaxy only works with roles publicly hosted on galaxy.ansible.com.
Correct
Ansible Galaxy can install roles from private Git repositories, tarballs, and local directories by specifying the source in requirements.yml or using the --server flag to point to a private automation hub.
Beginners assume Galaxy is only the public website because the official documentation mostly shows public examples. The exam tests private repos.
Mistake
Once you install a role with ansible-galaxy install, it is automatically updated every time you run a playbook.
Correct
Roles are downloaded once and remain unchanged until you explicitly run ansible-galaxy install with the --force flag or remove and reinstall them.
This confusion comes from comparing roles to package managers like apt that auto-update. Ansible intentionally avoids auto-updating to prevent breaking changes in production.
Mistake
You must write the role's version number with an '=' sign, like 'geerlingguy.nginx=3.0.0'.
Correct
The correct syntax uses a comma: 'geerlingguy.nginx,v3.0.0'. The equals sign is invalid and will cause an error.
Many beginners are accustomed to environment variable assignments (VAR=value) and mistakenly apply that pattern to the ansible-galaxy install command.
Mistake
The ansible-galaxy list command shows roles installed on the remote managed nodes, not on the control node.
Correct
ansible-galaxy list shows roles that are installed locally on the control node (the machine where you run Ansible commands), not on the managed servers.
The word 'list' sounds like it queries servers, but the galaxy tool only manages local role storage. Beginners conflate it with the ansible command that actually talks to remote nodes.
Mistake
You cannot install roles without an internet connection because Galaxy is an online service.
Correct
You can install roles from a local tarball, a filesystem path, or a private Git server using the src field in requirements.yml. Galaxy has an offline install mode.
The 'public repository' branding makes beginners think internet access is mandatory. The exam environment is often offline, so they test local install methods.
Reveal each answer, then mark whether you got it right. Score 60%+ to unlock the next chapter.
Use `ansible-galaxy install geerlingguy.nginx,v3.0.0`. The version comes after a comma, with no spaces. If you omit the version, you get the latest release.
`ansible-galaxy` manages roles — it downloads, lists, and removes them from the control node. `ansible-playbook` runs playbooks that use those roles against managed servers. They are separate tools for different jobs.
Ansible does not overwrite existing roles by default. Add `--force` to the install command to force an update to the latest or specified version.
They are stored in `~/.ansible/roles` (your home directory's .ansible folder). You can change this by setting `roles_path` in ansible.cfg or using the `--roles-path` flag.
Yes, if you have the role's tarball or a local Git repository. Use the `src` field in requirements.yml pointing to a file:// or git:// URL instead of a Galaxy namespace.
Create a requirements.yml file listing the roles under a `roles:` key, then run `ansible-galaxy install -r requirements.yml`. Each role entry can include `src`, `version`, and optional `scm`.
The playbook will fail with an error saying the role was not found when you try to run it. You must reinstall the role or remove the reference from the playbook.
You've finished Using Ansible Galaxy for Role Management. Continue through the EX294 study guide to build a complete picture of the exam.
Done with this chapter?