Scenario
Example of a list of IP addresses which need to be have a protocol e.g. https:
as prefix and a port number e.g. 5000
as suffix in order to configure a file or use the list to query the endpoint.
---
- hosts: localhost
gather_facts: false
vars:
endpoints: [192.168.1.10, 192.168.2.10, 192.168.3.10]
tasks:
- name: 'endpoints with protocol https and port 5000'
ansible.builtin.debug:
var: updated_endpoints
vars:
protocol: https://
port: :5000
updated_endpoints: |
{{
[protocol] | product(endpoints) | map('join') |
product([port]) | map('join') | list
}}
Reference
Initial Reference which provides the idea of using product
. I combined the logic to make the prefix and suffix logic work together.
Thought it might be helpful for people playing with lists and adding things to each element.