ansible 2.4 set_fact with regex_replace Quote issue

hi everybody,

i try to make a string transformation with regex_replace for construct my array. i use ansible 2.4, i try many variation, but i don’t find the right syntax with double quote and simple quote… someone can help me please ?

find some information about my issue :

ansible block :

  • name: ACM Create / Make Array for DNS validation process
    set_fact:
    cert_validation_target: "{{cert_validation_target}} +[ {‘dns_zone’:‘{{ item.DomainName | regex_replace(’[1]{0,3}(-admin){0,1}.{0,1}(?P(toto….[a-z]{2,3})|tata...[a-z]{2,3})$‘,’‘)}}’,‘validation_record’:‘{{item.ResourceRecord.Name}}’,‘validation_record_target’:‘{{item.ResourceRecord.Value}}’} ] "
    with_item: {{json_request}}

expected result array :
dns_zone | validation_record | validation_record_target
toto.contoso.com | _23c2345c38d3b5642cfc40c957e9a659.xxx-admin.toto.contoso.com. | _5ebe31541034fdefdf4a1681a09e6ca.ltfvzjuylp.acm-validations.aws.
tata.contoso.de | _f6036f745ae8f4efd01e32484159cbc0.inf-admin.tata.contoso.de. | _702240d8eb90f53a51239b6fb2f92bb9a.ltfvzjuylp.acm-validations.aws.

Json_request example :
{
“DomainName”: “xxx-admin.toto.contoso.com”,
“ResourceRecord”: {
“Name”: “_23c2345c38d3b5642cfc40c957e9a659.xxx-admin.toto.contoso.com.”,
“Type”: “CNAME”,
“Value”: “_5ebe31541034fdefdf4a1681a09e6ca.ltfvzjuylp.acm-validations.aws.”
},
“ValidationMethod”: “DNS”,
“ValidationStatus”: “PENDING_VALIDATION”
},
{
“DomainName”: “inf-admin.tata.contoso.de”,
“ResourceRecord”: {
“Name”: “_f6036f745ae8f4efd01e32484159cbc0.inf-admin.tata.contoso.de.”,
“Type”: “CNAME”,
“Value”: “_702240d8eb90f53a51239b6fb2f92bb9a.ltfvzjuylp.acm-validations.aws.”
},
“ValidationMethod”: “DNS”,
“ValidationStatus”: “PENDING_VALIDATION”

ansible execution result :

ERROR! Syntax Error while loading YAML.
The error appears to have been in '/var/lib/jenkins/workspace/xxxxxxxxxxxxxxx/tasks/main.yml': line 118, column 137, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:

  set_fact:
    cert_validation_target: "{{cert_validation_target}} + [ {'dns_zone':'{{ 'item.DomainName' | regex_replace('^[a-z]{0,3}(-admin){0,1}\.{0,1}(?P<subdomain>(toto..*\.[a-z]{2,3})|tata\..*\.[a-z]{2,3})$','<subdomain>')}}','validation_record':'{{item.ResourceRecord.Name}}','validation_record_target':'{{item.ResourceRecord.Value}}'} ] "
                                                                                                              ^ here

  1. a-z ↩︎