Ansible Lint
$ ansible-lint 官方出品 低风险ansible-lint 用于检查 Ansible Playbook、Role 与 Collection 中的语法错误、弃用模块及最佳实践问题。配合 -f json(Code Climate 格式)与 --offline,Agent 可在不访问 Ansible Galaxy 网络的前提下稳定检查仓库。
brew install ansible-lint 具备 -f json 与 --offline 的本地静态分析工具,MCP 服务端无法替代完整本地仓库检查。
Agent 友好度体检单
当前为静态评估(本机尚未安装或尚未运行探针)。可在本地运行 npm run data:probe 并提交 data/probes/ 升级为实测证据。
FCRS-1.0 六维评分拆解
支持 -f json、-f sarif、--offline 与 --nocolor,但未传 --offline 时可能因解析 Galaxy 依赖而产生干扰输出。
- Code Climate
-f jsonand-f sarifoutput formats - Requires
--offlinein air-gapped sandboxes to avoid Galaxy lookups
默认完全只读;仅在显式传入 --fix 时才会修改本地文件。
- Read-only default; explicit opt-in
--fixfor local rewrites
可通过 Homebrew、pip 与 uvx 在 macOS/Linux 安装,但依赖 ansible-core 且不原生支持 Windows。
- Depends on Python +
ansible-core; macOS/Linux only
可自动拦截 FQCN、Jinja2 与 YAML 常见错误,并用 --fix 减少人工修复成本。
- Covers syntax, schema, deprecation, and style rules
Ansible 官方项目(ansible/ansible-lint),MIT 协议,社区与 Red Hat 团队持续维护。
- Official
ansible/ansible-lintrepo under MIT
ReadTheDocs 文档详尽,每条规则均配有说明与正反示例。
- Rule catalog at ansible.readthedocs.io/projects/lint/
安全边界、鉴权与放权指南
常规检查无需任何凭证;仅在拉取私有 Collection 时才需配置 Ansible Galaxy Token。
MIT 开源免费。
# 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 高频安全命令配方
只读查询(安全推荐)
ansible-lint --offline -f json
不请求 Ansible Galaxy 网络,直接输出符合 Code Climate 规范的 JSON 检查结果。
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 元数据。