I've been trying to parse email addresses from the below json data:
"msg": [
{
"fqdn": "www.westero.local",
"function": "",
"maintenance_notes": ""
},
{
"fqdn": "mail.fem.local",
"function": "database",
"maintenance_notes": "notify [email protected] and [email protected]"
},
{
"fqdn": "net.runner.local",
"function": "web",
"maintenance_notes": "wait for [email protected] or [email protected]"
}
]
With the below Ansible task, I am only able to parse the first email address:
# extract emails from maintenance_notes
- name: Parse email addresses
set_fact:
email_addys: "{{ json_data | json_query('[*].maintenance_notes') | map('regex_search', '([a-zA-Z0-9._-]+@[a-zA-Z0-9_-]+.[a-zA-Z0-9_-]+)') | unique | select | list }}"
Is there a better way to extract the addresses so I would end up with the following data?
[email protected]
[email protected]
[email protected]
[email protected]
fqdnright there for you to grab the value for each such property?