ansible实现集群节点信息收集

之前写了一篇关于收集服务器硬件信息的博文,详见服务器硬件常用信息查询脚本 ,除使用脚本可以收集外,也可以使用ansible来实现资源收集。

准备ansible剧本

#cat collectinfo.yaml 
- hosts: all
  tasks:
  - name: collect info   
    template: src=./info.j2 dest=/info.txt
  - name: collect file
    fetch: src=/info.txt dest=./collections/
  - name: delete remote file
    command: rm -f /info.txt

在当前目录下新建collections目录,用于存放收集回的信息

模板文件

hostname: {{ ansible_hostname }}
product name: {{ ansible_product_name }}
product serial: {{ ansible_product_serial }}
system: {{ ansible_distribution }} {{ ansible_distribution_version }}
kernel: {{ ansible_kernel }}
CPU count: {{ ansible_processor_count }}  {{ ansible_processor_cores }} cores
total memory:{{ ansible_memtotal_mb }} MB
IP Address: {{ ansible_all_ipv4_addresses }}

执行脚本

# ansible-playbook collectinfo.yaml 

执行后的文件目录

[root@node01 simple_book]# tree
.
├── collectinfo.yaml
├── collections
│   ├── node01
│   │   └── info.txt
│   ├── node02
│   │   └── info.txt
│   └── node03
│       └── info.txt
└── info.j2

验证:

# cat collections/node02/info.txt 
hostname: node02
product name: VMware Virtual Platform
product serial: VMware-56 4d 43 50 c5 12 0d ae-28 bd 3b 60 89 6c fd f0
system: CentOS 7.4
kernel: 3.10.0-693.el7.x86_64
CPU count: 1  2 cores
total memory:3774 MB
IP Address: [u'172.16.0.12', u'192.168.23.12']
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值