packer, aws: "ec2-bundle-vol: line 6: ruby: command not found"

534 views Asked by At

I'm using packer, this is in my provisioners (or the relevant parts at least) right after a provisioner that installs ruby.

{ "type": "shell",
  "inline_shebang": "/bin/bash",
  "inline": [
    "source ~/.bash_profile",
    "rbenv versions",
    "ruby -v",
    "ls /home/ubuntu/.rbenv/versions/",
    "ls /home/ubuntu/.rbenv/",
    "sudo apt-get update",
    "sudo apt-get -y install unzip",
    "sudo apt-get -y install libqt4-dev libsndfile1-dev",
    "wget http://s3.amazonaws.com/ec2-downloads/ec2-ami-tools.zip",
    "sudo mkdir -p /usr/local/ec2",
    "sudo unzip ec2-ami-tools.zip -d /usr/local/ec2"
}

rbenv versions sees 2.1.6

ruby -v says it's 2.1.6

so ruby is definitely installed...

yet I get this error at the end of my packer bundle

==> amazon-instance: Bundling the volume...
    amazon-instance: /usr/local/ec2/ec2-ami-tools-1.5.7/bin/ec2-bundle-vol: line 6: ruby: command not found

the command I have for bundling the volume is

sudo -n env EC2_AMITOOL_HOME=/usr/local/ec2/ec2-ami-tools-1.5.7 /usr/local/ec2/ec2-ami-tools-1.5.7/bin/ec2-bundle-vol -k {{.KeyPath}}  -u {{.AccountId}} -c {{.CertPath}} -    r {{.Architecture}} -e {{.PrivatePath}}/* -d {{.Destination}} -p {{.Prefix}} --batch --no-filter"

I've tried to find any reference at all to someone else getting this error with ec2-ami-tools but with no success. Any pointers as to where I should look for information (already checked out ec2-ami-tools docs, packer docs referencing ec2-bundle-vol, other Packer configs, etc. but could have missed something) would be appreciated.

1

There are 1 answers

0
user2245700 On

My guess is it's because you are bundling with sudo. I actually don't know what rbenv is, but I suspect that only the ubuntu user knows where to find ruby.

So see if sudo ruby -v gives you the right output. If it doesn't, there's your problem.