Hi,
Firstly apologies if this came up already. I was not able to find it with Google searches.
This is a packer-vagrant mixed issue, so I know that it could be also in packer's group.
What I am trying to do is to use packer to create an AWS instance, provision it (with ansible), generate an AWS AMI and postprocessing would generate a vagrant box.
The whole process runs smoothly, but when I try to vagrant up that box I get "The box you attempted to add doesn't match the provider you specified.".
Here is the relevant code from packer's json:
{
Ā "variables": {
Ā Ā ...
Ā },
Ā "builders": [
Ā Ā {
Ā Ā Ā "type": "amazon-ebs",
Ā Ā Ā "access_key": "{{user `aws_access_key`}}",
Ā Ā Ā "secret_key": "{{user `aws_secret_key`}}",
Ā Ā Ā "region": "{{user `region`}}",
Ā Ā Ā "source_ami": "{{user `source_ami`}}",
Ā Ā Ā "instance_type": "{{user `size`}}",
Ā Ā Ā "ssh_username": "{{user `user`}}",
Ā Ā Ā "ami_name": "{{user `temp_box`}}",
Ā Ā Ā "ami_description": "{{user `ami_desc`}}",
Ā Ā Ā "ami_regions": [
Ā Ā Ā Ā "eu-west-1",
Ā Ā Ā Ā "eu-central-1"
Ā Ā Ā ],
Ā Ā Ā "associate_public_ip_address": true,
Ā Ā Ā "force_deregister": true,
Ā Ā Ā "run_tags": {
Ā Ā Ā Ā "type": "packertempinstance"
Ā Ā Ā },
Ā Ā Ā "tags": {
Ā Ā Ā Ā "type": "packerimage",
Ā Ā Ā Ā "tag2": "stuff"
Ā Ā Ā },
Ā Ā Ā "temporary_key_pair_name": "{{user `tmp_keypair`}}"
Ā Ā }
Ā ],
Ā "provisioners": [
Ā Ā {
Ā Ā Ā "type": "shell",
Ā Ā Ā "inline": [
Ā Ā Ā Ā "while [ ! -f /var/lib/cloud/instance/boot-finished ]; do echo 'Waiting for cloud-init...'; sleep 1; done"
Ā Ā Ā ]
Ā Ā },
Ā Ā {
Ā Ā Ā "type": "shell",
Ā Ā Ā "execute_command": "echo 'packer' | {{.Vars}} sudo -S -E bash '{{.Path}}'",
Ā Ā Ā "inline": ["apt install python-minimal aptitude -y"]
Ā Ā },
Ā Ā {
Ā Ā Ā "type": "ansible",
Ā Ā Ā "playbook_file": "./playbook.yml",
Ā Ā Ā "groups": ["all", "app"],
Ā Ā Ā "ssh_host_key_file": "/Users/myuser/.ssh/mykey.pem",
Ā Ā Ā "extra_arguments": "-v",
Ā Ā Ā "ansible_env_vars": [ "ANSIBLE_HOST_KEY_CHECKING=False" ]
Ā Ā },
Ā Ā {
Ā Ā Ā "type": "shell",
Ā Ā Ā "execute_command": "echo 'packer' | {{.Vars}} sudo -S -E bash '{{.Path}}'",
Ā Ā Ā "script": "cleanup.sh"
Ā Ā }
Ā ],
Ā "post-processors": [
Ā Ā {
Ā Ā Ā "type": "vagrant",
Ā Ā Ā "keep_input_artifact": true,
Ā Ā Ā "output": "modified-xenial.box"
Ā Ā }
Ā ]
}
When the modified-xenial.box is generated I'm adding it as a box:
# vagrant box add mybox `pwd`/modified-xenial.box
And then:
# vagrant init mybox -m
At this point I have a Vagrantfile like this:
$ cat Vagrantfile
Vagrant.configure("2") do |config|
Ā config.vm.box = "mybox"
Ā config.vm.box_url = ["file:///Users/myuser/Dev/modified-xenial.box"]
end
However, when I vagrant up it I get this:
$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Box 'mybox' could not be found. Attempting to find and install...
Ā Ā default: Box Provider: virtualbox
Ā Ā default: Box Version: >= 0
==> default: Box file was not detected as metadata. Adding it directly...
==> default: Adding box 'mybox' (v0) for provider: virtualbox
Ā Ā default: Unpacking necessary files from: file:///Users/myuser/Dev/modified-xenial.box
The box you attempted to add doesn't match the provider you specified.
Provider expected: virtualbox
Provider of box: aws
I understand that the original box was built using AWS's builder from packer, but the postprocessor should generate a vagrant/Virtualbox friendly box, right?
Any help into what I am doing wrong is appreciated.
Cheers,
Miguel