Chuyển đến nội dung
Skillpedia
Triển khai và đám mây (DevOps)18k · #10662

ansible

Skill này làm gì

Skill này hướng dẫn viết tự động hóa Ansible, gồm playbook, role, inventory và xử lý secret bằng Vault. Nó dành cho người quản lý máy chủ và hạ tầng bằng Ansible.

Khi nào nên dùng

  • ✓Khi bạn cần một playbook Ansible để thiết lập hoặc cập nhật máy chủ.
  • ✓Khi bạn muốn tổ chức tự động hóa thành các role và inventory có thể tái sử dụng.
  • ✓Khi bạn cần giữ mật khẩu trong Ansible Vault thay vì văn bản thuần.

Liên kết skill

https://github.com/RightNow-AI/openfang/blob/main/crates/openfang-skills/bundled/ansible/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/RightNow-AI/openfang/blob/main/crates/openfang-skills/bundled/ansible/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Viết một role Ansible cài đặt và cấu hình nginx trên các máy chủ web của chúng tôi, với secret được lưu trong Vault.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Skill đặt ra các nguyên tắc như tác vụ idempotent, tên tác vụ rõ ràng và playbook đã kiểm thử, cùng kỹ thuật cho role, template và biến được mã hóa.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

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
Câu hỏi thường gặp

Idempotent nghĩa là gì?

Nghĩa là chạy playbook hai lần cho kết quả giống chạy một lần, nên việc lặp lại là an toàn.

Secret được xử lý thế nào?

Skill khuyên mã hóa chúng bằng Ansible Vault và không bao giờ commit thông tin xác thực dạng văn bản thuần.

Tôi nên kiểm thử playbook thế nào?

Skill gợi ý molecule hoặc ansible-lint trước khi áp dụng playbook vào máy chủ sản xuất.

Chi tiết

Mô tả gốc của tác giả

Ansible automation expert for playbooks, roles, inventories, and infrastructure management

repo: RightNow-AI/openfang

Độ phổ biến

Sao GitHub
18k
Vị trí xếp hạng
#10662
Giấy phép
Apache-2.0
Cập nhật
2/7/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự