【发布时间】:2015-04-23 22:25:37
【问题描述】:
首先让我承认我很难理解整个资源创作技术堆栈。有 LWRP,图书馆资源,重量级资源,我似乎无法找到字符串的结尾,可以说开始解开这个毛线球。因此,这是一个有点广泛的多部分问题。
关键在于我有一个有效的方法,它调用一系列资源来对 linux 设备进行分区、格式化和挂载。现在我想把它变成一个 LWRP(或者如果 LWRP 不合适,任何合适的 R/P 方法),以便我可以以参数化的方式多次调用它。
这是我的初步尝试,关于它的问题如下:
# Resource:: mount_drive_as
#
# Will idempotently find a physical drive (/dev/sdb, /dev/sdc, etc),
# create a primary partition using the entire drive and formated to ext4
# and mount it at the specified mount point.
# An fstab entry is also created to auto mount the partition.
actions :create
default_action :create
#Path to the location where the drive will be mounted, e.g. /data
attribute :mount_point,
:name_attribute => true,
:kind_of => String,
:required => true
attribute :device,
:regex => [ /^sd[a-z]$/ ]
:default => 'sdb'
还有我的提供者(此时主要是原始配方的一个剪辑和过去):
#ensures parted is installed.
run_context.include_recipe 'parted'
def whyrun_supported?
true
end
action :create do
parted_disk "/dev/#{@new_resource.device}" do
label_type "gpt"
action :mklabel
end
parted_disk "/dev/#{@new_resource.device}" do
part_type "primary"
file_system "ext4"
action :mkpart
end
parted_disk "/dev/#{@new_resource.device}1" do
file_system "ext4"
action :mkfs
end
replace_or_add "add /dev/#{@new_resource.device}1 to /etc/fstab" do
path "/etc/fstab"
pattern "^/dev/#{@new_resource.device}1"
line "/dev/#{@new_resource.device}1 #{@new_resource.mount_point} ext4 defaults 0 0"
end
directory @new_resource.mount_point
execute 'mount /dev/#{@new_resource.device}1'
end
所以我有两个基本问题:
- 如何从 :create 操作中正确调用这些其他资源。
- 如何汇总他们所有
updated_by_last_action()调用的结果,以便在我的代码中正确调用updated_by_last_action()。 - 换一种说法,在这种情况下如何正确支持whyrun?
我意识到我在上面使用的一些食谱(特别是来自line 食谱的replace_or_add 和可能是execute)可能更好地从资源中以其他方式完成,但我可以稍后解决。我最感兴趣的是在这里利用的分开的资源。
【问题讨论】:
标签: chef-infra