How to include and reference a custom ssh key in a vagrant base (baseline) box? (virtualbox) - ssh

In vagrant documentation i did not found a hint on how to reference an included file from a included Vagrantfile within the same baseline box when using "vagrant package". Can anyone help?
Details:
When creating a new baseline box from scratch for vagrant, you are free to use the standard vagrant insecure ssh key or to create a custom new key. I did the last thing. And this new baseline box works fine with my custom key, when i use my Vagrantfile with this additional line:
config.ssh.private_key_path = "custom_key_file"
Now i decided to distribute my baseline box to my team members. Thats no problem. Just enter:
vagrant package --output custom.box
All other team members do copy the "custom_key_file" to the project root dir and create a "Vagrantfile" with this content (done using a version controll system):
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "custombox"
config.ssh.private_key_path = "custom_key_file"
end
When done, each team member enter the following to get a virtual machine based on custom.box fast and easy:
vagrant box add custombox custom.box
vagrant up
Works fine.
Now i want to tune my baseline box a little bit before distributing. I want to include the "custom_key_file" and a "Vagrantfile.pkg" that reads as follows:
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "custombox"
config.ssh.private_key_path = "custom_key_file"
end
To create the tuned baseline box i enter:
vagrant package --output custom2v.box --vagrantfile Vagrantfile.pkg --include custom_key_file
When i extract the custom2v.box i can see there is this tree:
C:.
│ box-disk1.vmdk
│ box.ovf
│ Vagrantfile
│
└───include
custom_key_file
_Vagrantfile
And "include/_Vagrantfile" has the content of my Vagrantfile.pkg. I can add that box as follows:
vagrant box add custombox2v custom2v.box
to a new project it is now very easy to enable it for vagrant. Just add a "Vagrantfile" read as follows:
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "custombox2v"
end
But when i do a:
vagrant up
i get the following error message:
[...]
Bringing machine 'default' up with 'virtualbox' provider...
There are errors in the configuration of this machine. Please fix
the following errors and try again:
SSH:
* `private_key_path` file must exist: custom_key_file
Can anyone help?

The reason is Vagrant's load order and merging of its configs.
What you want to happen is Vagrant to use the private key located inside the box archive.
What really happens when you run "up" is Vagrant merges your config with few others configs on its "load & merge" path.
So in the end of the way you have one big config with the setting:
config.ssh.private_key_path = "custom_key_file"
So Vagrant will look for custom_key_file in the same folder as your Vagrantfile and that's why you get your error.
Check this answer and this issue for information how to config Vagrant to look for the key relatively to box's Vagrantfile.

Related

Odoo custom addon_path not found

I setup a clean Debian 10 vps, launch this setup script
https://raw.githubusercontent.com/Yenthe666/InstallScript/14.0/odoo_install_debian.sh
and all seems is correctly installed
I can't get the /odoo/custom/addons folder to work
Odoo Enterprise
This is the /etc/odoo-server.conf
[options]
; This is the password that allows database operations:
admin_passwd = xxxxxxxxxx
xmlrpc_port = 8069
logfile = /var/log/odoo/odoo-server.log
addons_path = /odoo/enterprise/addons,/odoo/odoo-server/addons,/odoo/custom/addons
proxy_mode = True
then
service odoo-server restart
checking on the log the directory is found
2020-11-18 09:32:46,144 4683 INFO ? odoo: addons paths: ['/odoo/odoo-server/odoo/addons',
'/odoo/.local/share/Odoo/addons/14.0', '/odoo/enterprise/addons', '/odoo/odoo-server/addons',
'/odoo/custom/addons']
All modules inside /odoo/custom/addons have correct permissions "odoo:odoo" and 755
Activated developer mode with assets
In apps menu clicked on update module list
New addon doesn't show in App list... :(
Same addon here /odoo/odoo-server/addons works
Before all things, change permissions using:
sudo chmod -R odoo:odoo /added_path_of_addons/
Stop server using:
sudo /etc/init.d/odoo-server stop
Then restart it again:
sudo /etc/init.d/odoo-server start
pic1:
enter image description here
pic1 stop and start servise odoo after check pic2
odoo---server---odoo.conf---addons_path:Give the address your module want
enter image description here

vagrant ssh uses wrong ssh executable

I have a vagrant box with CentOS7 running under KVM/QEMU (libvirt) on my Fedora 29 host. vagrant up works fine. vagrant ssh fails with:
/usr/share/vagrant/gems/gems/vagrant-2.1.2/lib/vagrant/util/safe_exec.rb:39:
in `exec': : Permission denied - /home/username/bin/sshPermission denied - /home/username/bin/ssh ( (Errno::EACCESErrno::EACCES)
The doc says: Vagrant will attempt to use the local SSH client installed on the host machine. However, which ssh correctly results in: /usr/bin/ssh. So why vagrant doesn't use it ?
The directory! /home/username/bin/ssh was included in the PATH env when the box was created and vagrant seems to have stored this information somewhere. Removing the directory from PATH didn't help. Only when I rename or remove the directory vagrant ssh does work.
Can anyone tell me where vagrant stored the wrong info ?
Edit: The Vagrantfile is nearly empty, only config.vm.box contained...
Guess I found the reason - seems to be a bug or strange behavior of the vagrant version 2.1.2 that I use:
I still had directory /home/username/bin in the PATH env. Vagrant seems to list all entries in all directories included in PATH to look for ssh and finds subdirectory /home/username/bin/ssh not realizing that this is a directory ...
After removing /home/username/bin the command vagrant ssh works as expected. So unless vagrant is improved I have to permanently rename my /home/username/bin/ssh directory ...

Running a command on a vagrant box via ssh keeps asking for a password

I am trying to run a command on/in a vagrant box using ssh.
According to the documentation, vagrant ssh -c <command> should connect to the machine via ssh and run the command.
I tried this using a simple Ubuntu Server 16.04 box, but every time I get prompted for a password. Simply running vagrant ssh allows me to connect without providing a password.
I used the following Vagrantfile:
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "osslack/ubuntu-server-16.04-no-unattended-upgrades"
config.vm.box_version = "1.0"
end
I tried to test it with the following command: vagrant ssh -c "ls".
How can I run a command via ssh without being prompted for a password?
So, after playing around with it some more, I found a workaround/solution.
When using vagrant ssh, anything after -- will be directly passed to ssh.
So running vagrant ssh -- ls will tell ssh to run the command ls.
This does not prompt for a password.

Vagrant up can't find private_key_path

When I try to run vagrant up I get the error:
There are errors in the configuration of this machine. Please fix
the following errors and try again:
SSH:
* `private_key_path` file must exist: /home/buildbot/mykey.pem
However, this file definitely exists. If I run ls -lah /home/buildbot/mykey.pem, it's there. It's owned by my user "buildbot". It has the right permissions. Everything looks good, but yet Vagrant can't see it, even though it's running as user "buildbot". Why would this be?
My Vagrantfile is a fairly generic one for AWS:
# -*- mode: ruby -*-
# vi: set ft=ruby :
require 'vagrant-aws'
Vagrant.configure(2) do |config|
config.vm.box = 'aws-dummy'
config.vm.provider :aws do |aws, override|
aws.keypair_name = 'my-key-pair'
aws.security_groups = ['my-security-group']
aws.access_key_id = ENV['AWS_ACCESS_KEY']
aws.secret_access_key = ENV['AWS_SECRET_KEY']
aws.ami = 'ami-43c92455'
override.ssh.username = 'ubuntu'
override.ssh.private_key_path = ENV['AWS_PRIVATE_KEY_PATH']
end
end

Vagrant was unable to communicate with the guest machine

Im on Ubuntu 12.04 and my Vagranfile looks like this:
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "base"
config.vm.box_url = "http://cloud-images.ubuntu.com/vagrant/precise/current/precise-server-cloudimg-amd64-vagrant-disk1.box"
config.vm.network :forwarded_port, guest: 80, host: 8080
config.vm.provision :puppet do |puppet|
puppet.manifests_path = "puppet/manifests"
puppet.module_path = "puppet/modules"
puppet.manifest_file = "init.pp"
puppet.options="--verbose --debug"
end
end
This was supposed to be running fine, the same configuration works OK in my macbook.
Im using Vagrant 1.3.5 a VirtualBox 4.1.12 (but before I tried with 4.2.18)
I dont know how to fix this, I've been stuck for days now. Any help will be great.
Make sure you have a proper version of GuestAdditions. Or just use vagrant-vbguest plugin that will check and install it for you. In fact, it is must have plugin if you are using VirtualBox.
Try to increase config.ssh.timeout (default: 5 min.)
This is not really an answer, rather possible ways of solving. There is an open issue on vagrant.
This is a Vagrant bug that should be fixed in next version.
So far just make sure that the ~/vagrant.d/insecure_private_key file is owned by the same user that starts Vagrant, and has permissions 600, this should help.