Hi,
Having a headache with provisioning with forge then installing git repo.
This is what I do.
- Spin up my own EC2 server.
- Use Forge API to create a custom server in Forge and obtain a provisioning script.
- SSH to the server (via code) and run the provisioning script.
- 10 Minutes later the server is provisioned
- Then I try to install git repo either via api or forge UI and it just wont work. It says
Cloning into 'default'...
Host key verification failed.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
The main problem I think.. is step 3. If I manually SSH into the server myself and then run the script, after provisioning is complete I can install the git repo via the forge UI or via API. Only when I use code to SSH and run the script it wont install the repo.
I think its really weird that it wont install, because the provisioning completes. It sends me an email as normal and in Github the deploy key is set up.
I am using phpseclib to SSH into my server code below:
// SSH to server
$key = new RSA();
$key->loadKey($myKeyFile);
$ssh = new SSH2($serverIp);
if(! $ssh->login('ubuntu', $key)) {
throw new Exception('SSH exception - unable to gain access to server via SSH');
}
// Execute provisioning script
$ssh->exec('the-script-obtained-from-forge-here');
This all executes and the server provisions. So what Am I doing wrong? I contacted Forge support and have been told to check my code, but i'm stuck. I cant understand why it will work when manully SSH but via phpseclib is doesn't.
If any anyone can help I will be really grateful.
Thanks.