To content | To menu | To search

HashiCorp Packer で作った仮想マシンを Vagrant 向けの box ファイルで出力してインポートして起動

ubuntu.pkr.hcl の build の範囲を書き換えた。

build {
    sources = [
      "sources.virtualbox-iso.ubuntu"
    ]
    provisioner "shell" {
      # execute_command = "echo {{.ssh_password}} | sudo bash {{.Path}}"
      execute_command = "bash {{.Path}}"
      script = "scripts/setkey.sh"
    }
    post-processors {  
      post-processor "artifice" {
        files = [
          "build/packer-virtualbox/ubuntu18041-disk001.vmdk",
          "build/packer-virtualbox/ubuntu18041.ovf"
        ]
      }
      post-processor "vagrant" {
        keep_input_artifact = true
        provider_override   = "virtualbox"
      }  
    }
}

シェルスクリプトから sudo が必要なやつはカットして、キーを登録するところだけに集中。

#!/bin/bash

# https://www.gun.io/blog/building-vagrant-machines-with-packer
# set -e

# apt update -y -qq > /dev/null
# apt install -y linux-headers-$(uname -r) build-essential dkms nfs-common
# apt install -y curl git

# https://www.covermymeds.com/main/insights/articles/repeatable-vagrant-builds-with-packer/
# setup insecure vagrant user ssh key
/bin/mkdir /home/vagrant/.ssh
/bin/chmod 700 /home/vagrant/.ssh
/usr/bin/curl -L -o /home/vagrant/.ssh/id_rsa https://raw.githubusercontent.com/mitchellh/vagrant/master/keys/vagrant
/usr/bin/curl -L -o /home/vagrant/.ssh/authorized_keys https://raw.githubusercontent.com/mitchellh/vagrant/master/keys/vagrant.pub
/bin/chown -R vagrant:vagrant /home/vagrant/.ssh
/bin/chmod 0600 /home/vagrant/.ssh/*

これで通った。

https://discuss.hashicorp.com/t/virtualbox-iso-no-tty-present-and-no-askpass-program-specified/19513

https://www.packer.io/docs/debugging

https://acloudguru.com/hands-on-labs/formatting-a-packer-template-in-hcl2

https://www.gun.io/blog/building-vagrant-machines-with-packer

https://www.covermymeds.com/main/insights/articles/repeatable-vagrant-builds-with-packer/

https://lab.unicast.ne.jp/2013/09/09/troubleshooting-create-vagrant-box-with-packer/

https://qiita.com/mitzi2funk/items/c963483a11a1912e3c44

https://www.packer.io/docs/communicators/ssh

Add a comment

HTML code is displayed as text and web addresses are automatically converted.

They posted on the same topic

Trackback URL : https://www.pseudomoon.jp/dotclear/index.php?trackback/152

This post's comments feed