creating-ansible-playbooks
Execute use when you need to work with Ansible automation. This skill provides Ansible playbook creation with comprehensive guidance and automation. Trigger with phrases like "create Ansible playbook", "automate with Ansible", or "configure with Ansible".
- License 许可
- MIT
- 最近更新
- 2026-05-26
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- creating-ansible-playbooks
- author
- Jeremy Longshore <jeremy@intentsolutions.io>
- license
- MIT
- version
- 1.0.0
- description
- Execute use when you need to work with Ansible automation. This skill provides Ansible playbook creation with comprehensive guidance and automation. Trigger with phrases like "create Ansible playbook", "automate with Ansible", or "configure with Ansible".
- allowed-tools
- Read, Write, Edit, Grep, Glob, Bash(ansible:*), Bash(terraform:*)
- compatible-with
- claude-code, codex, openclaw
02 资源文件 8
- 资产文件assets/playbook_template.yml2.3 KB
- 资产文件assets/README.md501 B
- 资产文件assets/validation_rules.yml3.7 KB
- 参考文档references/README.md68 B
- 脚本scripts/README.md436 B
- 脚本scripts/secure_playbook.py11.3 KB
- 脚本scripts/test_playbook.sh8.7 KB
- 脚本scripts/validate_playbook.py10.6 KB
03 SKILL.md 正文
Creating Ansible Playbooks
Overview
Generate production-ready Ansible playbooks, roles, and inventories for infrastructure automation. Supports provisioning servers, deploying applications, configuring services, and enforcing desired state across fleets of machines using SSH-based agentless automation.
Prerequisites
- Ansible 2.14+ installed (
ansible --version) - SSH access to target hosts with key-based authentication
- Python 3.9+ on control node and managed nodes
- Inventory of target hosts (IPs or hostnames)
- Privilege escalation credentials (sudo) if configuring system-level resources
ansible-lintinstalled for playbook validation
Instructions
- Scan the project for existing Ansible files (
ansible.cfg,inventory/,roles/,group_vars/) to understand current structure - Determine the automation target: server provisioning, application deployment, configuration management, or security hardening
- Create the playbook YAML with proper structure:
hosts,become,vars,tasks,handlers - Extract reusable logic into roles using the standard directory layout (
tasks/,handlers/,templates/,defaults/,vars/,meta/) - Define variables in
group_vars/andhost_vars/for environment-specific values, keeping secrets invault-encrypted files - Use Jinja2 templates for configuration files that vary across environments
- Add handlers for service restarts triggered by configuration changes
- Validate the playbook with
ansible-lintandansible-playbook --check --diff(dry run) - Test idempotency by running the playbook twice and confirming no changes on the second run
Output
- Ansible playbooks (
.yml) with structured tasks, handlers, and variables - Role directories following Ansible Galaxy structure
- Jinja2 templates (
.j2) for dynamic configuration files - Inventory files (INI or YAML) with host groups
group_vars/andhost_vars/for environment separationansible.cfgwith connection and privilege escalation settings
Error Handling
| Error | Cause | Solution |
|---|---|---|
unreachable: Failed to connect to host |
SSH connection failure or wrong host/port | Verify SSH keys, host IPs, and that port 22 is open with ansible -m ping |
permission denied on become |
Missing or incorrect sudo password | Add --ask-become-pass or configure ansible_become_password in vault |
undefined variable |
Variable not defined in vars, defaults, or inventory | Check variable precedence; define in defaults/main.yml or group_vars/ |
ansible-lint: syntax-check failed |
YAML syntax error or deprecated module usage | Run ansible-lint -v and fix reported issues; replace deprecated modules |
changed on every run (not idempotent) |
Using command/shell without creates/removes guards |
Add creates: parameter or switch to purpose-built modules (copy, template, file) |
Examples
- "Create an Ansible playbook to provision an Ubuntu 22.04 server with Nginx, Certbot, and a firewall allowing only 80/443."
- "Generate a role that deploys a Python Flask app with Gunicorn, systemd service file, and log rotation."
- "Write an Ansible playbook to harden SSH config across all servers: disable root login, enforce key auth, set idle timeout."
Resources
- Ansible documentation: https://docs.ansible.com/ansible/latest/
- Ansible Galaxy roles: https://galaxy.ansible.com/
- Ansible Lint rules: https://ansible.readthedocs.io/projects/lint/rules/
- Best practices guide: https://docs.ansible.com/ansible/latest/tips_tricks/ansible_tips_tricks.html
04 同仓库更多 Skills
zustand-store-ts
Create Zustand stores with TypeScript, subscribeWithSelector middleware, and proper state/action separation. Use when building React state management, creating global stores, or implementing reactive state patterns with Zustand.
zustand-store-creator
Zustand Store Creator - Auto-activating skill for Frontend Development. Triggers on: zustand store creator, zustand store creator Part of the Frontend Development skill category.
zero-trust-config-helper
Zero Trust Config Helper - Auto-activating skill for Security Advanced. Triggers on: zero trust config helper, zero trust config helper Part of the Security Advanced skill category.
zapier-integration-helper
Zapier Integration Helper - Auto-activating skill for Business Automation. Triggers on: zapier integration helper, zapier integration helper Part of the Business Automation skill category.
zai-cli
Execute z.AI CLI providing vision, search, reader, and GitHub exploration via CLI and MCP. Use when user needs image/video analysis, OCR, UI-to-code conversion, error diagnosis, real-time web search, web page to markdown extraction, or GitHub code exploration. Trigger with phrases like "analyze this image", "search the web for", "read this page", "explore this repo", or "use zai". Requires Z_AI_API_KEY.
yt-research
Research competitor YouTube channels, niches, and trending topics for your content strategy. Use this skill whenever the user says "research channels", "analyze competitors", "find trending topics", "niche analysis", "competitive research", "what are other creators doing", "scrape YouTube channels", or wants to understand the competitive landscape for a specific tool or topic area. Use when working with yt research. Trigger with 'yt', 'research'.