I'm launching a setup playbook for a docker-compose service (apache solr) via extra vars. Those vars are set while executing since this playbook should be flexible and multiple configurations exists on one server.
My idea is, that the user can setup the variable in the ansible ui (ansible semaphore) as string:
- Variable name
project_cores
- Variable value (string)
main_en:english,main_de:german
I would like to iterate those cores as a dictionary. What I want at the end is:
{
{
name: main_en,
language: english
},
{
name: main_de,
language: german
},
}
The first step is to split them by ,
(this is already working):
- name: "debug: split cores"
debug:
msg: "{{ item }}"
loop: "{{ project_cores.split(',') }}"
I tried then the following without success as this does not add the keys of the sub elements:
- name: "Extract solr cores configuration."
set_fact:
dict: "{{ dict|default({}) | combine ( { item.split(':')[0] : item.split(':')[1] } ) }}"
with_items:
- "{{ project_cores.split(',') }}"
I tested some combinations but does not find a working solution on how to add the keys.
Any idea how to convert that string to a real directory stated in the first example? thanks in advance!