How to use a variable I created in a jinja2 template within playbook?

Hi,

I have something like this in a templates/file.j2 file (happens to be a kafka broker config):

Sure, you can use set_fact to set it as a task then it will be available for subsequent tasks and when templating.

Here’s how I build up the list of zookeeper hosts to pass to solrcloud. I’m not using private ips but should be adaptable to your situation.

`

  • name: set fact zookeeper hosts
    set_fact:
    zk_hosts: “{{ groups[‘zookeeper’] | join(':” ~ zookeeper_client_port ~ ‘,’) }}:{{ zookeeper_client_port }}"
    `

Hope this helps,

Jon