Sunday, 10 June 2018

packer: virtualbox

Prep
  • Vagrant
    • vagrant init hashicorp/precise64
    • vagrant up
    • vagrant destroy -f
Generate
  • Packer
    • find ~/.vagrant.d/ -name '*ovf' -ls | grep hashi
    • create ex001.json
      • see below
      • fix "source_path" to ovf file to match your system
    • packer validate ex001.json
    • packer build ex001.json
    • vagrant box add my-box-001 packer_virtualbox-ovf_virtualbox.box --force
Test
  • mkdir test001
  • cd test001
  • vagrant init
    • in generated "Vagrantfile", change 1st line to 2nd line
      •   config.vm.box = "base"
      •   config.vm.box = "my-box-001"
  • vagrant up
  • vagrant ssh
    • cat /var/tmp/welcome.txt
      • should say, "welcome001"
  • vagrant destroy -f
Cleanup
  • vagrant box remove my-box-001 --force
  • vagrant box remove hashicorp/precise64 --force


ex001.json

{
  "builders": [{
      "type": "virtualbox-ovf",
      "source_path": "<path to your home dir>/.vagrant.d//boxes/hashicorp-VAGRANTSLASH-precise64/1.1.0/virtualbox/box.ovf",
      "ssh_username": "vagrant",
      "ssh_password": "vagrant",
      "shutdown_command": "echo 'packer' | sudo -S shutdown -P now"
    }],
    "provisioners": [
        {
            "type": "shell",
            "inline":[ "echo welcome001 > /var/tmp/welcome.txt" ]
        }
    ],
    "post-processors": ["vagrant"]
}


No comments:

Post a Comment

Note: only a member of this blog may post a comment.

Interview questions: 2020-12

Terraform provider vs provisioner Load balancing Network Load Balancer vs Application Load Balancer  Networking Layer 1 vs Layer 4 haproxy u...