Ask Your Question

for loop in HOT

asked 2013-12-17 18:14:32 -0500

kj-tanaka gravatar image

Is there a way to use for-loop in HOT? It would be great if we can do something like this.

resources: {% for host in ['node01','node02','node03'] %} {{ host }}: type: OS::Nova::Server properties: key_name: mykey image: ubuntu-12.04 flavor: m1.small {% endfor %}

Thanks and best regards, Koji

edit retag flag offensive close merge delete

3 answers

Sort by ยป oldest newest most voted

answered 2013-12-17 18:30:29 -0500

zaneb gravatar image

No, there isn't.

You can use an InstanceGroup to create a group of servers with the same config, but there's no way to vary e.g. their names in a controlled way. Of course you can generate your template with an external program using any language you like. We don't want to turn Heat itself into a programming language though.

edit flag offensive delete link more

answered 2013-12-17 18:39:49 -0500

shardy gravatar image

This idea has been discussed, there was even a PoC patch which would allow this sort of templating using jinja2 ( ), but currently the answer is no, this is not possible in HOT, and there are no immediate plans to add advanced templating or program-control primitives to HOT like for loops.

The issue is that we have to weigh up the advantages of adding functionality to the HOT DSL, over the complexity and ovehead involved in maintaining it (and as mentioned in the review above, security concerns in the case of some feature-rich templating engines)

For now, I would suggest you have a simple wrapper script which mechanically generates your template, this should be very simple, e.g in python or shell script.

edit flag offensive delete link more

answered 2013-12-17 19:31:02 -0500

kj-tanaka gravatar image

Thanks guys for your quick answers! I'll look into InstanceGroup, and write a script if needed.

edit flag offensive delete link more

Get to know Ask OpenStack

Resources for moderators

Question Tools

1 follower


Asked: 2013-12-17 18:14:32 -0500

Seen: 964 times

Last updated: Dec 17 '13