又一个ansible例子

这个例子有点复杂,他在被控端上采集CPU 内存和磁盘利用率,并且以模板的形式保存在被控端,最后再把这个结果文件从被控端取回来。综合用到了shell、register、template和fetch4个模块


  • name: get cpu mem and disk

hosts: all

tasks:

  • name: get cpu

shell:

cmd: top -bn 1 | grep Cpu | awk '{print 2+3}'

register: mycpu

  • name: get mem

shell:

cmd: free | grep Mem | awk '{print 3/2}'

register: mymem

  • name: get disk

shell:

cmd: df / | grep / | awk '{print $5}'

register: mydisk

  • name: output template

template:

src: /root/result.j2

dest: /root/result.txt

  • name: fetch result

fetch:

src: /root/result.txt

dest: /root/

flat: yes

模板文件如下:

more result.j2

cpu useage: {{mycpu.stdout}}

mem useage: {{mymem.stdout}}

disk useage: {{mydisk.stdout}}

相关推荐
tan180°7 分钟前
Linux网络IP(上)(15)
linux·网络·tcp/ip
没有名字的鬼1 小时前
RK3399 SSH连接设置
linux·ssh·rk3399·mobaxterm
“αβ”1 小时前
MySQL库的操作
linux·服务器·网络·数据库·c++·mysql·oracle
lhyzws1 小时前
CENTOS上的网络安全工具(二十八)SPARK+NetSA Security Tools容器化部署(4)
linux·spark·centos
岚天start2 小时前
源码编译安装的Nginx增加echo模块过程详解
linux·运维·数据库
2201_757830872 小时前
Stream的终结方法
java·服务器·前端
胖咕噜的稞达鸭2 小时前
进程状态,孤儿进程僵尸进程,Linux真实调度算法,进程切换
linux·运维·算法
wanhengidc3 小时前
跨境电商为什么依赖于云手机
运维·服务器·游戏·智能手机·云计算
王道长服务器 | 亚马逊云3 小时前
直播站怎么做到“低延迟不掉线”?AWS + 拳头链路的实战组合
服务器·数据库·搜索引擎·云计算·aws
云计算老刘4 小时前
10. Linux 系统启动原理
linux·运维·服务器