diff --git a/changelogs/fragments/vmware_guest.yaml b/changelogs/fragments/vmware_guest.yaml new file mode 100644 index 00000000000..652444af7fa --- /dev/null +++ b/changelogs/fragments/vmware_guest.yaml @@ -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. diff --git a/lib/ansible/modules/cloud/vmware/vmware_guest.py b/lib/ansible/modules/cloud/vmware/vmware_guest.py index 8461d3ba811..a76fab86e36 100644 --- a/lib/ansible/modules/cloud/vmware/vmware_guest.py +++ b/lib/ansible/modules/cloud/vmware/vmware_guest.py @@ -229,6 +229,12 @@ options: - "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. @@ -419,6 +425,7 @@ EXAMPLES = r''' 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 @@ -2514,7 +2521,7 @@ class PyVmomiHelper(PyVmomi): 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) @@ -2695,21 +2702,6 @@ class PyVmomiHelper(PyVmomi): 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): - 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) @@ -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), @@ -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