I know this is 2 year old thread, but I bumped into this today and was able to create a dictionary. Something like this:
/tmp $ cat example.yml - hosts: 127.0.0.1 vars: app_servers: 5 ipaddress_base: "192.168.0" rmi_portbase: 10000 host_info: | {% set res = [] -%} {%- for number in range(1,app_servers + 1) -%} {% set ignored = res.extend([{ 'hostname': 'app' + number|string, 'ipaddress': ipaddress_base + '.' + number|string, 'rmi_port': rmi_portbase|int + ( number * 10) }]) -%} {%- endfor %} {{ res }} tasks: - debug: var=host_info /tmp $ ansible-playbook example.yml [WARNING]: provided hosts list is empty, only localhost is available PLAY [127.0.0.1] *************************************************************** TASK [setup] ******************************************************************* ok: [127.0.0.1] TASK [debug] ******************************************************************* ok: [127.0.0.1] => { "host_info": [ { "hostname": "app1", "ipaddress": "192.168.0.1", "rmi_port": 10010 }, { "hostname": "app2", "ipaddress": "192.168.0.2", "rmi_port": 10020 }, { "hostname": "app3", "ipaddress": "192.168.0.3", "rmi_port": 10030 }, { "hostname": "app4", "ipaddress": "192.168.0.4", "rmi_port": 10040 }, { "hostname": "app5", "ipaddress": "192.168.0.5", "rmi_port": 10050 } ] } PLAY RECAP ********************************************************************* 127.0.0.1 : ok=2 changed=0 unreachable=0 failed=0 On Friday, April 10, 2015 at 4:46:45 AM UTC+5:30, Brian Coca wrote: > > The answer is that neither returns what you think it does, both return > a string, the issue is that with some fields they expect a string or > array or array in string (which then they split with , to get a real > array). Fields that expect dicts do not do any magic nor expect > strings at any point. > > > -- > Brian Coca > -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscr...@googlegroups.com. To post to this group, send email to ansible-project@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/d994ba77-702a-4964-ba12-8273df350f40%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.