Home › Ansible › Ansible Windsurf rules

Ansible Windsurf rules

Windsurf rules for Ansible playbooks and roles: FQCN modules, idempotency, check mode, vault secrets, and ansible-lint.

WindsurfAnsible

How to use

Save this as .windsurf/rules/ansible.md in your repository root, commit it, and your agent will pick it up automatically. Edit the commands to match your project.

Note: Review and test before use. Provided as is, without warranty. See Terms.

.windsurf/rules/ansible.mdDownload  
---
trigger: glob
globs: **/*.yml,**/*.yaml,roles/**,playbooks/**
---

# Ansible

## Commands
- Lint: `ansible-lint` · Syntax: `ansible-playbook site.yml --syntax-check`
- Dry run: `ansible-playbook -i inventories/staging site.yml --check --diff --limit <host>`
- **Never run a playbook without `--check` against real inventories unless the user asks.** Molecule tests (`molecule test`) are fine.

## Rules
- Use fully qualified module names (`ansible.builtin.copy`, `ansible.builtin.template`, `community.general.ufw`).
- Prefer modules over `command`/`shell`. If you must use them, add `creates:`/`removes:` or `changed_when:`/`failed_when:` so they're idempotent and report changes honestly.
- Every task has a `name:` starting with a verb ("Install nginx").
- Roles follow the standard layout (`tasks/`, `handlers/`, `templates/`, `defaults/main.yml`, `meta/main.yml`). Defaults hold overridable variables, prefixed with the role name (`nginx_worker_processes`).
- Restart services via handlers (`notify: Restart nginx`), not unconditional restart tasks.
- Templates (`.j2`) start with `{{ ansible_managed | comment }}`.
- Secrets in Ansible Vault (`ansible-vault encrypt_string`) or an external secret lookup; `no_log: true` on tasks that handle them.
- Use `become: true` only on tasks that need it.
- Pin collections in `collections/requirements.yml`.
- Keep inventories per environment (`inventories/staging`, `inventories/production`) with `group_vars`/`host_vars`.

## Done
`ansible-lint` passes with the production profile and a `--check --diff` run on staging shows only expected changes.

More: all Ansible rules · all Windsurf rules

Related rules

AWS CDK (TypeScript) CLAUDE.md

CLAUDE.md for AWS CDK v2 apps in TypeScript: constructs, least-privilege grants, snapshot tests, and safe deploys.

Claude Code (CLAUDE.md)AWS CDK

Docker & Compose AGENTS.md

AGENTS.md for containerized projects: lean multi-stage Dockerfiles, Docker Compose for local dev, and image security.

AGENTS.mdDocker

Dockerfile Copilot path instructions

Path-specific Copilot instructions for Dockerfiles and compose files: multi-stage builds, non-root, and pinned images.

GitHub CopilotDocker

GitHub Actions workflow rules

Cursor rules for writing secure, fast GitHub Actions workflows: permissions, pinning, caching, and concurrency.

CursorGitHub Actions

GitHub Actions Copilot path instructions

Path-specific Copilot instructions for .github/workflows YAML: least privilege, pinned actions, and injection-safe steps.

GitHub CopilotGitHub Actions

Kubernetes & Helm CLAUDE.md

CLAUDE.md for Kubernetes manifests and Helm 3 charts: resources, probes, security context, and safe rollouts.

Claude Code (CLAUDE.md)Kubernetes / Helm

Get new rules weekly

One email a week: fresh rule files, agent tips, and what's changing in Cursor, Claude Code and Copilot. Free, unsubscribe anytime.

Opens the Rulestack Newsletter on beehiiv in a new tab. Or subscribe directly on beehiiv.