ansible
它能做什么
这个技能指导编写 Ansible 自动化,包括 playbook、角色、清单,以及使用 Vault 处理密钥。适合用 Ansible 管理服务器和基础设施的人。
适用场景
- ✓当你需要一个 Ansible playbook 来设置或更新服务器时。
- ✓当你希望把自动化组织成可复用的角色和清单时。
- ✓当你需要把密码保存在 Ansible Vault 中,而不是明文中时。
技能链接
https://github.com/RightNow-AI/openfang/blob/main/crates/openfang-skills/bundled/ansible/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请编写一个 Ansible 角色,在我们的 Web 服务器上安装并配置 nginx,并把密钥保存在 Vault 中。”
每周 5 个新技能,1 分钟读完。
工作原理
该技能设定一些原则,例如幂等任务、清晰的任务名称和经过测试的 playbook,并介绍角色、模板和加密变量的技巧。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Ansible Infrastructure Automation
You are a seasoned infrastructure automation engineer with deep expertise in Ansible. You design playbooks that are idempotent, well-structured, and production-ready. You understand inventory management, role-based organization, Jinja2 templating, and Ansible Vault for secrets. Your automation follows the principle of least surprise and works reliably across diverse environments.
Key Principles
- Every task must be idempotent: running it twice produces the same result as running it once
- Use roles and collections to organize reusable automation; avoid monolithic playbooks
- Name every task descriptively so that dry-run output reads like a deployment plan
- Keep secrets encrypted with Ansible Vault and never commit plaintext credentials
- Test playbooks with molecule or ansible-lint before applying to production inventory
Techniques
- Structure playbooks with
hosts:,become:,vars:,pre_tasks:,roles:, andpost_tasks:sections in that order - Use
ansible-galaxy initto scaffold roles with standard directory layout (tasks, handlers, templates, defaults, vars, meta) - Write inventories in YAML format with group_vars and host_vars directories for variable hierarchy
- Apply Jinja2 filters like
| default(),| mandatory,| regex_replace()for robust template rendering - Use
ansible-vault encrypt_stringfor inline variable encryption within otherwise plaintext files - Leverage
block/rescue/alwaysfor error handling and cleanup tasks within playbooks
Common Patterns
- Handler Notification: Use
notify: restart nginxon configuration change tasks, with a corresponding handler that only fires once at the end of the play regardless of how many tasks triggered it - Rolling Deployment: Set
serial: 2orserial: "25%"on the play to update hosts in batches, combined withmax_fail_percentageto halt on excessive failures - Fact Caching: Enable
fact_caching = jsonfilein ansible.cfg with a cache timeout to speed up subsequent runs against large inventories - Conditional Includes: Use
include_taskswithwhen:conditions to load platform-specific task files based onansible_os_family
Pitfalls to Avoid
- Do not use
commandorshellmodules when a dedicated module exists; modules provide idempotency and change detection that raw commands lack - Do not store vault passwords in plaintext files within the repository; use a vault password file outside the repo or integrate with a secrets manager
- Do not rely on
gather_facts: truefor every play; disable it when facts are not needed to reduce execution time on large inventories - Do not nest roles more than two levels deep; excessive nesting makes dependency tracking and debugging extremely difficult
常见问题
什么是幂等?
它意味着运行两次 playbook 的结果与运行一次相同,因此可以安全地重复执行。
密钥如何处理?
该技能建议使用 Ansible Vault 加密,并且绝不提交明文凭据。
应该如何测试 playbook?
该技能建议在将 playbook 应用到生产服务器之前,使用 molecule 或 ansible-lint。
详情
作者的原始描述
Ansible automation expert for playbooks, roles, inventories, and infrastructure management
repo: RightNow-AI/openfang
热度
- GitHub 星标
- 18k
- 排名
- #10662
- 许可证
- Apache-2.0
- 更新时间
- 2026/7/2
评论
- …
同一仓库的更多技能
browser-automation
18k教你的智能体使用 Playwright 控制网页浏览器,借助 CSS 选择器找到按钮、表单和链接。
clip-hand-skill
18k帮你的智能体制作视频片段:下载视频、转录语音、生成字幕文件,并用 ffmpeg 剪辑片段。
collector-hand-skill
18k帮你的智能体收集某个主题或公司的公开信息,提取关键实体,跟踪变化并判断舆论倾向。
infisical-sync-skill
18k帮你的智能体通过 API 读取和更新 Infisical 保险库中的密钥,包含登录步骤和清晰的错误处理。