# wait\_for esxi host to be available in vcenter an exist mateinance mode

**URL:** <https://forum.ansible.com/t/wait-for-esxi-host-to-be-available-in-vcenter-an-exist-mateinance-mode/38100>\
**Category:** Ansible Project\
**Created:** [June 13, 2023, 8:37pm UTC](https://forum.ansible.com/t/wait-for-esxi-host-to-be-available-in-vcenter-an-exist-mateinance-mode/38100 "2023-06-13T20:37:21Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tony\_Wong](https://avatars.discourse-cdn.com/v4/letter/t/3ab097/32.png) [@Tony\_Wong](https://forum.ansible.com/u/Tony_Wong)\
**Post date:** [June 13, 2023, 8:37pm UTC](https://forum.ansible.com/t/wait-for-esxi-host-to-be-available-in-vcenter-an-exist-mateinance-mode/38100/1 "2023-06-13T20:37:21Z")

</div>

I got this pb. In stead of waiting for port 443 available. I need to have it shows as available or back in a connected state or in maintenance mode in vcenter then exit maintenance mode. any idea how?

- name: test

hosts: all

gather\_facts: no

vars\_files:

- vcenter\_creds.yml

- vars.yml

tasks:

- name: Enable SSH service

vmware\_host\_service\_manager:

hostname: ‘{{ vcenter\_hostname }}’

username: ‘{{ vcenter\_admin }}’

password: ‘{{ vcenter\_admin\_pass }}’

esxi\_hostname: “{{ inventory\_hostname }}”

validate\_certs: no

state: present

service\_name: “TSM-SSH”

delegate\_to: localhost

- name: Esxcli

shell:

cmd: ‘{{ cmd }}’

register: esxcli\_output

- name: Display esxcli output

debug:

var: esxcli\_output.stdout\_lines

- name: Reboot ESXi host

vmware\_host\_powerstate:

hostname: ‘{{ vcenter\_hostname }}’

username: ‘{{ vcenter\_admin }}’

password: ‘{{ vcenter\_admin\_pass }}’

esxi\_hostname: “{{ inventory\_hostname }}”

validate\_certs: no

state: reboot-host

delegate\_to: localhost

- name: Wait for ESXi host to become available

wait\_for:

host: “{{ inventory\_hostname }}”

port: 443

delay: 10

timeout: 300

state: started

delegate\_to: localhost
