Repository: ansible/ansible

Issue:
ovirt_templates: wait parameter is ignored
##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
ovirt_templates

##### ANSIBLE VERSION
<!--- Paste verbatim output from "ansible --version" between quotes below -->
```
ansible 2.3.2.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides
  python version = 2.7.5 (default, May  3 2017, 07:55:04) [GCC 4.8.5 20150623 (Red Hat 4.8.5-14)]
```

##### CONFIGURATION
default
<!---
If using Ansible 2.4 or above, paste the results of "ansible-config dump --only-changed"

Otherwise, mention any settings you have changed/added/removed in ansible.cfg
(or using the ANSIBLE_* environment variables).

-->

##### OS / ENVIRONMENT
rhel 7.4
<!---
Mention the OS you are running Ansible from, and the OS you are
managing, or say "N/A" for anything that is not platform-specific.
Also mention the specific version of what you are trying to control,
e.g. if this is a network bug the version of firmware on the network device.
-->

##### SUMMARY
<!--- Explain the problem briefly -->
Importing template from export storage domain with parameter wait: yes
wait parameter is ignored

##### STEPS TO REPRODUCE
<!---
For bugs, show exactly how to reproduce the problem, using a minimal test-case.
For new features, show how the feature would be used.
-->

<!--- Paste example playbooks or commands between quotes below -->
```yaml
    - name: import template
      ovirt_templates:
        state: imported
        name: exported_template
        export_domain: export
        storage_domain: storage
        cluster: Default
        auth: "{{ovirt_auth}}"
        wait: yes
```



Discussion:
cc @machacekondra @mwperina
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->

Resolving patch:
diff --git a/lib/ansible/module_utils/ovirt.py b/lib/ansible/module_utils/ovirt.py
--- a/lib/ansible/module_utils/ovirt.py
+++ b/lib/ansible/module_utils/ovirt.py
@@ -746,14 +746,14 @@ def action(
             'diff': self._diff,
         }
 
-    def wait_for_import(self):
+    def wait_for_import(self, condition=lambda e: True):
         if self._module.params['wait']:
             start = time.time()
             timeout = self._module.params['timeout']
             poll_interval = self._module.params['poll_interval']
             while time.time() < start + timeout:
                 entity = self.search_entity()
-                if entity:
+                if entity and condition(entity):
                     return entity
                 time.sleep(poll_interval)
 
diff --git a/lib/ansible/modules/cloud/ovirt/ovirt_templates.py b/lib/ansible/modules/cloud/ovirt/ovirt_templates.py
--- a/lib/ansible/modules/cloud/ovirt/ovirt_templates.py
+++ b/lib/ansible/modules/cloud/ovirt/ovirt_templates.py
@@ -351,7 +351,10 @@ def main():
                     ) if module.params['cluster'] else None,
                     **kwargs
                 )
-                template = templates_module.wait_for_import()
+                # Wait for template to appear in system:
+                template = templates_module.wait_for_import(
+                    condition=lambda t: t.status == otypes.TemplateStatus.OK
+                )
                 ret = {
                     'changed': True,
                     'id': template.id,


Test patch: