I am trying to use the OpenStack provisioner API in packer to clone an instance. So far I have developed the script:
{ "variables": { }, "description": "This will create the baked vm images for any environment from dev to prod.", "builders": [ { "type": "openstack", "identity_endpoint": "", "tenant_name": "admin", "domain_name": "Default", "username": "admin", "password": "****************", "region": "RegionOne", "image_name": "cirros", "flavor": "m1.tiny", "insecure": "true", "source_image": "0f9b69ee-4e9f-4807-a7c4-6a58355c37b1", "communicator": "ssh", "ssh_keypair_name": "******************", "ssh_private_key_file": "~/.ssh/id_rsa", "ssh_username": "root" } ], "provisioners": [ { "type": "shell", "inline": [ "sleep 60" ] } ] } But upon running the script using packer build script.json I get the following error:
User:packer User$ packer build script.json openstack output will be in this color. 1 error(s) occurred: * ssh_private_key_file is invalid: stat ~/.ssh/id_rsa: no such file or directory My id_rsa is a file starting and ending with:
------BEGIN RSA PRIVATE KEY------ key ------END RSA PRIVATE KEY-------- Which I thought meant it was a PEM related file so I found this was weird so I made a pastebin of my PACKER_LOG:
Initial analysis tell me that the only error is a missing packerconfig file. Upon googling this the top searches tell me if it doesn't find one it defaults. Is this why it is not working?
Any help would be of great assistance. Apparently there are similar problems on the github support page () But I don't understand some of the solutions posted and if they apply to me.
I've tried to be as informative as I can. Happy to provide any information where I can!!
Thank you.
3 Answers
* ssh_private_key_file is invalid: stat ~/.ssh/id_rsa: no such file or directory The "~" character isn't special to the operating system. It's only special to shells and certain other programs which choose to interpret it as referring to your home directory.
It appears that OpenStack doesn't treat "~" as special, and it's looking for a key file with the literal pathname "~/.ssh/id_rsa". It's failing because it can't find a key file with that literal pathname.
Update the ssh_private_key_file entry to list the actual pathname to the key file:
"ssh_private_key_file": "/home/someuser/.ssh/id_rsa", Of course, you should also make sure that the key file actually exists at the location that you specify.
2Have to leave a post here as this just bit me… I was using a variable with ~/.ssh/id_rsa and then I changed it to use the full path and when I did… I had a space at the end of the variable value being passed in from the command line via Makefile which was causing this error. Hope this saves someone some time.
Kenster's answer got you past your initial question, but it sounds like from your comment that you were still stuck.
Per my reply to your comment, Packer doesn't seem to support supplying a passphrase, but you CAN tell it to ask the running SSH Agent for a decrypted key if the correct passphrase was supplied when the key was loaded. This should allow you to use Packer to build with a protect SSH key as long as you've loaded it into SSH agent before attempting the build.
The SSH communicator connects to the host via SSH. If you have an SSH agent configured on the host running Packer, and SSH agent authentication is enabled in the communicator config, Packer will automatically forward the SSH agent to the remote host.
The SSH communicator has the following options:
ssh_agent_auth (boolean) - If true, the local SSH agent will be used to authenticate connections to the remote host. Defaults to false.