Ansible WinRM wait

So, with one of the projects that I’m working on, we have to remotely configure a Windows server. This involves using WinRM, instead of SSH.

During one part of the playbook, we bring up a server in EC2 using the “ec2” module with the “wait” option set to true. However, even when this returns and EC2 considers the machine “up”, it’s still unresponsive when you try to login using WinRM. This was causing the next task to fail with a timeout.

The first attempt at getting this to work, looked like this:

- name: Check connectivity to the machine
  win_ping: data="winpong"
  register: winping_result
  until: winping_result | success
  retries: 100
  delay: 20

The above however, doesn’t actually work and in fact errors out with a timeout the first time that it’s run through the loop.

After a bit more research, the correct way to do the above in Ansible is:

- name: Wait for machine to come up
  local_action: wait_for port=5986 host="{{ inventory_hostname }}" delay=270

Where “inventory_hostname” will be replaced by the hostname of the current machine that the task is working on.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.