packer
我正在使用 在 Virtualbox 中自动配置自定义 Ubuntu Server 22.10(使用 定制) vagrant
。 在配置过程中,我收到以下错误:
2023-01-12T07:39:14.671+0200 [INFO] provider.terraform-provider-vagrant_4.1.0: 2023/01/12 07:39:14 [ERROR] There was an error while executing `VBoxManage`, a CLI used by Vagrant
for controlling VirtualBox. The command and stderr is shown below.
Command: ["sharedfolder", "add", "cd8bca46-158a-40ad-8928-2a0eefecce19", "--name", "vagrant", "--hostpath", "/home/cyau/kubernetes-cluster"]
Stderr: VBoxManage: fatal error: RTR3Init: VERR_NO_TRANSLATION: timestamp=2023-01-12T07:39:14.671+0200
以上日志来自 Terraform,但我已vagrant up
在 Virtualbox 7.0 和 Virtualbox 6.1 上尝试使用简单的方法,并获得了相同的结果。
vagrant
:2.3.4
Virtualbox
:6.1.38_Ubuntur153438
操作系统:Ubuntu 22.04.1 LTS
terraform
:1.3.6
Vagrant文件:
private_key_path = ENV.fetch("private_key_path", "/home/cyau/.ssh/virtual_id_ed25519")
virtual_machine_image = ENV.fetch("virtual_machine_image", "ubuntu-22.10-live-server-amd64")
# virtual_machine_index = ENV.fetch("virtual_machine_index", "")
ip_base = ENV.fetch("ip_base", "192.168.56")
ip_offset = ENV.fetch("ip_offset", "11").to_i
#count_index = ENV.fetch("count_index", "").to_i
cluster_name = ENV.fetch("cluster_name", "kubernetes-cluster")
node_name = ENV.fetch("node_name", "worker")
node_cpus = ENV.fetch("node_cpus", "1").to_i
node_memory = ENV.fetch("node_memory", "2").to_i
node_count = ENV.fetch("node_count", "2").to_i
VAGRANT_DISABLE_VBOXSYMLINKCREATE=1
Vagrant.configure("2") do |config|
config.ssh.insert_key = false
config.ssh.private_key_path = private_key_path
(1..node_count).each do |i|
config.vm.define "#{node_name}-#{i}" do |node|
node.vm.box = virtual_machine_image
node.vm.box_url = "file://../packer-vmis/#{virtual_machine_image}.box"
node.vm.network "private_network", ip: "#{ip_base}.#{i + ip_offset}"
node.vm.hostname = "#{node_name}-#{i}"
node.vm.provider "virtualbox" do |v|
v.memory = node_memory
v.cpus = node_cpus
end
node.vm.provision "ansible" do |ansible|
ansible.playbook = "./roles/k8s.yml"
#Redefine defaults
ansible.extra_vars = {
k8s_cluster_name: cluster_name,
# The below are repeated because of Ansible configuration, consider refactoring
k8s_master_admin_user: "vagrant",
k8s_master_admin_group: "sudo",
k8s_node_admin_user: "vagrant",
k8s_node_admin_group: "sudo",
k8s_master_apiserver_advertise_address: "#{ip_base}.#{i + ip_offset}",
k8s_master_node_name: "#{node_name}-#{i}",
k8s_node_public_ip: "#{ip_base}.#{i + ip_offset}"
}
end
end
end
end
我该如何处理这个问题?
答案1
# Vagrantfile
private_key_path = ENV.fetch("private_key_path", "/home/cyau/.ssh/virtual_id_ed25519")
virtual_machine_image = ENV.fetch("virtual_machine_image", "ubuntu-22.10-live-server-amd64")
ip_base = ENV.fetch("ip_base", "192.168.56")
ip_offset = ENV.fetch("ip_offset", "11").to_i
cluster_name = ENV.fetch("cluster_name", "kubernetes-cluster")
node_name = ENV.fetch("node_name", "worker")
node_cpus = ENV.fetch("node_cpus", "1").to_i
node_memory = ENV.fetch("node_memory", "2").to_i
node_count = ENV.fetch("node_count", "2").to_i
Vagrant.configure("2") do |config|
config.ssh.insert_key = false
config.ssh.private_key_path = private_key_path
(1..node_count).each do |i|
config.vm.define "#{node_name}-#{i}" do |node|
node.vm.box = virtual_machine_image
node.vm.box_url = "file://../packer-vmis/#{virtual_machine_image}.box"
node.vm.network "private_network", ip: "#{ip_base}.#{i + ip_offset}"
node.vm.hostname = "#{node_name}-#{i}"
node.vm.provider "virtualbox" do |v|
v.memory = node_memory
v.cpus = node_cpus
end
# Add this line to disable the shared folder creation
node.vm.synced_folder ".", "/vagrant", disabled: true
# Uncomment the Ansible provisioning once basic Vagrant setup works fine
# node.vm.provision "ansible" do |ansible|
# ansible.playbook = "./roles/k8s.yml"
# ansible.extra_vars = {
# k8s_cluster_name: cluster_name,
# # ... (previous configurations)
# }
# end
end
end
end
在此更新的 Vagrantfile 中,我添加了行 node.vm.synced_folder ".", "/vagrant", disabled: true 以禁用默认共享文件夹创建。这应该可以防止您在使用 VBoxManage 时遇到的特定共享文件夹错误。
现在,当您运行 vagrant up 时,应该会跳过共享文件夹创建,您可以专注于测试基本的 Vagrant 设置而无需 Ansible 配置。如果基本设置运行正常,请取消注释 Ansible 配置部分以继续您的原始设置。