Publish and consume roles from Ansible Galaxy
✓Works with OpenClaudeYou are an Ansible automation engineer. The user wants to publish custom Ansible roles to Ansible Galaxy and consume existing roles from Galaxy in their playbooks.
What to check first
- Run
ansible --versionto confirm Ansible is installed - Run
ansible-galaxy --versionto verify galaxy CLI is available - Check that you have an Ansible Galaxy account at https://galaxy.ansible.com with an API token generated
Steps
- Create a properly structured Ansible role directory using
ansible-galaxy init my_role— this generates the required meta/, tasks/, handlers/, templates/, vars/, and defaults/ subdirectories - Edit
meta/main.ymlin your role with accurate metadata:galaxy_infoblock with namespace, name, description, license, min_ansible_version, and supported platforms - Populate
tasks/main.ymlwith your role's actual tasks,defaults/main.ymlwith variable defaults, andhandlers/main.ymlwith handlers - Create a
.gitignorein the role root excluding common files, then initialize git:git initand commit your code - Push the repository to GitHub (or your git host) with the naming convention
ansible-role-{rolename} - Set your Galaxy API token in
~/.ansible/galaxyor via environment variableANSIBLE_GALAXY_TOKEN - Run
ansible-galaxy role publish --api-key [token]from inside your role directory to publish to Galaxy - To consume a Galaxy role, add it to a
requirements.ymlfile withcollections:orroles:sections, then runansible-galaxy install -r requirements.ymlbefore running playbooks
Code
# meta/main.yml - Required metadata for Galaxy publication
---
galaxy_info:
author: "Your Name"
description: "Brief description of what this role does"
company: "Optional Company Name"
license: "MIT"
min_ansible_version: "2.9"
platforms:
- name: "EL"
versions:
- "8"
- "9"
- name: "Ubuntu"
versions:
- "20.04"
- "22.04"
galaxy_tags:
- "web"
- "nginx"
- "deploy"
# tasks/main.yml - Core role tasks
---
- name: "Install nginx package"
ansible.builtin.package:
name: "nginx"
state: "present"
- name: "Deploy nginx config template"
ansible.builtin.template:
src: "nginx.conf.j2"
dest: "/etc/nginx/nginx.conf"
backup: true
owner: "root"
group: "root"
mode: "0644"
notify: "Restart nginx"
- name: "Ensure nginx service is enabled and running"
ansible.builtin.service:
name: "nginx"
enabled: true
state
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related Ansible Skills
Other Claude Code skills in the same category — free to download.
Ansible Playbook
Write Ansible playbooks for server configuration
Ansible Role
Create reusable Ansible roles with defaults and handlers
Ansible Vault
Manage secrets with Ansible Vault encryption
Ansible Inventory
Configure dynamic inventory for cloud providers
Ansible Testing
Test Ansible roles with Molecule and Testinfra
Ansible Idempotent Playbook
Write Ansible playbooks that can run repeatedly without causing changes when nothing needs to change
Ansible Vault for Secrets
Encrypt sensitive data in Ansible playbooks with Ansible Vault
Want a Ansible skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.