由于sudo需要tty,Packer构建失败

Har*_*rge 14 sudo virtualbox packer vagrant

我的打包器构建失败,显示以下消息:

sudo: sorry, you must have a tty to run sudo.
Run Code Online (Sandbox Code Playgroud)

我的主机是带有vagrant和virtualbox的Windows 8,我的客人是centos7.在研究它是我的理解,不要求suty的tty是消息的原因.但我有以下内容ks.cfg:

sed -i 's/^.*requiretty/#Defaults requiretty/' /etc/sudoers
Run Code Online (Sandbox Code Playgroud)

可能问题是我需要在Windows vagrant ssh端设置一些东西,以便创建一个伪造的tty?

这是我第一次去打包机.

我正在使用我下载的打包器构建.

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" ]
      ]
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)

提前致谢.

San*_*ick 26

您必须在ssh连接中启用PTY.在配置项后面添加您的构建器部分:

"ssh_pty" : "true"
Run Code Online (Sandbox Code Playgroud)

另请参见https://packer.io/docs/templates/communicator.html#ssh_pty

您在配置程序部分中的"execute_command"应该是 "execute_command" : "echo 'vagrant' | {{ .Vars }} sudo -E -S sh '{{ .Path }}'"

  • 这是正确的答案.我希望我昨天看到这个,因为它会为我节省很多时间.只是为了澄清你需要做些什么,你想要这样的"建设者":[{"type":"virtualbox-iso","communicator":"ssh","ssh_pty":"true",` (2认同)

Yai*_*gal 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"
  ]
}
Run Code Online (Sandbox Code Playgroud)

堆:

  • 主持人 - Mac
  • Packer构建器类型 - virtualbox-iso
  • (使用流浪汉)