CLI 目录 横向对比 FCRS-1.0 标准 /llms.txt
← 返回 CLI 目录

Ansible Lint

$ ansible-lint 官方出品 低风险
Ansible · 云原生与基础设施 · MIT · macos / linux

ansible-lint 用于检查 Ansible Playbook、Role 与 Collection 中的语法错误、弃用模块及最佳实践问题。配合 -f json(Code Climate 格式)与 --offline,Agent 可在不访问 Ansible Galaxy 网络的前提下稳定检查仓库。

FCRS-1.0 综合评分
87 /100
良好 (Good)
中置信度 (源码/文档)
零摩擦安装命令
brew install ansible-lint
CLI vs MCP 选型建议 优先选 CLI

具备 -f json 与 --offline 的本地静态分析工具,MCP 服务端无法替代完整本地仓库检查。

Agent 友好度体检单

✓ 原生 JSON 输出
— 字段裁剪
✓ 无头非交互
— 支持 Dry-Run
— 只读模式开关
✓ 支持 NO_COLOR
✓ 自省/Schema 发现
— 官方 SKILL.md

当前为静态评估(本机尚未安装或尚未运行探针)。可在本地运行 npm run data:probe 并提交 data/probes/ 升级为实测证据。

FCRS-1.0 六维评分拆解

Agent 友好度 21 / 25

支持 -f json、-f sarif、--offline 与 --nocolor,但未传 --offline 时可能因解析 Galaxy 依赖而产生干扰输出。

  • Code Climate -f json and -f sarif output formats
  • Requires --offline in air-gapped sandboxes to avoid Galaxy lookups
安全与权限边界 23 / 25

默认完全只读;仅在显式传入 --fix 时才会修改本地文件。

  • Read-only default; explicit opt-in --fix for local rewrites
安装与运行摩擦 11 / 15

可通过 Homebrew、pip 与 uvx 在 macOS/Linux 安装,但依赖 ansible-core 且不原生支持 Windows。

  • Depends on Python + ansible-core; macOS/Linux only
能力覆盖与边际价值 13 / 15

可自动拦截 FQCN、Jinja2 与 YAML 常见错误,并用 --fix 减少人工修复成本。

  • Covers syntax, schema, deprecation, and style rules
维护与来源背书 10 / 10

Ansible 官方项目(ansible/ansible-lint),MIT 协议,社区与 Red Hat 团队持续维护。

  • Official ansible/ansible-lint repo under MIT
文档与可验证性 9 / 10

ReadTheDocs 文档详尽,每条规则均配有说明与正反示例。

  • Rule catalog at ansible.readthedocs.io/projects/lint/

安全边界、鉴权与放权指南

鉴权方式
无需鉴权
凭证存储位置

常规检查无需任何凭证;仅在拉取私有 Collection 时才需配置 Ansible Galaxy Token。

潜在副作用
只读查询 本地写入
费用与配额提示

MIT 开源免费。

可复制到 CLAUDE.md / AGENTS.md 的安全护栏
# ansible-lint Agent Rules
- Always pass `--offline` in sandboxed environments to prevent Galaxy network hangs.
- Use `-f json` (or `-f sarif`) for structured findings and avoid `--fix` without reviewing `git diff`.
- Check `.ansible-lint` config in repo root before overriding rules.

Agent 高频安全命令配方

只读查询(安全推荐)

以离线 JSON 模式检查 Ansible 仓库
ansible-lint --offline -f json

不请求 Ansible Galaxy 网络,直接输出符合 Code Climate 规范的 JSON 检查结果。

以紧凑格式检查单个 Playbook
ansible-lint --offline -q -f pep8 playbooks/site.yml

输出简洁的 file:line: rule 诊断行,便于 Agent 快速定位。

受控写入与预演

自动修复安全的格式问题
ansible-lint --offline --fix=all playbooks/site.yml

通过 --fix 在本地自动重写 YAML 与 FQCN 规范(执行后需检查 git diff)。

核心优势

  • + 支持 -f json、-f sarif 与 --nocolor,易于 CI 与 Agent 集成。
  • + --offline 模式确保在受限沙箱中也能快速稳定执行。
  • + 内置 --fix 可自动完成 FQCN 与 YAML 格式修复。

注意事项与踩坑点

  • ! 不原生支持 Windows(Windows 用户需使用 WSL)。
  • ! 未指定 --offline 时默认可能尝试联网拉取 Ansible Galaxy 元数据。

已验证兼容的 Agent 宿主

Claude Code Codex CLI Gemini CLI