From ea05035be248b944ae0776e230f9affb2fe85cd0 Mon Sep 17 00:00:00 2001 From: Luca Lorenzetto Date: Thu, 26 Oct 2017 15:12:34 +0200 Subject: [PATCH] Use latest available template (#31780) * Use latest available template Documentation states: template_version: version number of the template to be used for VM. By default the latest available version of the template is used. This was not true because if parameter was not specified, template[0] is choosen, without checking if is the latest. Now, sorting + selecting the latest selects the one with the latest version number. * Sort in reverse order, style cleanup Applied fixes from comment --- lib/ansible/modules/cloud/ovirt/ovirt_vms.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ansible/modules/cloud/ovirt/ovirt_vms.py b/lib/ansible/modules/cloud/ovirt/ovirt_vms.py index dd733eb323..d21e336c8b 100644 --- a/lib/ansible/modules/cloud/ovirt/ovirt_vms.py +++ b/lib/ansible/modules/cloud/ovirt/ovirt_vms.py @@ -607,7 +607,7 @@ class VmsModule(BaseModule): self.param('template_version') ) ) - template = templates[0] + template = sorted(templates, key=lambda t: t.version.version_number, reverse=True)[0] return template