我的打包程序构建失败,显示以下消息:
sudo: sorry, you must have a tty to run sudo.
我的主机是带有vagrant和virtualbox的Windows 8,我的客人是centos7。
在研究它是我的理解,不要求suty的tty是消息的原因。但我在ks.cfg
中有以下内容:
sed -i 's/^.*requiretty/#Defaults requiretty/' /etc/sudoers
问题可能是我需要在windows vagrant ssh端设置一些东西,以便创建一个伪造的东西吗?
这是我第一次去打包机。
我正在使用我下载的打包器版本。
packer.json下面:
{
"variables": {
"version": "{{env `VERSION`}}"
},
"provisioners": [
{
"type": "shell",
"execute_command": "sudo {{.Vars}} sh {{.Path}}",
"scripts": [
"scripts/vagrant.sh",
"scripts/vmtools.sh",
"scripts/cleanup.sh",
"scripts/zerodisk.sh"
]
}
],
"post-processors": [
{
"type": "vagrant",
"output": "INSANEWORKS-CentOS-7.0-x86_64-{{user `version`}}-{{.Provider}}.box"
}
],
"builders": [
{
"type": "virtualbox-iso",
"iso_url": "http://ftp.iij.ad.jp/pub/linux/centos/7/isos/x86_64/CentOS-7-x86_64-NetInstall-1503.iso",
"iso_checksum": "498bb78789ddc7973fe14358822eb1b48521bbaca91c17bd132c7f8c903d79b3",
"iso_checksum_type": "sha256",
"ssh_username": "vagrant",
"ssh_password": "vagrant",
"ssh_wait_timeout": "45m",
"ssh_disable_agent": "true",
"boot_command": [
"<tab> text ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ks.cfg<enter><wait>"
],
"disk_size": "40000",
"hard_drive_interface": "sata",
"guest_additions_path": "VBoxGuestAdditions_{{.Version}}.iso",
"guest_additions_sha256": "7b61f523db7ba75aebc4c7bb0cae2da92674fa72299e4a006c5c67517f7d786b",
"guest_os_type": "RedHat_64",
"headless": "true",
"http_directory": "http",
"shutdown_command": "sudo /sbin/halt -p",
"vboxmanage": [
[ "modifyvm", "{{.Name}}", "--memory", "1024" ],
[ "modifyvm", "{{.Name}}", "--cpus", "1" ]
]
}
]
}
提前致谢。
答案 0 :(得分:25)
您必须在ssh连接中启用PTY。在配置项后面添加构建器部分:
"ssh_pty" : "true"
另见https://packer.io/docs/templates/communicator.html#ssh_pty
你的&#34; execute_command&#34;在供应者部分应为"execute_command" : "echo 'vagrant' | {{ .Vars }} sudo -E -S sh '{{ .Path }}'"
答案 1 :(得分:5)
对于类似的错误消息 - “sudo:no tty present并且没有指定askpass程序” - 我在本文中找到了解决方案:
http://blog.endpoint.com/2014/03/provisioning-development-environment_14.html
除了在构建器部分添加"ssh_pty" : "true"
之外,还要添加以下配置程序:
{
"type": "shell",
"execute_command": "echo '{{user `ssh_pass`}}' | {{ .Vars }} sudo -E -S sh '{{ .Path }}'",
"inline": [
"echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers"
]
}
堆栈: