Ansible
$ ansible 官方出品 高风险Ansible(ansible 及 ansible-playbook、ansible-inventory)无需在目标主机安装代理即可通过 SSH 编排服务器配置,支持 --check --diff 变更预演、ANSIBLE_STDOUT_CALLBACK=json 结构化回调与 ansible-inventory --list JSON 清单导出。
brew install ansible ansible 直接读取本地仓库 Playbook 与清单并通过 SSH 调度执行,必须通过本地 CLI 运行。
Agent 友好度体检单
当前为静态评估(本机尚未安装或尚未运行探针)。可在本地运行 npm run data:probe 并提交 data/probes/ 升级为实测证据。
FCRS-1.0 六维评分拆解
ansible-inventory --list 与 ANSIBLE_STDOUT_CALLBACK=json 提供结构化 JSON,且 --check --diff 支持预演。
- Supports
--check --diff,ANSIBLE_STDOUT_CALLBACK=json, andansible-inventory --list
--check --diff 与 --limit 是强有力的护栏,但 shell/command 类原生命令任务在 check 模式下通常无法模拟(除非避免使用 check_mode: false)。
- Supports
--check,--diff, and--limit; raw shell tasks vary
macOS 与 Linux 可通过 brew install ansible 或 pip install ansible-core 方便安装;Windows 控制端需借助 WSL。
- macOS/Linux native via Homebrew and PyPI; Windows via WSL
海量幂等模块支撑跨主机群的无代理配置编排。
- Mature agentless SSH automation ecosystem
Red Hat 官方仓库(ansible/ansible)在 GPL-3.0-or-later 下长期维护。
- Official
ansible/ansiblerepository
具备详尽的 docs.ansible.com 文档与离线模块查询工具 ansible-doc。
- Offline
ansible-docand online reference
安全边界、鉴权与放权指南
使用 ~/.ssh/ 或 ssh-agent 中的 SSH 密钥,以及可选的 Ansible Vault 密码文件(--vault-password-file / ANSIBLE_VAULT_PASSWORD_FILE)。
完全开源免费(GPL-3.0-or-later);直接作用于您既有的 SSH 受管主机。
# Ansible Agent Rules - ALWAYS run `ansible-playbook --syntax-check` and `--check --diff` before real execution. - Set `ANSIBLE_NOCOLOR=1` and `ANSIBLE_HOST_KEY_CHECKING=True`; pass `--limit <host>` when testing. - Never run destructive ad-hoc `shell`/`command` modules across `all` hosts without human approval.
Agent 高频安全命令配方
只读查询(安全推荐)
ansible-inventory -i inventory.ini --list
不连接远程主机即可输出完整的主机组与变量 JSON。
--check --diff 预演 Playbook 变更 ANSIBLE_NOCOLOR=1 ansible-playbook -i inventory.ini site.yml --check --diff
模拟执行任务并展示文件与模板差异,不实际修改目标主机。
受控写入与预演
ANSIBLE_STDOUT_CALLBACK=json ANSIBLE_NOCOLOR=1 ansible-playbook -i inventory.ini site.yml --limit web01
通过 --limit web01 收窄影响范围并以 JSON 回调捕获执行结果。
核心优势
- +
--check --diff可在落地前预演幂等配置变更。 - +
ANSIBLE_STDOUT_CALLBACK=json与ansible-inventory --list输出标准 JSON。 - +
ansible-doc可离线查询全部已安装模块的精确参数定义。
注意事项与踩坑点
- ! 控制节点不原生支持 Windows(需使用 WSL)。
- ! Playbook 中直接调用
shell或command的任务在--check模式下容易跳过或失真。