commit bd8471b8c0608bcb46c08c33100999c073cf6a92 Author: Zhongwei Li Date: Sun Nov 30 08:18:54 2025 +0800 Initial commit diff --git a/.claude-plugin/plugin.json b/.claude-plugin/plugin.json new file mode 100644 index 0000000..8fb55fb --- /dev/null +++ b/.claude-plugin/plugin.json @@ -0,0 +1,15 @@ +{ + "name": "ansible-playbook-creator", + "description": "Create Ansible playbooks for configuration management", + "version": "1.0.0", + "author": { + "name": "Claude Code Plugins", + "email": "[email protected]" + }, + "skills": [ + "./skills" + ], + "commands": [ + "./commands" + ] +} \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..1583f38 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# ansible-playbook-creator + +Create Ansible playbooks for configuration management diff --git a/commands/ansible-playbook.md b/commands/ansible-playbook.md new file mode 100644 index 0000000..31f5ee9 --- /dev/null +++ b/commands/ansible-playbook.md @@ -0,0 +1,25 @@ +--- +description: $(echo "$description" | cut -d' ' -f1-5) +--- + +# $(echo "$name" | sed 's/-/ /g' | sed 's/\b\(.\)/\u\1/g') + +$(echo "$description") + +## Key Features + +- Production-ready configurations +- Best practices implementation +- Security-first approach +- Scalable architecture +- Comprehensive documentation +- Multi-platform support + +## Example Usage + +This plugin generates complete configurations for your DevOps needs. +Specify your requirements and get production-ready code instantly. + +## When Invoked + +Generate configurations and setup code based on your specific requirements and infrastructure needs. diff --git a/plugin.lock.json b/plugin.lock.json new file mode 100644 index 0000000..2f6cf6a --- /dev/null +++ b/plugin.lock.json @@ -0,0 +1,69 @@ +{ + "$schema": "internal://schemas/plugin.lock.v1.json", + "pluginId": "gh:jeremylongshore/claude-code-plugins-plus:plugins/devops/ansible-playbook-creator", + "normalized": { + "repo": null, + "ref": "refs/tags/v20251128.0", + "commit": "d9246a6f2a79b1f5ea8fa91caf3f909d0a25edbb", + "treeHash": "a3ac74ea700b88a490f8887c1396a7e5a1f3834680dfa8e090d0af5583536453", + "generatedAt": "2025-11-28T10:18:04.677349Z", + "toolVersion": "publish_plugins.py@0.2.0" + }, + "origin": { + "remote": "git@github.com:zhongweili/42plugin-data.git", + "branch": "master", + "commit": "aa1497ed0949fd50e99e70d6324a29c5b34f9390", + "repoRoot": "/Users/zhongweili/projects/openmind/42plugin-data" + }, + "manifest": { + "name": "ansible-playbook-creator", + "description": "Create Ansible playbooks for configuration management", + "version": "1.0.0" + }, + "content": { + "files": [ + { + "path": "README.md", + "sha256": "0227216c342e63d8811d23daa0fae833bb3b51ab5cbd0c7f926245939e3d5971" + }, + { + "path": ".claude-plugin/plugin.json", + "sha256": "fe24f9e8690ed3082d1de1000f61992c79231da47616de14f98bdd1c186e6e23" + }, + { + "path": "commands/ansible-playbook.md", + "sha256": "353f80054a90cda1e6716da3628115ce829307fbbb83a15b64f1d37c96224a99" + }, + { + "path": "skills/ansible-playbook-creator/SKILL.md", + "sha256": "d8951e1da7f65e93060b1722efe619be31b4a828ca2ac36900ef92d8f0552fb5" + }, + { + "path": "skills/ansible-playbook-creator/references/README.md", + "sha256": "92e5fcf89ba18488e9e5746fb4c1ee91f62877434275ee39f2609494dfda068e" + }, + { + "path": "skills/ansible-playbook-creator/scripts/README.md", + "sha256": "90ebaf71ef820c9a797e47c25ef43e383c4064caa590068074e546ce5e44dcc8" + }, + { + "path": "skills/ansible-playbook-creator/assets/playbook_template.yml", + "sha256": "be180b18aa4d5271d751bc2d57533b4785827bbddd774f2deb5098a597c57013" + }, + { + "path": "skills/ansible-playbook-creator/assets/validation_rules.yml", + "sha256": "f8a6402f0ce87c455173c4645aadbc2868d23ed41f192eeb4ec67fb40030e233" + }, + { + "path": "skills/ansible-playbook-creator/assets/README.md", + "sha256": "e7d804b544622d345698bfef44fa0d3f9185a39f4591a9e5a1ca2336c55d6b0d" + } + ], + "dirSha256": "a3ac74ea700b88a490f8887c1396a7e5a1f3834680dfa8e090d0af5583536453" + }, + "security": { + "scannedAt": null, + "scannerVersion": null, + "flags": [] + } +} \ No newline at end of file diff --git a/skills/ansible-playbook-creator/SKILL.md b/skills/ansible-playbook-creator/SKILL.md new file mode 100644 index 0000000..4e0123c --- /dev/null +++ b/skills/ansible-playbook-creator/SKILL.md @@ -0,0 +1,52 @@ +--- +name: creating-ansible-playbooks +description: | + This skill creates Ansible playbooks for automating configuration management tasks. It generates production-ready, multi-platform playbooks based on user-defined requirements, incorporating best practices and a security-first approach. Use this skill when you need to automate server configurations, software deployments, or infrastructure management using Ansible. Trigger this skill by requesting "Ansible playbook," specifying configuration details, or asking for automation of a particular setup. +allowed-tools: Read, Write, Edit, Grep, Glob, Bash +version: 1.0.0 +--- + +## Overview + +This skill empowers Claude to generate Ansible playbooks, streamlining infrastructure automation. It takes your specifications and translates them into executable Ansible code, allowing for repeatable and reliable deployments. + +## How It Works + +1. **Receiving User Request**: Claude receives the user's request for an Ansible playbook, including details about the desired configuration. +2. **Generating Playbook**: Based on the user's input, Claude utilizes the `ansible-playbook-creator` plugin to generate a complete Ansible playbook. +3. **Presenting the Playbook**: Claude presents the generated Ansible playbook to the user for review and execution. + +## When to Use This Skill + +This skill activates when you need to: +- Automate server configuration management tasks. +- Deploy applications across multiple servers consistently. +- Create repeatable and reliable infrastructure setups. + +## Examples + +### Example 1: Setting up a web server + +User request: "Create an Ansible playbook to install and configure Apache on Ubuntu servers." + +The skill will: +1. Generate an Ansible playbook that installs the Apache web server and configures it with a default virtual host. +2. Present the playbook to the user, ready for execution against Ubuntu servers. + +### Example 2: Deploying a Docker container + +User request: "Generate an Ansible playbook to deploy a Docker container running Nginx on CentOS servers." + +The skill will: +1. Generate an Ansible playbook that installs Docker, pulls the Nginx image, and runs it as a container on CentOS servers. +2. Provide the playbook to the user for immediate deployment. + +## Best Practices + +- **Specificity**: Provide detailed requirements for the desired configuration to generate accurate playbooks. +- **Security**: Review the generated playbooks for security best practices before deploying them in production. +- **Testing**: Always test generated playbooks in a staging environment before applying them to production servers. + +## Integration + +This skill integrates with Claude's core capabilities by providing a specialized tool for Ansible playbook creation. It enhances Claude's ability to assist with DevOps tasks and infrastructure automation. \ No newline at end of file diff --git a/skills/ansible-playbook-creator/assets/README.md b/skills/ansible-playbook-creator/assets/README.md new file mode 100644 index 0000000..65b8935 --- /dev/null +++ b/skills/ansible-playbook-creator/assets/README.md @@ -0,0 +1,7 @@ +# Assets + +Bundled resources for ansible-playbook-creator skill + +- [ ] playbook_template.yml: A basic template for Ansible playbooks, including common sections and best practice configurations. +- [ ] example_playbooks/: A directory containing example playbooks for various use cases, such as installing software, configuring firewalls, and managing users. +- [ ] validation_rules.yml: A set of rules for validating the generated playbooks, ensuring they adhere to best practices and security standards. diff --git a/skills/ansible-playbook-creator/assets/playbook_template.yml b/skills/ansible-playbook-creator/assets/playbook_template.yml new file mode 100644 index 0000000..4e85705 --- /dev/null +++ b/skills/ansible-playbook-creator/assets/playbook_template.yml @@ -0,0 +1,75 @@ +--- +# Ansible Playbook Template +# This template provides a starting point for creating Ansible playbooks. +# It includes common sections and best practice configurations. + +- name: "REPLACE_ME - Playbook Description" + hosts: all # Target hosts or groups (e.g., webservers, dbservers) + become: true # Enable privilege escalation (sudo) + become_user: root # Specify the user to become (optional, defaults to root) + gather_facts: true # Gather facts about the target hosts + + # Define variables that can be used throughout the playbook + vars: + # Example variables + app_name: "YOUR_APP_NAME" + app_version: "1.0.0" + install_dir: "/opt/{{ app_name }}" + # Add more variables as needed + + # Pre-tasks: Tasks that run before any roles are applied + pre_tasks: + - name: "Update apt cache (Debian/Ubuntu)" + apt: + update_cache: yes + when: ansible_os_family == "Debian" + + - name: "Update yum cache (RedHat/CentOS)" + yum: + update_cache: yes + when: ansible_os_family == "RedHat" + + # Roles: Group of tasks to perform a specific function + roles: + - role: common # Example role for common configurations + # vars: # Role-specific variables (optional) + # some_var: "YOUR_VALUE_HERE" + + # Add more roles as needed (e.g., webserver, database) + # - role: webserver + + # Tasks: Individual steps to be executed + tasks: + - name: "Create installation directory" + file: + path: "{{ install_dir }}" + state: directory + owner: root + group: root + mode: "0755" + + - name: "Copy application files" + copy: + src: "files/{{ app_name }}" # Path to application files on the control node + dest: "{{ install_dir }}" + owner: root + group: root + mode: "0644" + + # Add more tasks as needed + + # Post-tasks: Tasks that run after all roles and tasks have been applied + post_tasks: + - name: "Restart application service" + service: + name: "{{ app_name }}" + state: restarted + ignore_errors: true # Allows the playbook to continue even if the service restart fails + + # Handlers: Tasks that are triggered by other tasks + handlers: + - name: "Restart web server" + service: + name: apache2 + state: restarted + listen: "Restart web server" # Triggered by tasks that notify "Restart web server" \ No newline at end of file diff --git a/skills/ansible-playbook-creator/assets/validation_rules.yml b/skills/ansible-playbook-creator/assets/validation_rules.yml new file mode 100644 index 0000000..50feb88 --- /dev/null +++ b/skills/ansible-playbook-creator/assets/validation_rules.yml @@ -0,0 +1,94 @@ +# validation_rules.yml + +# --- General Playbook Structure Rules --- +playbook_structure: + # Rule: Playbook must have a name + name_required: true + # Rule: Playbook must have at least one host + hosts_required: true + # Rule: Playbook should have a gather_facts setting (explicitly true or false) + gather_facts_required: true + gather_facts_default: true # Consider setting to false if facts are not needed for performance + # Rule: Playbook should have a become setting (explicitly true or false) if privilege escalation is needed + become_recommended: true # Recommend setting this, but don't enforce. + become_default: false # Set to true if most tasks require sudo. + +# --- Task Specific Rules --- +task_rules: + # Rule: Each task must have a name + name_required: true + # Rule: Avoid using the 'shell' module unless necessary. Prefer specific modules. + no_shell_unless_necessary: true + shell_exceptions: # List of commands where shell is acceptable. Helps reduce false positives. + - "ls" + - "grep" + - "awk" + - "sed" + # Rule: Use 'changed_when' instead of relying on return codes for idempotency. + changed_when_recommended: true + # Rule: Use 'failed_when' to handle unexpected errors. + failed_when_recommended: true + +# --- Security Best Practices --- +security_rules: + # Rule: Avoid storing secrets directly in playbooks. Use Ansible Vault or a secrets management system. + no_plain_text_secrets: true + secret_keywords: # List of keywords that indicate a potential secret + - "password" + - "secret" + - "token" + - "key" + # Rule: Use 'become' with caution. Limit its scope to only the tasks that require it. + become_caution: true + # Rule: Avoid using '*' in host patterns in production. Be specific. + no_wildcard_hosts: true + # Rule: Validate input parameters to prevent injection vulnerabilities. + validate_input: true + input_validation_regex: "REPLACE_ME" # Example regex for validating input. Should be customized per variable. + +# --- Idempotency Rules --- +idempotency_rules: + # Rule: Ensure tasks are idempotent. They should only make changes when necessary. + idempotent_tasks: true + # Rule: Use 'creates' or 'removes' in file/copy/template modules for idempotency. + file_idempotency: true + # Rule: Use 'state' parameter where applicable (e.g., present/absent for files/packages). + state_parameter_required: true + state_parameter_exceptions: # Some modules don't use state, so exclude them + - "debug" + - "include_tasks" + - "include_role" + +# --- Error Handling Rules --- +error_handling_rules: + # Rule: Implement proper error handling using 'rescue' and 'always' blocks. + rescue_blocks_recommended: true + always_blocks_recommended: true + # Rule: Use 'ignore_errors' with caution. Document why it is necessary. + ignore_errors_caution: true + +# --- Variable Usage Rules --- +variable_rules: + # Rule: Use descriptive variable names. + descriptive_variable_names: true + # Rule: Define variables in a structured way (e.g., group_vars, host_vars). + structured_variables: true + # Rule: Avoid using hardcoded values directly in tasks. Use variables instead. + no_hardcoded_values: true + +# --- Module Specific Rules (Example for apt module) --- +apt_module_rules: + # Rule: Ensure 'update_cache' is set to 'yes' when installing packages for the first time. + update_cache_recommended: true + # Rule: Specify a state (present/absent) when managing packages. + state_required: true + default_package: "YOUR_VALUE_HERE" # Example default package + +# --- Platform Specific Rules --- +platform_rules: + # Rule: Use conditional statements ('when') to handle platform-specific differences. + conditional_platform_tasks: true + supported_platforms: # List of supported platforms + - "Ubuntu" + - "CentOS" + - "Windows" \ No newline at end of file diff --git a/skills/ansible-playbook-creator/references/README.md b/skills/ansible-playbook-creator/references/README.md new file mode 100644 index 0000000..a8dc10a --- /dev/null +++ b/skills/ansible-playbook-creator/references/README.md @@ -0,0 +1,7 @@ +# References + +Bundled resources for ansible-playbook-creator skill + +- [ ] ansible_best_practices.md: Comprehensive guide on Ansible best practices, including idempotency, variable usage, and error handling. +- [ ] security_hardening_guide.md: Detailed instructions on security hardening techniques for Ansible playbooks, such as using Ansible Vault and avoiding hardcoded credentials. +- [ ] multi_platform_compatibility.md: Guidelines for creating playbooks that are compatible with multiple operating systems and platforms. diff --git a/skills/ansible-playbook-creator/scripts/README.md b/skills/ansible-playbook-creator/scripts/README.md new file mode 100644 index 0000000..9f98958 --- /dev/null +++ b/skills/ansible-playbook-creator/scripts/README.md @@ -0,0 +1,7 @@ +# Scripts + +Bundled resources for ansible-playbook-creator skill + +- [ ] validate_playbook.py: Validates the generated playbook syntax and structure using ansible-lint or similar tools. +- [ ] test_playbook.sh: Executes the generated playbook in a test environment (e.g., a container) to verify its functionality. +- [ ] secure_playbook.py: Scans the playbook for security vulnerabilities and suggests remediations based on best practices.