I've a task in ansible where I've to extract value of token from a json object, which is as follows:
{
"token.stdout_lines": [
"{",
"\t\"id\": \"08320829d85c7000\",",
"\t\"description\": \"\",",
"\t\"token\": \"zMiyCw7X6u_IjBpTbD1Nvt4eGk-dxBXWWOqRCgWh_KiYtp7AjD5mML5mBIEtApncBSXwU3QqexT_4VVmEv0WeA==\",",
"\t\"status\": \"active\",",
"\t\"userName\": \"telegraf\",",
"\t\"userID\": \"0831cb0c68dc7000\",",
"\t\"permissions\": [",
"\t\t\"read:orgs/ea37b04111f50748/buckets\",",
"\t\t\"write:orgs/ea37b04111f50748/buckets\"",
"\t]",
"}"
]
}
In order to retrieve the value of the token, I followed these steps:
- set_fact:
myvalue: "{{ token.stdout_lines | regex_search('regexp')}}"
vars:
regexp: 'token([^"]+)":([^"]+)"([^.{\\}$"]+)'
- debug:
var: myvalue
The output I get is a null value in myvalue.
Can anyone point to where I am making a mistake?
Many thanks