I'm using Ansible to get a list of user emails from an API and I want to loop over them.
This is the json response I get from the API:
"users": [
{
"email": "email1@email.com",
"id": 1,
"is_admin": true
},
{
"email": "email2@email.com",
"id": 2,
"is_admin": false
},
]
edit: the task after that which I need the email for:
- name: Send emails
register: result
uri:
url: http://api
method: GET
body_format: json
return_content: yes
body:
email: "{{ item.email }}"
scope: SCOPE
loop: "{{ users.json['users'] }}"
- name: Print result
debug:
var: result
the error I get:
fatal: [localhost]: FAILED! => {"msg": "template error while templating string: unexpected char '@' at 16. String: {{ email@email.com }}"}
If I use email: item.email
the json request body will be "body": {"email": "item.email"}
instead of the email value
How Can I get the full email of each user?