Too many retries waiting for SSH to be available. Last error: Maximum number of retries (60) exceeded

Hi all,
I have been battling this issue for a while and all the solutions I found online don’t seem to work
I keep getting

Waiting for machine to be running, this may take a few minutes...
Detecting operating system of created instance...
Waiting for SSH to be available...
Error creating machine: Error detecting OS: Too many retries waiting for SSH to be available.  Last 
error: Maximum number of retries (60) exceeded
Exited with code 1

I tried recreating the image and it works, I also checked the status of the container and it is running
ssh keys have no passphrase

What are some quick steps I can take do debug this?

Config.yml

    version: 2
    jobs:
      build:
        machine: true
        working_directory: ~/appapi
        steps:
          - checkout
          - run:
              name: Run tests
              command: |
                docker-compose -f local.yml up -d
                docker-compose -f local.yml run django python manage.py help
                docker-compose -f local.yml run django pytest
      deploy:
        machine: true
        working_directory: ~/appapi
        steps:
          - checkout
          - add_ssh_keys:
              fingerprints:
                f1:40:**:^**
          - run:
              name: Deploy Master to Digital Ocean
              command: |
                cp ./id_rsa_f140****.pub ~/.ssh
                ls -al ~/.ssh
                base=https://github.com/docker/machine/releases/download/v0.14.0 &&
                curl -L $base/docker-machine-$(uname -s)-$(uname -m) >/tmp/docker-machine &&
                sudo install /tmp/docker-machine /usr/local/bin/docker-machine
                mkdir -p .envs/.production
                docker-machine create --driver generic --generic-ip-address *8.**.**.** --generic-ssh-key ~/.ssh/id_rsa_f1404ab app
                export COMPOSE_TLS_VERSION=TLSv1_2
                eval "$(docker-machine env app)"
                docker-compose -f production.yml build
                docker-compose -f production.yml up -d

    workflows:
      version: 2
      build-and-deploy:
        jobs:
          - build
          - deploy:
              requires:
                - build

Is this invoking the post-build SSH feature in CircleCI?

Or are you trying to create an SSH tunnel to your deploy server?

1 Like

Creating an ssh tunnel to the deploy server.

        Creating CA: /home/circleci/.docker/machine/certs/ca.pem
        Creating client certificate: /home/circleci/.docker/machine/certs/cert.pem
        Running pre-create checks...
        Creating machine...
        (appapi) Importing SSH key...
        Waiting for machine to be running, this may take a few minutes...
        Detecting operating system of created instance...
        Waiting for SSH to be available...
        Error creating machine: Error detecting OS: Too many retries waiting for SSH to be available.  Last error: Maximum number of retries (60) exceeded
        Exited with code 1

Builds work fine, tests run.
been getting stuck here of the past 3 days

Which of your steps is initiating the SSH connection?

To debug this, I would request a post-build SSH session in the CircleCI control panel, from where you can try a manual SSH outbound connection. I would guess that your target server does not have port 22 open, or maybe it does not have an SSH server running.

I am able to login using ssh docker-machine ssh machine-name.
Does that count?

I’m not familiar with docker-machine, but yes, if you can successfully run that inside a CircleCI post-build SSH session (i.e from the CircleCI build servers) then yes, that would count. Have you done that?

Yes I was able to do that a well, reran the build with ssh, I was able to ssh from there

OK, great - so I guess your task is to work out what the difference is between CircleCI running an ordinary build (where it does not work) and CircleCI letting you run the build manually in an SSH session.

Does Docker Machine need some time to settle down? I wonder if doing a sleep of a few seconds prior to doing the SSH command would help? (I don’t use DM, as I mentioned, so I am a bit hampered in my assistance - but that is where I would start myself).