Skills DirectorySkills Directory
SkillsLearnSecurityCategoriesDocsBlogPro
Sign InSubmit Skill
Skills Directory

Security-tested agent skills for Claude, coding agents, and AI workflows.

Directory

  • Browse Skills
  • All Skills A–Z
  • Claude Skills
  • Claude Code Skills
  • Agent Skills
  • Categories
  • Authors
  • Submit a Skill

Learn

  • Learn Hub
  • Install Claude Skills
  • Write SKILL.md
  • Skills vs MCP
  • Directories Compared

Security

  • Security
  • Methodology
  • Secure Claude Skills
  • Security Badges
  • Chrome Extension
  • Skill Manager

Company

  • About
  • Community
  • Blog
  • API Docs
  • Advertise

2026 Skills Directory. All rights reserved.

ProTermsPrivacyRefunds
Back to skills

Role Builder

ASecurity

Creates Ansible roles with proper structure, tasks, handlers, and variables. Use when creating Ansible roles, organizing automation tasks, or structuring configuration management.

29 stars
0 votes
0 copies
7 views
Added 12/21/2025
devopspythongobashgitdocumentation

Security Analysis

A100/100

Pro scans all 4 files and shows the line behind each finding

Scanned 2/12/2026

$npx -y skills add armanzeroeight/fastagent-plugins --skill role-builder --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Role Builder?

Add the live security badge to your README — it updates automatically with every re-scan.

Security grade badge for Role Builder
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/armanzeroeight-role-builder/badge)](https://www.skillsdirectory.com/skills/armanzeroeight-role-builder)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
Files
SKILL.md
---
name: role-builder
description: Creates Ansible roles with proper structure, tasks, handlers, and variables. Use when creating Ansible roles, organizing automation tasks, or structuring configuration management.
---

# Role Builder

## Quick Start

Create well-structured Ansible roles with proper organization, reusability, and idempotency.

## Instructions

### Step 1: Initialize role structure

```bash
# Create role using ansible-galaxy
ansible-galaxy init my_role

# Or create manually
mkdir -p roles/my_role/{tasks,handlers,templates,files,vars,defaults,meta}
```

**Standard role structure:**
```
my_role/
├── tasks/
│   └── main.yml          # Main task list
├── handlers/
│   └── main.yml          # Handlers
├── templates/
│   └── config.j2         # Jinja2 templates
├── files/
│   └── script.sh         # Static files
├── vars/
│   └── main.yml          # Role variables
├── defaults/
│   └── main.yml          # Default variables
├── meta/
│   └── main.yml          # Role metadata and dependencies
└── README.md             # Role documentation
```

### Step 2: Define tasks

**tasks/main.yml:**
```yaml
---
# Main task file for my_role

- name: Install required packages
  ansible.builtin.package:
    name: "{{ item }}"
    state: present
  loop: "{{ required_packages }}"
  tags: [packages]

- name: Create application directory
  ansible.builtin.file:
    path: "{{ app_directory }}"
    state: directory
    owner: "{{ app_user }}"
    group: "{{ app_group }}"
    mode: '0755'
  tags: [setup]

- name: Deploy configuration file
  ansible.builtin.template:
    src: config.j2
    dest: "{{ app_directory }}/config.yml"
    owner: "{{ app_user }}"
    group: "{{ app_group }}"
    mode: '0644'
  notify: restart application
  tags: [config]

- name: Ensure service is running
  ansible.builtin.service:
    name: "{{ service_name }}"
    state: started
    enabled: true
  tags: [service]
```

### Step 3: Create handlers

**handlers/main.yml:**
```yaml
---
# Handlers for my_role

- name: restart application
  ansible.builtin.service:
    name: "{{ service_name }}"
    state: restarted

- name: reload application
  ansible.builtin.service:
    name: "{{ service_name }}"
    state: reloaded

- name: validate configuration
  ansible.builtin.command:
    cmd: "{{ app_binary }} --validate-config"
  changed_when: false
```

### Step 4: Define variables

**defaults/main.yml (default values):**
```yaml
---
# Default variables for my_role

app_user: appuser
app_group: appgroup
app_directory: /opt/myapp
service_name: myapp

required_packages:
  - python3
  - python3-pip
  - git
```

**vars/main.yml (role-specific variables):**
```yaml
---
# Role-specific variables

app_binary: /usr/local/bin/myapp
config_template: config.j2
```

### Step 5: Add metadata

**meta/main.yml:**
```yaml
---
galaxy_info:
  author: Your Name
  description: Role for deploying my application
  company: Your Company
  license: MIT
  min_ansible_version: '2.9'
  
  platforms:
    - name: Ubuntu
      versions:
        - focal
        - jammy
    - name: EL
      versions:
        - '8'
        - '9'
  
  galaxy_tags:
    - application
    - deployment

dependencies:
  - role: common
    vars:
      common_packages:
        - curl
        - wget
```

## Role Design Patterns

### Pattern 1: Modular tasks

**Break tasks into separate files:**
```yaml
# tasks/main.yml
---
- name: Include installation tasks
  ansible.builtin.include_tasks: install.yml
  tags: [install]

- name: Include configuration tasks
  ansible.builtin.include_tasks: configure.yml
  tags: [configure]

- name: Include service tasks
  ansible.builtin.include_tasks: service.yml
  tags: [service]
```

### Pattern 2: Conditional execution

```yaml
- name: Install on Debian-based systems
  ansible.builtin.apt:
    name: "{{ package_name }}"
    state: present
  when: ansible_os_family == "Debian"

- name: Install on RedHat-based systems
  ansible.builtin.yum:
    name: "{{ package_name }}"
    state: present
  when: ansible_os_family == "RedHat"
```

### Pattern 3: Idempotent operations

```yaml
- name: Ensure configuration is present
  ansible.builtin.lineinfile:
    path: /etc/myapp/config
    line: "{{ config_line }}"
    state: present
    create: true
  # Idempotent - only changes if line is missing

- name: Ensure service is running
  ansible.builtin.service:
    name: myapp
    state: started
  # Idempotent - only starts if not running
```

## Best Practices

**Use fully qualified collection names:**
```yaml
# Good
- name: Install package
  ansible.builtin.package:
    name: nginx

# Avoid
- name: Install package
  package:
    name: nginx
```

**Add descriptive names:**
```yaml
# Good
- name: Install nginx web server
  ansible.builtin.package:
    name: nginx

# Avoid
- name: Install
  ansible.builtin.package:
    name: nginx
```

**Use tags for selective execution:**
```yaml
- name: Install packages
  ansible.builtin.package:
    name: "{{ item }}"
  loop: "{{ packages }}"
  tags: [packages, install]

- name: Configure application
  ansible.builtin.template:
    src: config.j2
    dest: /etc/app/config
  tags: [config, configure]
```

**Implement error handling:**
```yaml
- name: Attempt risky operation
  ansible.builtin.command:
    cmd: /usr/local/bin/risky-command
  register: result
  failed_when: false
  changed_when: result.rc == 0
  tags: [risky]

- name: Handle failure
  ansible.builtin.debug:
    msg: "Operation failed, continuing anyway"
  when: result.rc != 0
```

## Advanced

For detailed information, see:
- [Role Structure](reference/role-structure.md) - Complete role directory layout and organization
- [Handlers](reference/handlers.md) - Handler patterns and best practices
- [Variables](reference/variables.md) - Variable precedence and management

Attribution

armanzeroeightarmanzeroeight
View sourceSee grades on GitHubMore from armanzeroeight →
SSkills DirectorySkills Directory

Ship a skill? Prove it's safe.

Free 120-pattern security scan, letter grade, and an embeddable README badge.

Submit a skill

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments (0)

No comments yet. Be the first to comment!

SSkills DirectorySkills Directory

Ship a skill? Prove it's safe.

Free 120-pattern security scan, letter grade, and an embeddable README badge.

Submit a skill

Related Skills

Terraform Module Library

Build reusable Terraform modules for AWS, Azure, and GCP infrastructure following infrastructure-as-code best practices. Use when creating infrastructure modules, standardizing cloud provisioning, or implementing reusable IaC components.

401991 votes

sematext-otel

Wire a service's OpenTelemetry output to Sematext Cloud. Walks through region, App-type, instrumentation flow (managed OTLP endpoint vs Sematext Agent), and signal selection (traces/metrics/logs), then produces the exact env-var block and points at a runnable reference example in this repo. Invoke when instrumenting a new app for Sematext.

01 votes

Deployment Patterns

Deployment workflows, CI/CD pipeline patterns, Docker containerization, health checks, rollback strategies, and production readiness checklists for web applications. Use when setting up deployment infrastructure or planning releases.

2699140 votes

Babysit

Watch a pull request or review cycle until it is ready to merge. Use when asked to babysit, monitor, or keep checking PR comments, reviews, and CI until all actionable issues are resolved.

971540 votes

V7 Roster

Interact with the Paperclip control plane API for task coordination and governance. Use when checking assignments, updating issue status, posting comments, delegating work, managing routines, or calling Paperclip API endpoints.

953190 votes
View all in devops →