Reputation: 6383
I require my SSH keys during provisioning to authorize git clones from our git repo. So I added this to VagrantFile:
config.ssh.forward_agent = true
In the provision script we have something like:
# this will prevent the yes/no security prompt
echo -e "Host gitlab.ourdomain.com\n\tStrictHostKeyChecking no\n" >> /home/vagrant/.ssh/config
# clone the repo
git clone --branch devel [email protected]:sso/mwauth.git website
On vagrant up
I see this in the terminal:
Cloning into 'website'...
Host key verification failed.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
..however, when I then vagrant ssh
into the vagrant instance and manually run the same clone command, it clones the remote repo and no prompt. Are keys only passed with vagrant ssh
but no available during provisioning?
Upvotes: 1
Views: 416
Reputation: 53703
The issue is that you add the ssh key for vagrant user but you run the provisioning as root user so when you clone the root user does not have the key, and when you vagrant ssh
into your box you're logged with vagrant user.
you can add privileged: false
when you run your provisioning, something like
config.vm.provision "shell", privileged: false, path: "script.sh"
or running as other user
su -l vagrant "git clone --branch devel [email protected]:sso/mwauth.git website"
Upvotes: 1