Ansible Playbook- Pass variables in for loop
<p>I am trying to create tomcat cluster based on number of hosts, and I am trying to pass variables to a for loop in template file.</p>

<p>I want to control <code>num_hosts</code> from variables.</p>

<p>The template file snippet is:</p>

<pre><code>{% for id in range(1,( {{ num_hosts }} )) %}
    &lt;Member
       className="org.apache.catalina.tribes.membership.StaticMember"
       port="4110"
       host="${test.server.web.other{{ id }}.fqdn}"
       domain="delta-static"
    /&gt;
{% endfor %}
</code></pre>

<p>Got the below error</p>

<pre><code>fatal: [test-web01.aliceapp.com]: FAILED! =&gt;
{"changed": false,
"failed": true,
"invocation": {"module_args": {"dest": "/home/tomcat/apache-tomcat/conf/server.xml", "src": "test/server.j2"}, "module_name": "template"},
"msg": "AnsibleError: an unexpected type error occurred. Error was an integer is required"}
</code></pre>

<p>I have tried multiple combination of syntaxes, bot none of them are working.</p>