搜索

PythonReactSEOPDF
GitHub Skill

ansible-playbook

Write and review Ansible playbooks following best practices. Use when the user says "write ansible", "ansible playbook", "review playbook", "automate with ansible", or asks to configure servers with Ansible.

mhalder☆ 1 仓库 Stars0 仓库 Forks

安装与使用

请根据来源仓库和你的 AI 工具说明安装此技能。先阅读技能文件和依赖要求,再添加到工作流。

查看来源 ↗使用指南

技能说明

Ansible Playbook

Write and review Ansible playbooks, roles, and tasks following best practices.

Instructions

When writing:

  1. Understand the target configuration goal
  2. Check existing playbooks/roles for patterns to follow
  3. Write idempotent tasks with proper error handling
  4. Include appropriate tags and handlers

When reviewing:

  1. Read the playbook/role
  2. Check for issues listed below
  3. Suggest improvements

Playbook structure

---
- name: Configure web servers
  hosts: webservers
  become: true
  vars_files:
    - vars/main.yml
  handlers:
    - name: Restart nginx
      ansible.builtin.service:
        name: nginx
        state: restarted
  tasks:
    - name: Install nginx
      ansible.builtin.apt:
        name: nginx
        state: present
        update_cache: true
      notify: Restart nginx
      tags: [nginx, packages]

Best practices

  • MUST use FQCNs: ansible.builtin.copy not copy
  • MUST use name: for every task
  • MUST use become: explicitly, not assuming root
  • Use handlers for service restarts
  • Use block/rescue/always for error handling
  • Use ansible-vault for secrets
  • Use variables for anything environment-specific
  • Use --check mode compatible tasks where possible

Security checks

  • No plaintext passwords in playbooks
  • Secrets in vault-encrypted files
  • no_log: true on tasks with sensitive data
  • File permissions explicitly set
  • SSH keys not hardcoded

Common patterns

# Idempotent file content
- name: Configure app
  ansible.builtin.template:
    src: app.conf.j2
    dest: /etc/app/config
    mode: "0644"
    owner: app
    group: app
    validate: "/usr/bin/app --check %s"
  notify: Restart app

# Package installation
- name: Install packages
  ansible.builtin.apt:
    name: "{{ packages }}"
    state: present
  vars:
    packages:
      - nginx
      - certbot

Rules

  • MUST use fully qualified collection names (FQCNs)
  • MUST include task names
  • Never hardcode secrets in playbooks
  • Never use shell: when a module exists
  • Always make tasks idempotent

使用示例

查看来源仓库中的使用示例与配置说明。

查看来源 ↗

来源历史

收录时间
2026-01-20
索引更新时间
2026-01-26
Branch
main

收录与同步日期属于本站记录。源码修改历史请查看来源仓库。

GitHub ↗

chat Comments (0)

chat_bubble_outline

No comments yet. Be the first to share your thoughts!