主厨配方将几个git存储库克隆到单独的文件夹
我需要将几个git仓库克隆到单独的文件夹中(即 / var / www / repo_name
)。
在我看来,我可以这样:
I need to clone several git repositories into separate folders (i.e /var/www/repo_name
).
It seems to me, I can do that with:
git node['git_folder'] do
repository node['git_repository']
reference "master"
action :sync
user "username"
end
但是如何为角色中的一个配方赋予多个属性?我可以以某种方式使用数据袋来满足我的需求吗?有什么不同的方法吗?
But how can I give several attributes to one recipe in the role?. Can I somehow use data bags for my needs? Is there any different way?
在这里,您将使用数据包来实现它:
Here is how you would accomplish it using data bags:
假定您具有以下数据包结构:
Assuming you have the following data bag structure:
data_bags
git_repos
repo_1.json
repo_2.json
假设您具有以下数据包项目结构:
Assuming you have the following data bag item structure:
{
"id": "repo_1",
"destination": "/var/www/repo_1",
"url": "https://repo.to/clone.git,
"revision": "master",
"user": "username",
"action": "sync"
}
属性 id
,目的地
和 url
是必需的。如果修订
,用户
或操作
,将在配方中使用默认值:
The attributes id
, destination
, and url
are required. If revision
, user
, or action
are omitted, default values will be used in the recipe:
data_bag('git_repos').each do |name|
repo = data_bag_item('git_repos', name)
git repo['destination'] do
repository repo['url']
reference repo['revision'] || 'master'
user repo['user'] || 'username'
action repo['action'] ? repo['action'].to_sym : :sync
end
end
如您所见,您可以在这种情况下 使用数据包,但是我不清楚您为什么要这样做。我认为,这种方法的直观性要差得多,并且在调试过程中很难推理。
As you can see, you could use data bags in this instance, but it's unclear to me why you would want to do so. In my opinion, this approach is far less intutive and much more difficult to reason about during debugging.