Generating hostgroups based on String array


I’m trying something like:

for (var dcname in [“dc1”,“dc2”, “dc3”]) {
object HostGroup “dc-” + dcname {
display_name = “DC” + dcname
assign where dcname == host.vars.dc

Unfortunately, it is not working with: "Tried to access undefined script variable ‘dcname’ "

I tried lambda function with the usage of the command use(dcname) :
display_name = {{ use(dcname) “DC” + dcname }}
and I got the error: " Error: syntax error, unexpected use (T_USE), expecting }} (T_NULLARY_LAMBDA_END)

So, I missed something, but I don’t know what yet, someone may have an idea?
Best regards

Hello Franck,


misses a use(dcname) just before the {.