vagrant のプロビジョニングでgit cloneがSSHの認証エラーになる

f:id:orangeclover:20151003210200j:plain

やりたいこと

初回のvagrant up、vagrant up --provision、vagrant provisionでの
プロビジョニングでgithubやbitbucketからクローンしたい。

が、エラーになってしまう。
vagrant sshでログインしてからのgit cloneは成功する。
provisionでやろうとするとエラーになる。
なんかWindows版のバグ踏んでるんだろうか。。。
ホストがWindowsでうまくいってる方がいたら教えて下さい。

エラー

==> default: Cloning into '/path/to/repository'...
==> default: Error reading response length from authentication socket.
==> default: Permission denied (publickey).
==> default: f
==> default: atal:
==> default: C
==> default: ould not read from remote repository.
==> default:
==> default: Please make sure you have the correct access rights
==> default: and the repository exists.
The SSH command responded with a non-zero exit status. Vagrant
assumes that this means the command failed. The output for this command
should be in the log above. Please read the output to determine what
went wrong.

vagrantfile

Vagrant provision でも SSH Agent Forwarding するを参考に、 forward_agent、privileged、StrictHostKeyCheckingの設定をしている。

config.ssh.forward_agent = true
config.vm.provision "shell",privileged: false, inline: <<-SHELL
    sudo apt-get install -y git-core
    echo -e "Host bitbucket.org" > ~vagrant/.ssh/config
    echo -e "    StrictHostKeyChecking no" >> ~vagrant/.ssh/config
    git clone git@bitbucket.org:path/to/private/repository /path/to/repository 
SHELL

手順

$ eval `ssh-agent`
$ ssh-add ~/.ssh/id_rsa.bitbucket.org
$ vagrant up --provision

確認したこと

privileged

provisionでidコマンドを実行すると以下になっているので、privilegedの設定は有効になっていて vagrantユーザーで動作してる。

 ==> default: uid=1001(vagrant) gid=1001(vagrant) groups=1001(vagrant)

SSH Agent Fowrdingの設定

vagrant sshでログインしてからgit cloneするとパスワード入力せずに認証できるから、設定は問題ない。

remote: Counting objects: 17370, done.
remote: Compressing objects: 100% (11174/11174), done.

provisionでssh-add -lを実行するとエラーになってる

    Error reading response length from authentication socket.

環境