Master端
打开存放自定义grains的目录
vim /etc/salt/master file_roots: base: - /srv/salt/
建立自定义模块
cd /srv/salt mkdir _grains cd _grains
编写自定义grains
cat disk.pyimport 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
测试
[[email protected] _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
时间: 2024-10-15 15:35:53