/ansible:ansible-rolesfrom ansible
Guides creation and consumption of Ansible roles, including directory structure, role metadata, Jinja2 templates, and Galaxy collections.
Ships in ansible. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Activate when creating reusable role structures, using import_role: or include_role:, writing Jinja2 templates, or working with Ansible Galaxy collections and roles.
This skill follows core:anti-fabrication. The claim area is role directory conventions,
meta/main.yml fields, and the Jinja2 filters used in role templates. Verified against
ansible-core 2.21.2 (pipx-installed live, claude-skills-223): the default() filter's
boolean-argument semantics and flatten's default-level behavior were both found
backwards from what the skill documented and corrected — this is exactly the kind of
inverted claim a docs-only read misses. The role directory layout itself is stable
Ansible convention, low risk. ansible-galaxy hub-doc conventions (requirements.yml,
collection installs) were last checked 2026-05-06, not re-verified this pass — treat
those as lower-confidence than the filter/role corrections above.
A role is a self-contained directory of tasks, handlers, variables, templates, and files organized for reuse. Instead of copying tasks between playbooks, extract them into a role and apply the role wherever needed.
Roles enforce a consistent directory layout that Ansible recognizes automatically.
roles/
└── my_role/
├── tasks/
│ └── main.yml # entry point — required
├── handlers/
│ └── main.yml # handlers (notified by tasks)
├── defaults/
│ └── main.yml # default variables (lowest precedence)
├── vars/
│ └── main.yml # role variables (higher precedence than defaults)
├── files/
│ └── app.conf # static files (copy: module)
├── templates/
│ └── nginx.conf.j2 # Jinja2 templates (template: module)
├── meta/
│ └── main.yml # role metadata and dependencies
└── tests/
├── inventory
└── test.yml # simple smoke test playbook
Scaffold a new role:
ansible-galaxy role init my_role
| Location | Precedence | Purpose |
|---|---|---|
defaults/main.yml | Lowest — easily overridden | User-facing knobs with sensible fallbacks |
vars/main.yml | Higher — harder to override | Internal role constants |
# defaults/main.yml
nginx_port: 80
nginx_worker_processes: auto
nginx_log_level: warn
# vars/main.yml
nginx_config_dir: /etc/nginx
nginx_pid_file: /var/run/nginx.pid
Set defaults for everything a consumer might want to change. Put implementation details in vars.
# Classic roles: block (static, resolved at parse time)
- hosts: webservers
roles:
- common
- role: nginx
vars:
nginx_port: 8080
# import_role (static — analyzed before execution)
- hosts: webservers
tasks:
- name: Apply base role
ansible.builtin.import_role:
name: common
# include_role (dynamic — resolved at runtime, supports when:/loop:)
- hosts: webservers
tasks:
- name: Apply role conditionally
ansible.builtin.include_role:
name: nginx
when: install_nginx | bool
loop: "{{ nginx_sites }}"
loop_control:
loop_var: nginx_site
Use import_role when you need tags to propagate; use include_role when you need conditionals or loops on the role itself.
Declare roles that must run before this role in meta/main.yml:
# roles/app/meta/main.yml
galaxy_info:
author: rginnow
description: Deploy the application
license: MIT
min_ansible_version: "2.14"
dependencies:
- role: common
- role: nginx
vars:
nginx_port: 8080
Dependencies run first, in order. Ansible deduplicates them — a dependency listed by multiple roles only runs once per play.
Use the template: module to render Jinja2 templates from templates/ onto managed nodes.
- name: Write nginx config
ansible.builtin.template:
src: nginx.conf.j2 # relative to templates/ — Ansible finds it
dest: /etc/nginx/nginx.conf
owner: root
group: root
mode: "0644"
notify: Reload nginx
Template syntax:
{# nginx.conf.j2 #}
worker_processes {{ nginx_worker_processes }};
pid {{ nginx_pid_file }};
events {
worker_connections {{ nginx_worker_connections | default(1024) }};
}
http {
server {
listen {{ nginx_port }};
server_name {{ ansible_fqdn }};
{% for location in nginx_locations %}
location {{ location.path }} {
proxy_pass {{ location.upstream }};
}
{% endfor %}
}
}
Key Jinja2 syntax:
{{ variable }} — output a value{% if condition %}...{% endif %} — conditional block{% for item in list %}...{% endfor %} — loop{# comment #} — template comment (not in output){{ value | filter }} — apply a filterCommon filters:
{{ my_list | join(', ') }} {# join list items #}
{{ name | upper }} {# uppercase #}
{{ path | basename }} {# filename from path #}
{{ value | default('fallback') }} {# fallback if undefined #}
{{ items | selectattr('active') }} {# filter objects by attribute #}
{{ count | int }} {# type conversion #}
Galaxy is the public hub for community roles and collections.
# Install a role
ansible-galaxy role install geerlingguy.nginx
# Install a collection (namespaced: namespace.collection)
ansible-galaxy collection install community.general
ansible-galaxy collection install amazon.aws
# Specify version
ansible-galaxy collection install community.general:==6.0.0
Pin dependencies in a requirements.yml file and install all at once:
# requirements.yml
roles:
- name: geerlingguy.nginx
version: "3.2.0"
- src: https://github.com/example/my-role
name: my_custom_role
collections:
- name: community.general
version: ">=6.0.0"
- name: amazon.aws
version: "6.5.0"
ansible-galaxy role install -r requirements.yml
ansible-galaxy collection install -r requirements.yml
# ansible.cfg
[defaults]
roles_path = roles:~/.ansible/roles:/usr/share/ansible/roles
Ansible searches each path in order when resolving role names.
What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub vinnie357/claude-skills --plugin ansible2 plugins in one repository ship this exact skill · first indexed Aug 7, 2026
5 skills in this plugin
/ansibleGuide for Ansible automation and configuration management. Use when writing playbooks, tasks, handlers, variables, conditionals, loops, or needing an overview of Ansible project structure and development workflows./ansible-inventoryGuide for Ansible inventory management. Use when configuring static or dynamic inventory files, defining host patterns, setting host and group variables, using group_vars and host_vars directories, or working with inventory plugins./ansible-testingGuide for testing Ansible roles and playbooks with Molecule. Use when writing Molecule test scenarios, configuring drivers (Docker, Podman, delegated), writing Testinfra or Ansible Verify tests, or integrating Molecule into CI pipelines./ansible-vaultGuide for Ansible Vault secrets management and security practices. Use when encrypting variables or files with ansible-vault, configuring vault passwords, using vault IDs, or applying security hardening to playbooks.Other plugins' skills for the same job