我需要帮助修复以下 Vagrant 文件,因为它的行为不正确。
由于某种原因,执行 vagrant up 时,Shell 脚本在 Windows VM 上执行,而不是在 Linux 上执行。
Vagrant.configure("2") do |config_wglr|
config_wglr.winrm.timeout = 3600
config_wglr.winrm.retry_limit = 30
config_wglr.winrm.retry_delay = 10
config_wglr.vm.boot_timeout = 3600
config_wglr.vm.define "WGLR" do |glw_runner|
glw_runner.vm.box = "gusztavvargadr/docker-windows"
glw_runner.vm.network "private_network", ip: "xxxx"
end
config_wglr.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--memory", "2048"]
vb.customize ["modifyvm", :id, "--vram", "256"]
end
end
Vagrant.configure("2") do |config_lglr|
config_lglr.vm.box = "generic/rocky8"
config_lglr.vm.hostname = "LGLR"
config_lglr.vm.network "private_network", ip: "yyyy"
# the boxes need to be accessible via password and username
config_lglr.vm.provision "shell", inline: <<-SHELL
sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/g' /etc/ssh/sshd_config
systemctl restart sshd
SHELL
config_lglr.vm.define "LGLR"
# begin disable audio
config_lglr.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--audio", "none"]
end
# end disable audio
end
欢迎提出任何建议。
行为日志-在 Linux VM 启动之前执行 Shell 脚本。
==> WGLR: Machine booted and ready!
==> WGLR: Checking for guest additions in VM...
==> WGLR: Setting hostname...
==> WGLR: Waiting for machine to reboot...
==> WGLR: Configuring and enabling network interfaces...
==> WGLR: Mounting shared folders...
WGLR: /vagrant => C:/workdir/ansible-playbook-gitlabrunners
==> WGLR: Running provisioner: shell...
WGLR: Running: inline PowerShell script
WGLR: sed : The term 'sed' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
WGLR: spelling of the name, or if a path was included, verify that the path is correct and try again.
WGLR: At C:\tmp\vagrant-shell.ps1:1 char:5
WGLR: + sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/g' ...
WGLR: + ~~~
WGLR: + CategoryInfo : ObjectNotFound: (sed:String) [], CommandNotFoundException
WGLR: + FullyQualifiedErrorId : CommandNotFoundException
WGLR:
WGLR: systemctl : The term 'systemctl' is not recognized as the name of a cmdlet, function, script file, or operable
WGLR: program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
WGLR: At C:\tmp\vagrant-shell.ps1:2 char:5
WGLR: + systemctl restart sshd
WGLR: + ~~~~~~~~~
WGLR: + CategoryInfo : ObjectNotFound: (systemctl:String) [], CommandNotFoundException
WGLR: + FullyQualifiedErrorId : CommandNotFoundException
WGLR:
==> LGLR: Importing base box 'generic/rocky8'...
答案1
解决。
我错过了定义级别的 DO,因此范围是错误的。