I feel like I'm going crazy here. I am trying to create a Vagrant VirtualBox image from a CentOS 7 ISO using Packer. More specifically, I am running the virtualbox-iso
builder and using the Vagrant post-processor. According to the output from the packer build
operation, my provisioners are all working, but none of my provisioning changes are showing up when I bring the box up with Vagrant. As an example, I am using the file provisioner to upload a file to the /home/vagrant directory. In my mind, this is as simple as it gets.
"provisioners": [
{
"type": "file",
"source": "files/file",
"destination": "/home/vagrant/file"
}
...
Packer doesn't throw any errors, and by all indications, the file upload is successful. Here is the message from the Packer trace indicating the file was uploaded.
==> virtualbox-iso: Uploading files/file => /home/vagrant/file
And yet, when I bring up the box in Vagrant and I SSH in, the file is not there. Same thing with my scripts - Packer indicates that they are being run, and I even added print debug statements in the shell scripts using &&
to verify that commands were executed successfully, such as:
mkdir -p /home/vagrant/folder1 && echo "Made the directory, dammit"
I see my echo
statement in the packer build
trace, but still nothing in /home/vagrant when I login. I feel like I'm missing something obvious... Does anybody know what the problem might be?
EDIT: Here is the template for the VBox image. I am also building a VMware image, but I did not include that one here.
"builders": [
{
"type": "virtualbox-iso",
"boot_command": [
"<tab> text ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ks.cfg<enter><wait>"
],
"boot_wait": "10s",
"disk_size": 81920,
"guest_os_type": "RedHat_64",
"headless": true,
"http_directory": "http",
"iso_urls": [
"CentOS-7-x86_64-Minimal-1708.iso",
"http://mirrors.ocf.berkeley.edu/centos/7/isos/x86_64/CentOS-7-x86_64-Minimal-1708.iso"
],
"iso_checksum_type": "sha256",
"iso_checksum": "bba314624956961a2ea31dd460cd860a77911c1e0a56e4820a12b9c5dad363f5",
"ssh_username": "vagrant",
"ssh_password": "vagrant",
"ssh_port": 22,
"ssh_wait_timeout": "10000s",
"shutdown_command": "echo 'vagrant'|sudo -S /sbin/halt -h -p",
"guest_additions_path": "VBoxGuestAdditions_{{.Version}}.iso",
"virtualbox_version_file": ".vbox_version",
"vm_name": "packer-centos-7-x86_64",
"vboxmanage": [
[
"modifyvm",
"{{.Name}}",
"--memory",
"1024"
],
[
"modifyvm",
"{{.Name}}",
"--cpus",
"2"
]
]
},
...
After running packer build
I am running vagrant up virtualbox
which is the name of the VM as defined in my Vagrantfile:
# VirtualBox.
# `vagrant up virtualbox --provider=virtualbox`
config.vm.define "virtualbox" do |virtualbox|
virtualbox.vm.hostname = "virtualbox-centos7"
virtualbox.vm.box = "file://builds/virtualbox-centos7.box"
virtualbox.vm.network :private_network, ip: "172.16.3.2"
config.vm.provider :virtualbox do |v|
v.gui = false
v.memory = 1024
v.cpus = 1
v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
v.customize ["modifyvm", :id, "--ioapic", "on"]
end
config.vm.provision "shell", inline: "echo Hello, World"
end
I am working off of the following repository on GitHub (which I realize may be a bit dated): https://github.com/geerlingguy/packer-centos-7
However, I am trying to tweak the examples to suit my own needs.
EDIT 2: For troubleshooting purposes, I tried removing the vagrant post-processor and just keeping the VMware and VBox images without converting to Vagrant boxes. I booted each of these and the provisioning I did with Packer shows up there. This means that the problem happens somewhere during or after the conversion to Vagrant boxes, since both the VMware and VBox non-Vagrant images have the desired changes. Hopefully this helps narrow it down.
packer build
command, else existing files won't be overwritten and you end up with the old box... – su_li