Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable changing the timeout of wait_for_ip_address #63557

Merged
merged 1 commit into from
Oct 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelogs/fragments/vmware_guest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
minor_changes:
- Added a timeout parameter `wait_for_ip_address_timeout` for `wait_for_ip_address` for longer-running tasks in vmware_guest.
27 changes: 10 additions & 17 deletions lib/ansible/modules/cloud/vmware/vmware_guest.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,12 @@
- "vmware-tools needs to be installed on the given virtual machine in order to work with this parameter."
default: 'no'
type: bool
wait_for_ip_address_timeout:
description:
- Define a timeout (in seconds) for the wait_for_ip_address parameter.
default: '300'
type: int
version_added: '2.10'
wait_for_customization:
description:
- Wait until vCenter detects all guest customizations as successfully completed.
Expand Down Expand Up @@ -419,6 +425,7 @@
netmask: 255.255.255.0
device_type: vmxnet3
wait_for_ip_address: yes
wait_for_ip_address_timeout: 600
delegate_to: localhost
register: deploy_vm

Expand Down Expand Up @@ -2514,7 +2521,7 @@ def deploy_vm(self):
set_vm_power_state(self.content, vm, 'poweredon', force=False)

if self.params['wait_for_ip_address']:
self.wait_for_vm_ip(vm)
wait_for_vm_ip(self.content, vm, self.params['wait_for_ip_address_timeout'])

if self.params['wait_for_customization']:
is_customization_ok = self.wait_for_customization(vm)
Expand Down Expand Up @@ -2695,21 +2702,6 @@ def wait_for_task(self, task, poll_interval=1):
time.sleep(poll_interval)
self.change_applied = self.change_applied or task.info.state == 'success'

def wait_for_vm_ip(self, vm, poll=100, sleep=5):
garwil marked this conversation as resolved.
Show resolved Hide resolved
ips = None
facts = {}
thispoll = 0
while not ips and thispoll <= poll:
newvm = self.get_vm()
facts = self.gather_facts(newvm)
if facts['ipv4'] or facts['ipv6']:
ips = True
else:
time.sleep(sleep)
thispoll += 1

return facts

def get_vm_events(self, vm, eventTypeIdList):
byEntity = vim.event.EventFilterSpec.ByEntity(entity=vm, recursion="self")
filterSpec = vim.event.EventFilterSpec(entity=byEntity, eventTypeId=eventTypeIdList)
Expand Down Expand Up @@ -2764,6 +2756,7 @@ def main():
esxi_hostname=dict(type='str'),
cluster=dict(type='str'),
wait_for_ip_address=dict(type='bool', default=False),
wait_for_ip_address_timeout=dict(type='int', default=300),
state_change_timeout=dict(type='int', default=0),
snapshot_src=dict(type='str'),
linked_clone=dict(type='bool', default=False),
Expand Down Expand Up @@ -2834,7 +2827,7 @@ def main():
if tmp_result['changed']:
result["changed"] = True
if module.params['state'] in ['poweredon', 'restarted', 'rebootguest'] and module.params['wait_for_ip_address']:
wait_result = wait_for_vm_ip(pyv.content, vm)
wait_result = wait_for_vm_ip(pyv.content, vm, module.params['wait_for_ip_address_timeout'])
if not wait_result:
module.fail_json(msg='Waiting for IP address timed out')
tmp_result['instance'] = wait_result
Expand Down