I'm writing an ansible playbook that creates users in an internal system through a call to an API where the request body contains all of the user information in json format.
Right now my playbook hold all of those variables in a list of dictionaries like this:
userInfoDict: "{{[ {'FirstName': 'John', 'LastName': 'Lennon', 'Number': '', 'email': 'john@example.com'}, {'FirstName': 'Paul', 'LastName': 'McCartney', 'Number': '', 'email': 'paul@example.com'} ]}}"
Where the "Number" field is blank, I have a play to grab available phone numbers from an internal DB, and that list of numbers is held in a variable called numberList
What I want to do, is to iterate through UserInfoDict, and set the Number field to the next value in my list of numbers, But I haven't been able to do that.
Is there any way to do something like this in ansible? Where you access an object at an index of a list?
- set_fact:
finalUserInfo: "{{userInfoDict[i].Number : item}}"
loop: "{{numberList}}
Something like this ^