标签:fdisk class import grains logs style vda color srv
Master端
打开存放自定义grains的目录
vim /etc/salt/master
file_roots:
base:
- /srv/salt/
建立自定义模块
cd /srv/salt
mkdir _grains
cd _grains
编写自定义grains
cat disk.py
import os def disk(): grains = {} disk = os.popen(‘fdisk -l |grep \‘Disk\‘ |grep -v \‘VolGroup\‘ | grep -v \‘label\‘ |awk -F , \‘{print $1}\‘ | sed \‘s/Disk identifier.*//g\‘ |sed \‘s/Disk //g\‘ | sed \‘/^$/d\‘‘).read() disk = str(disk) #disk = disk.split(‘:‘) grains[‘disk‘] = disk return grains
把自定义grains推送到客户端
salt ‘*‘ grains.items
测试
[root@172-16-1-226 _grains]# salt ‘*‘ grains.item disk 172-16-1-225: ---------- disk: /dev/vda: 107.4 GB 172-16-1-213: ---------- disk: /dev/vda: 107.4 GB 172-16-1-226: ---------- disk: /dev/vda: 107.4 GB
标签:fdisk class import grains logs style vda color srv
原文地址:http://www.cnblogs.com/zhaijunming5/p/6744938.html