Ansible
Ansible是一款code方向的AI技能,核心价值是Ansible conventions and best practices,可用于解决开发者在code领域的实际问题,帮助用户提升效率、自动化重复任务或优化工作流。
Ansible conventions and best practices
mkdir -p ./skills/ansible && curl -sfL https://raw.githubusercontent.com/github/awesome-copilot/main/skills/ansible/SKILL.md -o ./skills/ansible/SKILL.md Run in terminal / PowerShell. Requires curl (Unix) or PowerShell 5+ (Windows).
Skill Content
# Ansible Conventions and Best Practices
General Instructions
- Use Ansible to configure and manage infrastructure.
- Use version control for your Ansible configurations.
- Keep things simple; only use advanced features when necessary
- Give every play, block, and task a concise but descriptive `name`
- Start names with an action verb that indicates the operation being performed, such as "Install," "Configure," or "Copy"
- Capitalize the first letter of the task name
- Omit periods from the end of task names for brevity
- Omit the role name from role tasks; Ansible will automatically display the role name when running a role
- When including tasks from a separate file, you may include the filename in each task name to make tasks easier to locate (e.g., `<TASK_FILENAME> : <TASK_NAME>`)
- Use comments to provide additional context about **what**, **how**, and/or **why** something is being done
- Don't include redundant comments
- Use dynamic inventory for cloud resources
- Use tags to dynamically create groups based on environment, function, location, etc.
- Use `group_vars` to set variables based on these attributes
- Use idempotent Ansible modules whenever possible; avoid `shell`, `command`, and `raw`, as they break idempotency
- If you have to use `shell` or `command`, use the `creates:` or `removes:` parameter, where feasible, to prevent unnecessary execution
- Use [fully qualified collection names (FQCN)](https://docs.ansible.com/ansible/latest/reference_appendices/glossary.html#term-Fully-Qualified-Collection-Name-FQCN) to ensure the correct module or plugin is selected
- Use the `ansible.builtin` collection for [builtin modules and plugins](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/index.html#plugin-index)
- Group related tasks together to improve readability and modularity
- For modules where `state` is optional, explicitly set `state: present` or `state: absent` to improve clarity and consistency
- Use the lowest privileges necessary to perform a task
- Only set `become: true` at the play level or on an `include:` statement, if all included tasks require super user privileges; otherwise, specify `become: true` at the task level
- Only set `become: true` on a task if it requires super user privileges
Secret Management
- When using Ansible alone, store secrets using Ansible Vault
- Use the following process to make it easy to find where vaulted variables are defined
1. Create a `group_vars/` subdirectory named after the group
2. Inside this subdirectory, create two files named `vars` and `vault`
3. In the `vars` file, define all of the variables needed, including any sensitive ones
4. Copy all of the sensitive variables over to the `vault` file and prefix these variables with `vault_`
5. Adjust the variables in the `vars` file to point to the matching `vault_` variables using Jinja2 syntax: `db_password: "{{ vault_db_password }}"`
6. Encrypt the `vault` file to protect its contents
7. Use the variable name from the `vars` file in your playbooks
- When using other tools with Ansible (e.g., Terraform), store secrets in a third-party secrets management tool (e.g., Hashicorp Vault, AWS Secrets Manager, etc.)
- This allows all tools to reference a single source of truth for secrets and prevents configurations from getting out of sync
Style
- Use 2-space indentation and always indent lists
- Separate each of the following with a single blank line:
- Two host blocks
- Two task blocks
- Host and include blocks
- Use `snake_case` for variable names
- Sort variables alphabetically when defining them in `vars:` maps or variable files
- Always use multi-line map syntax, regardless of how many pairs exist in the map
- It improves readability and reduces changeset collisions for version control
- Prefer single quotes over double quotes
- The only time you should use double quotes is when they are nested within single quotes (e.g.
🎯 Best For
- Claude users
- GitHub Copilot users
- Software engineers
- Development teams
- Tech leads
💡 Use Cases
- Code quality improvement
- Best practice enforcement
📖 How to Use This Skill
- 1
Install the Skill
Copy the install command from the Terminal tab and run it. The SKILL.md file downloads to your local skills directory.
- 2
Load into Your AI Assistant
Open Claude or GitHub Copilot and reference the skill. Paste the SKILL.md content or use the system prompt tab.
- 3
Apply Ansible to Your Work
Open your project in the AI assistant and ask it to apply the skill. Start with a small module to verify the output quality.
- 4
Review and Refine
Review AI suggestions before committing. Run tests, check for regressions, and iterate on the skill output.
❓ Frequently Asked Questions
Is Ansible compatible with Cursor and VS Code?
Yes — this skill works with any AI coding assistant including Cursor, VS Code with Copilot, and JetBrains IDEs.
Do I need specific dependencies for Ansible?
Check the install command and Works With section. Most code skills only require the AI assistant and your codebase.
How do I install Ansible?
Copy the install command from the Terminal tab and run it. The skill downloads to ./skills/ansible/SKILL.md, ready to use.
Can I customize this skill for my team?
Absolutely. Edit the SKILL.md file to add team-specific instructions, examples, or workflows.
⚠️ Common Mistakes to Avoid
Skipping validation
Always test AI-generated code changes, even for simple refactors.
Missing dependency updates
Check if the skill requires updated dependencies or new packages.