Skip to content

Instantly share code, notes, and snippets.

@sheldonh
Last active July 27, 2023 21:02
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save sheldonh/7203512 to your computer and use it in GitHub Desktop.
Save sheldonh/7203512 to your computer and use it in GitHub Desktop.
Wait for SSH to come up in an Ansible playbook
---
- hosts: demo
tags: wait
gather_facts: no
tasks:
- name: Wait for SSH
local_action: wait_for port=22 host={% if ansible_ssh_host is defined %}{{ ansible_ssh_host }}{% else %}{{ inventory_hostname }}{% endif %}
@chrisshroba
Copy link

Thanks for this! New to ansible and didnt't realize gather_facts: no existed!

@berendt
Copy link

berendt commented Sep 23, 2018

@manicmonkey
Copy link

FYI I just found some awesome syntax which simplifies your host variable:
{{ ansible_ssh_host|default(inventory_hostname) }}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment