In python the Jinja2 template returns a backslash before the double quote, I need to remove this

One of the lines in my jinja2 template should return

   STACKNAME=\"",{"Ref":"AWS::StackName"},"\"

      

If you go back to the template, return

   STACKNAME=\\\"\",{\"Ref\":\"AWS::StackName\"},\"\\\"

      

I tried to create a variable

 DQ = '"'

      

and setting the template as

STACKNAME="{{DQ}},{{{DQ}}Ref{{DQ}}:{{DQ}}AWS::StackName{{DQ}}},{{DQ}}"

      

but the result still causes the backslash before the {{DQ}} variable

I also tried inserting a unique string %%% DQ %%% and then getting the results and then doing a string replacement, but it still gives me a backslash.

How do I get the results I want?

UPDATE: My apologies. It turns out this is not a jinja2 pattern returning escaped quotes. I am making a later call in the script for:

lc.UserData=Base64(Join("", [commandList]))

      

And it is this call to the Troposphere module for Base64 and / or Join that causes this problem and inserts the screens.

Testing Further shows what Base64 does the escaping.

+3


source to share


1 answer


This looks like a hack and I hope someone has a better solution, but I solved the problem by following these steps.

In the template, I made a line like this:

STACKNAME="QQ,{QQRefQQ:QQAWS::StackNameQQ},QQ"

      

Then in the last line of the program where I have:



print t.to_json()

      

I changed it to

print t.to_json().replace("QQ", '"')

      

Which produces exactly what I'm looking for.

0


source







All Articles