On Fri, 21 Feb 2020 01:57:32 -0800 (PST)
João Santos <
morgado...@gmail.com> wrote:
> The properties file will havethis layout as an example:
>
> sw01.local.protocol=${proto}
> sw01.local.host=${host}
> sw01.local.user=${user}
>
> sw02.local.protocol=${proto}
> sw02.local.host=${host}
> sw02.local.user=${user}
>
> In the end my goal will be to have like:
>
> sw01:
> local:
> protocol: ${proto}
> host: ${host}
> user: ${user}
Try this
- set_fact:
prop: "{{ prop|default({})|
combine({my_key0:
{my_key1:
{my_key2: my_value}}}, recursive=True) }}"
vars:
my_keys: "{{ item.split('=').0 }}"
my_value: "{{ item.split('=').1 }}"
my_keys_split: "{{ my_keys.split('.') }}"
my_key0: "{{ my_keys_split.0 }}"
my_key1: "{{ my_keys_split.1 }}"
my_key2: "{{ my_keys_split.2 }}"
loop: "{{ lookup('file', 'java/springboot').splitlines()|
list|select()|list }}"
- debug:
var: prop
HTH,
-vlado