乐于分享
好东西不私藏

AIOps 探索:OpenClaw 直接安装 Ansible Skill:批量管理 Linux 主机如此简单

AIOps 探索:OpenClaw 直接安装 Ansible Skill:批量管理 Linux 主机如此简单

研究 AIOps 已有数月,目前手里有不少可落地的方案了,接下来会把这些方案全部整理到我的公众号里。欢迎大家关注,可以把你遇到的场景在评论区留言。我会在能力范围内给你提供思路和建议。

上周有给大家提供一篇:AIOps 探索:OpenClaw 安装 Prometheus Skill 实战:一键打造智能运维助手,今天继续深入聊聊怎么通过 ClawHub 直接安装现成的 Ansible Skill,不用手写!


一、前置条件

在开始之前,你需要准备好以下环境:

  1. OpenClaw 已安装并运行(具体安装过程我就不展示了)

  2. Ansible 已安装 在控制机器上

  3. 至少一台 Linux 主机 用于测试

  4. SSH 免密配置 完成

具体过程我就不展示了,希望大家能看明白这个思路。


二、ClawHub Skills 搜索

2.1 搜索 Ansible 相关 Skills

来看下搜索过程:

$ clawhub search ansibleansible         Ansible           (3.090)ansible-skill   Ansible Skill     (0.984)sysadmin        Sysadmin          (0.973)linux           Linux             (0.999)host-hardening  Host Hardening    (0.887)

太火了!这么多相关的 Skills!

2.2 查看已安装 Skills

$ clawhub listproactive-agent-skill     1.0.0openclaw-mcp-plugin       0.1.1web-search-free           1.0.1openclaw-github-assistant 2.0.1skill-vetter              1.0.0

三、安装 Ansible Skill

3.1 安装核心 Skills

我的第一个提示词:

帮我安装 ansible-skill 和 linux 这两个 Skills

看看它的回复:

# 安装 Ansible 自动化技能clawhub install ansible-skill# 安装 Linux 系统操作指南clawhub install linux# 安装 Ansible 最佳实践参考clawhub install ansible# 安装主机安全加固技能clawhub install host-hardening

3.2 验证安装

$ clawhub listproactive-agent-skill     1.0.0openclaw-mcp-plugin       0.1.1web-search-free           1.0.1openclaw-github-assistant 2.0.1skill-vetter              1.0.0ansible-skill             latestlinux                     latestansible                   latesthost-hardening            latest

牛逼!全部安装成功了!


四、Skill 功能详解

4.1 ansible-skill 包含内容

这个 Skill 由 botond-rackhost 发布,包含:

skills/ansible/├── SKILL.md├── inventory/              # 主机清单│   ├── hosts.yml│   └── group_vars/├── playbooks/              # 可执行剧本│   ├── site.yml│   ├── openclaw-vps.yml│   └── security.yml├── roles/                  # 可复用角色│   ├── common/            # 基础系统配置│   ├── security/          # 安全加固│   ├── nodejs/            # Node.js 安装│   └── openclaw/          # OpenClaw 部署└── references/             # 文档参考    ├── best-practices.md    ├── modules-cheatsheet.md    └── troubleshooting.md

4.2 linux Skill 包含内容

这个 Skill 由 ivangdavila 发布,包含:

  • Linux 系统操作避坑指南

  • 常见权限陷阱说明

  • 诊断技巧和命令参考

  • 安全扫描:Benign(高可信度)


五、实战演示

5.1 配置主机清单

编辑 inventory/hosts.yml:

all:  children:    webservers:      hosts:        web01:          ansible_host: 192.168.1.101          ansible_user: root        web02:          ansible_host: 192.168.1.102          ansible_user: root    dbservers:      hosts:        db01:          ansible_host: 192.168.1.201          ansible_user: root    all:vars:      ansible_ssh_private_key_file: ~/.ssh/id_rsa      ansible_python_interpreter: /usr/bin/python3

5.2 测试连接

来看下测试过程:

$ ansible all -i inventory/hosts.yml -m pingweb01 | SUCCESS => {    "changed": false,    "ping": "pong"}web02 | SUCCESS => {    "changed": false,    "ping": "pong"}db01 | SUCCESS => {    "changed": false,    "ping": "pong"}

5.3 通过 OpenClaw 调用

我的提示词:

检查所有 Linux 主机的磁盘使用率,超过 80% 的列出来

它生成的命令:

ansible all -i inventory/hosts.yml -m shell -a "df -h / | awk 'NR==2 {print $5}'"

执行结果:

web01 | CHANGED | rc=0 >>45%web02 | CHANGED | rc=0 >>82%  ⚠️db01 | CHANGED | rc=0 >>67%

哇!web02 磁盘超过 80% 了,需要清理。


六、常用运维场景

6.1 批量部署 Nginx

# 使用预定义的 playbookansible-playbook -i inventory/hosts.yml playbooks/site.yml \  --tags "nginx,web"

6.2 安全加固

# 运行安全加固剧本ansible-playbook -i inventory/hosts.yml playbooks/security.yml \  --limit production \  --tags "ssh,firewall"

6.3 批量执行命令

# 检查系统负载ansible all -i inventory/hosts.yml -m shell -a "uptime"# 重启服务ansible openclaw -i inventory/hosts.yml -m systemd \  -a "name=openclaw state=restarted"# 检查磁盘空间ansible all -i inventory/hosts.yml -m shell -a "df -h"

6.4 滚动更新

# 一次更新一台服务器ansible-playbook -i inventory/hosts.yml playbooks/update.yml \  --serial 1

七、与其他 Skills 联动

7.1 配合 proactive-agent-skill

可以设置定时任务自动巡检:

# HEARTBEAT.md 配置### System Checks- [ ] Ansible 主机连通性检查- [ ] 磁盘使用率告警 (>80%)- [ ] 服务状态检查

7.2 配合 host-hardening

自动执行安全加固:

# 安装后自动运行clawhub install host-hardeningansible-playbook -i inventory/hosts.yml playbooks/hardening.yml

八、总结

最关键的步骤是:

  1. clawhub search - 搜索现成 Skills,不要重复造轮子

  2. clawhub install - 一键安装,自动下载到 ~/.openclaw/workspace/skills/

  3. 配置 inventory - 主机清单要准确

  4. SSH 免密 - 这是 Ansible 能工作的基础

这套组合拳打下来,批量运维 Linux 主机还真挺简单的。比手写 Skills 效率高多了,而且社区维护的 Skills 质量有保障。


九、Skill 安全说明

ClawHub 上的 Skills 都经过安全扫描:

Skill

安全等级

置信度

ansible-skill

Benign

High

linux

Benign

High

ansible

Benign

High

host-hardening

Benign

High

但要注意:

  • 部分 Skill 包含可执行命令,运行前请审查

  • 生产环境建议先在测试机器验证

  • 敏感操作(如 rm -rf)不要直接让 Agent 执行


十、下一步计划

接下来有更多场景可以探索:

  • 如何用 ansible-skill 实现 OpenClaw 自动部署

  • 基于 proactive-agent-skill 的定时巡检

  • Ansible Vault 密钥管理最佳实践

有任何问题可以在公众号后台留言,欢迎大家分享自己的使用场景。


最后介绍下我的公众号:研究 AIOps 已有数月,目前手里有不少可落地的方案了,接下来会把这些方案全部整理到我的公众号里。如果你觉得这篇文章有帮助,欢迎关注,分享给更多运维伙伴。

相关学习资料