-1

I want to pass multiple ip list and same port in single variable using ansible jinja. I want output in configuration file like this.

value=["10.0.0.1:8200", "10.0.0.1:8200", "10.0.0.1:8200", "10.0.0.1:8200"]

or if I can pass ["10.0.0.1:8200", "10.0.0.1:8200", "10.0.0.1:8200", "10.0.0.1:8200"] in single variable?

matku
  • 1
  • 1
  • could you show your playbook, because what you ask is not very clear – Frenchy Jul 04 '22 at 07:13
  • Hi thanks frenchy for ur reply. my question is i wanna just pass a variable in var.yml file. ip_address: in this variable wanna give multiple ip address. and wanna use this variable in template jinja file. where i wanna take output like this value=["10.0.0.1:8200", "10.0.0.1:8200", "10.0.0.1:8200", "10.0.0.1:8200"] – matku Jul 04 '22 at 07:26
  • you want to create a var.yml from your template and in your var.yml you want to have value=["10.0.0.1:8200", "10.0.0.1:8200", "10.0.0.1:8200", "10.0.0.1:8200"] ? – Frenchy Jul 04 '22 at 07:51
  • You do not pass variable to template in Ansible, like in a MVC. All variables available to the playbook are available to the template. So, the answer is yes. But without any example playbook or task, there is not much more someone can do to help you. – β.εηοιτ.βε Jul 04 '22 at 07:51

1 Answers1

0

I got the answer i printed the array value. its working fine.

value= {% for i in range(0, ip_address|count,5) %}
       ["{{ ip_address[i] }}:{{ port_no }}", "{{ ip_address[i+1] }}:{{ port_no }}","{{ ip_address[i+2] }}:{{ port_no }}","{{ ip_address[i+3] }}:{{ port_no }}","{{ ip_address[i+4] }}:{{ port_no }}"]
Frenchy
  • 16,386
  • 3
  • 16
  • 39
matku
  • 1
  • 1
  • Hi can we define variable value in var.yml and can make loop changes according variable value but out put should be in same form. ["10.0.0.1:8200", "10.0.0.2:8200", "10.0.0.3:8200", "10.0.0.4:8200"] so on... we can not take output in list. it should be in row format. – matku Jul 06 '22 at 06:35