跳到正文
Skillpedia
部署与云(DevOps)18k · #10662

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。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/RightNow-AI/openfang/blob/main/crates/openfang-skills/bundled/ansible/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 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:, and post_tasks: sections in that order
  • Use ansible-galaxy init to 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_string for inline variable encryption within otherwise plaintext files
  • Leverage block/rescue/always for error handling and cleanup tasks within playbooks

Common Patterns

  • Handler Notification: Use notify: restart nginx on 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: 2 or serial: "25%" on the play to update hosts in batches, combined with max_fail_percentage to halt on excessive failures
  • Fact Caching: Enable fact_caching = jsonfile in ansible.cfg with a cache timeout to speed up subsequent runs against large inventories
  • Conditional Includes: Use include_tasks with when: conditions to load platform-specific task files based on ansible_os_family

Pitfalls to Avoid

  • Do not use command or shell modules 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: true for 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

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能