I am at a bit of a loss on how to transform a list of dicts into a json structure that is needed to be sent as a variable into another module
To start with, I have a list of dict that describes all the information about the 'teams' I am creating (in awx / Tower). This list details a bunch of information about my teams. Not all need to be transformed into the JSON structure for this next update I need to do.
awxTeamsDefinition:
- { teamname: Team1, ldapgroupname: tower-team-1, description: This is tower team 1, organization: orgA }
- { teamname: Team2, ldapgroupname: tower-team-2, description: This is tower team 2, organization: orgA }
- { teamname: Team3, ldapgroupname: tower-team-3, description: This is tower team 3, organization: orgB }
- { teamname: Team4, ldapgroupname: tower-team-4, description: This is tower team 4, organization: orgB }
Next, I need to extract some information and stick it in a JSON structure that looks like this:
{
"Team1": {
"remove": true,
"organization": "orgA",
"users": "cn=tower-team-1,cn=groups,cn=accounts,dc=domain,dc=com"
},
"Team2": {
"remove": true,
"organization": "orgA",
"users": "cn=tower-team-2,cn=groups,cn=accounts,dc=domain,dc=com"
},
"Team3": {
"remove": true,
"organization": "orgB",
"users": "cn=tower-team-3,cn=groups,cn=accounts,dc=domain,dc=com"
},
"Team4": {
"remove": true,
"organization": "orgB",
"users": "cn=tower-team-4,cn=groups,cn=accounts,dc=domain,dc=com"
}
}
I need this JSON structure in a variable that I can pass into another module.
This is simply beyond my ansible / jinja trickery ability. I don't know how to extract from a dict and promote that the the index of each json entry (in this case, 'teamname'), get rid of the 'description', and use 'ldapgroupname' to replace into the cn structure. Any help would be appreciated. Thanks!