unable to use set_fact in ansible. please help me out
"msg": [
"nilaj 15",
"ajin 15"
]
- set_fact:
name_list: "{{ name_list + item.split() | first }}"
priv_list: "{{ name_list + item.split() | last }}"
loop: "{{ user_list }}"
expected output:
name_list = [ "nilamj","ajitn" ]
priv_list = [ "15","15" ]
If I understand correctly, you want to split an array of strings at the space character and divide it into different lists.
I would advise against implementing this as an Ansible loop and use Jinja functionality instead.
You can use the
mapfunction to apply the respective filter to each element of the entered list.Your
set_facttask would then look like this (without loop):splitis applied usingmapmapand the filterfirstorlast.The input:
results in this output: