Skip to content

Commit c141df9

Browse files
committed
Add waiting for vm to be ready up to 3 mins
1 parent 25b45db commit c141df9

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

ansible/playbook-gcp-vm-create.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,8 @@
7878
[gcp]
7979
{{ external_ip }} ansible_user={{ ansible_user }} ansible_ssh_private_key_file=~/.ssh/id_rsa
8080
dest: /tmp/inventory.ini
81+
82+
- name: Wait for SSH on the provisioned VM
83+
import_tasks: ansible/tasks/task-vm-check-ready.yaml
84+
vars:
85+
wait_for_ssh_on: "{{ external_ip }}"
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
- name: Wait for SSH to become available on target host
2+
block:
3+
- name: 🔍 Check SSH port on {{ wait_for_ssh_on }}
4+
ansible.builtin.wait_for:
5+
host: "{{ wait_for_ssh_on }}"
6+
port: 22
7+
timeout: 10
8+
state: started
9+
register: ssh_wait_result
10+
retries: 18
11+
delay: 10
12+
until: ssh_wait_result is succeeded
13+
14+
- name: SSH is now available on {{ wait_for_ssh_on }}
15+
ansible.builtin.debug:
16+
msg: "SSH is ready on {{ wait_for_ssh_on }}"
17+
18+
rescue:
19+
- name: SSH not ready after 3 minutes
20+
ansible.builtin.fail:
21+
msg: "Failed to connect to {{ wait_for_ssh_on }} on port 22 after 3 minutes"

0 commit comments

Comments
 (0)