From d94f9bdd8db5c163b8808f5bc9791dc976b37628 Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Mon, 6 Feb 2017 23:14:31 +0100 Subject: [PATCH] cloudstack: ensure we select a template compatible with disksize (#21058) When the user specify a root disk size, the template image must be smaller than the specified root disk size. --- lib/ansible/modules/cloud/cloudstack/cs_instance.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/ansible/modules/cloud/cloudstack/cs_instance.py b/lib/ansible/modules/cloud/cloudstack/cs_instance.py index 0ae1d2e8ca6..a2879a5d850 100644 --- a/lib/ansible/modules/cloud/cloudstack/cs_instance.py +++ b/lib/ansible/modules/cloud/cloudstack/cs_instance.py @@ -477,14 +477,20 @@ class AnsibleCloudStackInstance(AnsibleCloudStack): if self.template: return self._get_by_key(key, self.template) + rootdisksize = self.module.params.get('root_disk_size') args['templatefilter'] = self.module.params.get('template_filter') templates = self.cs.listTemplates(**args) if templates: for t in templates['template']: if template in [ t['displaytext'], t['name'], t['id'] ]: + if rootdisksize and t['size'] > rootdisksize*1024**3: + continue self.template = t return self._get_by_key(key, self.template) - self.module.fail_json(msg="Template '%s' not found" % template) + more_info = "" + if rootdisksize: + more_info = " (with size <= %s)" % rootdisksize + self.module.fail_json(msg="Template '%s' not found%s" % (template, more_info)) elif iso: if self.iso: