Failed to connect to the host via ssh: No route to host

Problem to solve

Hello all,

I have created a pipeline in gitlab which deploys a virtual machine on Openstack using terraform. I use ansible resource to configure the deployed vm.
${openstack_networking_floatingip_v2.floatip.address} variable to fetch the floating ip address of the vm created as its not fixed every time I deploy a vm.

I have created a gitlab runner on same openstack to run the pipeline so that the deployed vms would be reachable.

I have attached ssh key pair which will be injected into the vms while its creation. Please note that key pair is of the gitlab runner vm (as the creation will be triggered/executed inside of the gitlab runner). I have also passed private key file while running the ansible script.

When I trigger the pipeline I get this error:

UNREACHABLE! => {“changed”: false, “msg”: “Failed to connect to the host via ssh: ssh: connect to host No route to host”, “unreachable”: true}

But when I manually login into the gitlab-runner vm I can SSH to the deployed vm which means the SSH key pair is fine and there is not authentication issue here.
The issue is pipeline job. Am I missing out something? some configuration in gitlab?

PS: gitlab is reachable to the opnstack


Terraform version 1.7
Virtual Machine Os Ubuntu 22 LTS
Ansible [core 2.15.9]

I apologise if I wrote something useless I am pretty new at this. Any suggestion is much required. Thanks in advance:)

for people who come across this type of error I solved it by adding delay or “sleep 60” before firing the ansible script.
PS: I did not continue this method as provisioner from terraform triggered some unexpected situations and made the ci pipeline unstable and unpredictable.
I separated the deploying and provisioning stage in the pipeline. Hope this helps

1 Like