我想安装aws临时设备
/dev/xvde on /mnt/ephemeral0
/dev/xvdf on /mnt/ephemeral1
/dev/xvdg on /mnt/ephemeral2
/dev/xvdh on /mnt/ephemeral3
例如,。如果我选择较小的机器尺寸,我的短暂设备就会减少,因此它必须是设备的动态发现。
我有这样的想法使用facter,但我很难与木偶语法挣扎。
根据要求,这里是具有2个短暂设备的机器上的facter的输出:
./facter |grep xv
blockdevice_xvda_size => 8589934592
blockdevice_xvdf_size => 16380329984
blockdevice_xvdg_size => 16380329984
blockdevices => xvda,xvdf,xvdg
由此我想生成/ etc / fstab挂载,因此xvde和xvdf分别在/ mnt / ephemeral0和/ mnt / ephemeral1上可用。
class mystuff::ephemeral () {
mount { $blockdevices:
pseudecode:
loop through blockdevice that don't match xvda, reset ephemeral counter to 0
if blockdevice match regex xvd[e-h] create an entry in fstab for /dev/xvd[which ever was matched] /mnt/ephemeral$counter
increase counter by 1
mount -a
}
}
更新:在肮脏的黑客行为之下,我已经习惯让自己摆脱困境:
mount { 'unmount_mnt':
name => '/mnt',
ensure => absent,
}
exec { 'fstab':
command => 'X=0; for i in $(/bin/cat /proc/partitions | /bin/awk \'{print $4}\' |/bin/grep xvd[f-i]);do /bin/mkdir /mnt/ephemeral$X; /bin/echo /dev/$i /mnt/ephemeral$X ext3 defaults,nofail,noexec 0 2 ; X=$((X+1)) ; done >> /etc/fstab && mount -a',
unless => '/bin/grep ephemeral /etc/fstab >/dev/null 2>&1',
provider => shell,
notify => Service['auditd'],
path => ["/bin"],
require => Mount['unmount_mnt'],
}
我需要建议如何使用facter以及如何在不使用puppet exec的情况下以优雅的方式构造循环。
答案 0 :(得分:1)
在使用更新的信息审核您的请求后,我建议您通过这种方式解决问题。应该从已安装了facter的AMI映像创建实例。
启动(创建)新实例时,请在user data
下方(提前选项)插入,以便自动挂载固定磁盘。
#!/usr/bin/env bash
emphemeral=$(facter|awk -F "_" '/xvd[f-i]/&&/_size/{print $2}' )
let x=0
for i in ${emphemeral}
do
mkfs.ext4 -E nodiscard /dev/${i}
mkdir -p /mnt/ephemeral${x}
mount /dev/${i} /mnt/ephemeral${x}
echo "/dev/${i} /mnt/ephemeral${x} auto defaults,nofail,nobootwait,comment=cloudconfig 0 2" >> /etc/fstab
(( x++ ))
done
以下是旧答案,它不适合您的问题,但它是指定短暂磁盘的另一种解决方法。
define mystuff::ephemeral(
$device,
$name,
) {
mount { "${name}":
device => $device,
fstype => "ext4",
ensure => "mounted",
options => "defaults",
atboot => "true",
}
}
您可以应用这样的清单:
mystuff::ephemeral {'ephemeral0':
device => '/dev/xvde',
name => '/mnt/ephemeral0,
}