使用 Chef 在 运行 食谱的其余部分之前设置 DNS?

Use Chef to set DNS before running the rest of a cookbook?

我正在关注大厨之旅并学习如何对大厨进行故障排除 (https://learn.chef.io/modules/keep-your-cookbooks-up-to-date#/)。问题是我使用的每个发行版都在获取 10.0.2.3 resolv.conf 文件。

我试过遵循这个 post: https://serverfault.com/questions/453185/vagrant-virtualbox-dns-10-0-2-3-not-working

但是,该解决方案仅适用于现有 VM。在我的食谱中,我创建了一个模板 resolv.conf.erb 并在 default.rb 的开头放置了以下代码:

模板'/etc/resolv.conf'做 来源 'resolv.conf.erb' 模式“644” 结束

然而,无论我如何尝试和配置它(default.rb 是我的策略文件中的第一件事 运行),厨师正在要求 ubuntu 从 omnitruck.chef.io 在部署我的 resolv.conf 模板之前。这是所有 default.rb:

#
# Cookbook:: base
# Recipe:: default
#
# Copyright:: 2019, The Authors, All Rights Reserved.

include_recipe 'hardening::default'

template '/etc/resolv.conf' do
  source 'resolv.conf.erb'
  mode '644'
end

file '/etc/motd' do
  content node['base']['message']
end

我还需要配置什么才能让 chef 在尝试 wget 之前部署 resolv.conf?

chef 通过在节点上下载并安装 chef 来执行其 bootstrap,然后才使用 运行 列表中的食谱执行 chef-client。因此,在 Chef 启动其 bootstrap.

之前,您需要使用您最喜欢的 dns 解析器配置您的节点

如果您正在使用 vagrant, you can try vagrant-dns or build your own vagrant basebox