又一个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}}

相关推荐
weixin_438732108 小时前
ChromeDriver谷歌驱动下载
linux·chrome·selenium·自动化·mac·chrome devtools·chromedriver
小付爱coding8 小时前
跟着官网学LangChain【第01章:模型(Models)】
服务器·网络·langchain
Black__Jacket8 小时前
Ubuntu下,/dev下,无法读取到CH340串口芯片的端口号
linux·运维·ubuntu
小王不爱笑1328 小时前
云服务器部署 JavaWeb 项目
运维·服务器
清泉影月8 小时前
Linux:Squid正向代理实现内网访问互联网
linux·运维·服务器
切糕师学AI8 小时前
ARM 中的 SVC 监管调用(Supervisor Call)
linux·c语言·汇编·arm开发
陌上花开缓缓归以9 小时前
linux jiffies 初始化不为0问题分析
linux·arm开发
霖霖总总9 小时前
[小技巧39]Linux 文件与命令查找工具(which、whereis、locate、find)全面解析
linux·运维
xlq223229 小时前
6.Linux权限
linux
ayaya_mana9 小时前
在 CentOS 7/RHEL 7 上安装并切换至新版内核
linux·运维·centos