Hi there,
I simply cannot figure out how to create a string from a list.
What output I want in a variable:
"{{10.0.0.1:8080,10.0.0.2:8080}}"
I am retrieving a dynamic list of private IPs from Azure Scaleset.
`
tasks:
-
name: Connect
command: az account set -s {{ subscription_id }} -
name: Get private IPs
command: az vmss nic list --resource-group {{ customer_group }} --vmss-name {{ customer }}-vmss
register: result -
name: Filter result
set_fact:
ip_list: “{{ result.stdout | from_json | json_query(‘[].ipConfigurations[].privateIpAddress’) }}” -
set_fact:
foo: “{{ item }}:8080”
with_items: “{{ ip_list }}” -
debug: var=foo
`
Output so far:
`
PLAY [localhost] ********************************************************************************************************************
TASK [set_fact] *********************************************************************************************************************
ok: [localhost]
TASK [Connect] **********************************************************************************************************************
changed: [localhost]
TASK [Get private IPs] **************************************************************************************************************
changed: [localhost]
TASK [Filter result] ****************************************************************************************************************
ok: [localhost]
TASK [set_fact] *********************************************************************************************************************
ok: [localhost] => (item=10.1.1.7)
ok: [localhost] => (item=10.1.1.4)
ok: [localhost] => (item=10.1.1.5)
TASK [debug] ************************************************************************************************************************
ok: [localhost] => {
“foo”: “10.1.1.5:8080”
}
`
I need to create a loop that puts the list into a string.
`
- set_fact:
foo: “{{ item }}:8080”
with_items: “{{ ip_list }}”
`
Does anybody know how to do this?