如何使用Chef nfs cookbook

时间:2016-12-16 17:56:16

标签: amazon-web-services amazon-ec2 chef

我花了一些试验和错误来弄清楚如何将AWS EFS mount命令转换为使用chef资源,所以我想我想分享。

亚马逊给出的

命令:

sudo mount -t nfs4 -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2 $(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone).fs-01234567.efs.us-west-2.amazonaws.com:/ efs

1 个答案:

答案 0 :(得分:5)

include_recipe 'nfs'

az = node['ec2']['placement_availability_zone']
region = az[0..-2] # trim last char
file_system_id = 'fs-01234567'
efs_uri = "#{az}.#{file_system_id}.efs.#{region}.amazonaws.com:/" 

directory '/mnt/efs' do
  owner 'root'
  group 'root'
  mode '0755
  recursive true
  action :create
end

mount '/mnt/efs' do
  device efs_uri
  fstype 'nfs4'
  options 'nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2'
  action [:mount, :enable]
end