There are files in the directory:
environment1_--_192.168.12.239
environment1_--_192.168.12.46
environment1_--_192.168.12.72
environment1_--_192.168.12.83
environment2_--_192.168.12.150
environment2_--_192.168.12.53
environment2_--_192.168.12.44
environment2_--_192.168.12.90
Find files:
- ansible.builtin.find:
paths: "./environments/"
file_type: file
register: environment_hosts_files
I need to get a list of dictionaries:
environment_hosts:
- name: environment1
hosts:
- 192.168.12.239
- 192.168.12.46
- 192.168.12.72
- 192.168.12.83
- name: environment2
hosts:
- 192.168.12.150
- 192.168.12.53
- 192.168.12.44
- 192.168.12.90
How to do this?
Get the lists
gives
Get the lists of the environments and hosts, and create the dictionary
gives
Convert the dictionary to a list if you want to
gives
Given the tree
Example of a complete playbook for testing