Hi friends,
I want to use ansible to merge below 2 dictionary to become 1.
I have been stucking for few days already. Headache.
I have 2 variables now.
1. variable “my_directories”:
{ "directoryA": [ "/bar/foo/file1.txt", "/bar/foo/file2.txt" ], "directoryB": [ "/bar/baz/file3.txt", "/bar/baz/file4.txt", "/bar/baz/file5.txt" ] }
2. variable “my_filecontents”:
{ "/bar/foo/file1.txt": "file1Content", "/bar/foo/file2.txt": "file2Content", "/bar/baz/file3.txt": "file3Content", "/bar/baz/file4.txt": "file4Content", "/bar/baz/file5.txt": "file5Content" }
i want to merge it to become:
Result variable: “my_result”
`
{
“directoryA”: {
“/bar/foo/file1.txt”: “file1Content”,
“/bar/foo/file2.txt”: “file2Content”
},
“directoryB”: {
“/bar/baz/file3.txt”: “file3Content”,
“/bar/baz/file4.txt”: “file4Content”,
“/bar/baz/file5.txt”: “file5Content”
}
}
`
The directories and files could be dynamic.
I tried so many codes but still did not work.
Thank you!