I have to add a key and a value to a list which is read from a csv-file into a variable.
To explain it a bit better. First I load a list from a csv-file:
- name: Load user list from csv
community.general.read_csv:
path: ../files/example-prod.csv
delimiter: ','
register: users
delegate_to: localhost
When I look at the "users" variable I get the following output:
"list": [
{
"firstName": "Max",
"gid": "2002",
"homedir": "example",
"lastName": "Mustermann",
"uid": "m.example"
},
{
"firstName": "Martin",
"gid": "2002",
"homedir": "staff",
"lastName": "Muster",
"uid": "martin.muster"
}
]
Now I need to generate passwords for all users in the list. So I want to loop through the items and add a new key-value-pair to each item in the list.
The output that I want after the password creation loop is:
"list": [
{
"firstName": "Max",
"gid": "2002",
"homedir": "example",
"lastName": "Mustermann",
"uid": "m.example",
"password": "examplepassword"
},
{
"firstName": "Martin",
"gid": "2002",
"homedir": "staff",
"lastName": "Muster",
"uid": "martin.muster",
"password": "examplepassword"
}
]
...so I can read out the variables later.
How to accomplish this? I've read many things about how to do this with a dictionary, but since I'm using a list here, I could not find it out.