I'm trying to write a json file with a list of ip addresses formatted as "http://{ip_address}:{port}" as a part of an ansible playbook. I'm able to get `"{ip_address}:port" with the following code:
vars:
config:
addresses: "{{ groups['other']
| map('extract', hostvars)
| map(attribute='ansible_host')
| product([':' ~ other_port]) | map('join')
}}"
I tried using the format filter but it expects the input to be the format pattern not a variable to insert into a format.
If I was allowed to execute arbitrary python would express what I want as:
vars:
config:
addresses: "{{ [ f'http://{host.hostvars.ansible_host}:{port}' for host in groups['other'] }}"
but it's all got to be in jinja2 filters. I feel like being able to even tack on the port number was a fluke. Is there a way to express this in jinja? Right now I'm looking at hard-coding the format into the hosts file.
othergroup? Willaddressessimply be undefined for them?othergroup simply won't be in the list. For context, this playbook would be run on a group of hosts that aren'totherbut need the addresses ofother.