How can I prevent templates from mixing up with the content they receive?

I am using wordpress install option to install and for that I have a template for wp-config.php.

My wp-config.php.j2 template has keys and salts replacement, it looks like

{{ wordpress_keys.content }}

      

wordpress_keys comes from a task that looks like this:

- name: retrieve new wordpress keys and salts
  uri:
    url: "https://api.wordpress.org/secret-key/1.1/salt/"
    method: GET
    return_content: yes
  register: wordpress_keys

      

The problem is that sometimes keys and salts have "special" characters in them like <>, {}, etc., and this seems to cause an error like this to be generated:

fatal: [ddc-wpchange2.ddc.prod] => {'msg :: AnsibleError: failed template define (' AUTH_KEY ',
' 1 = MFI * +! D ^ 1 / y;} za6 $ Qfw4vo {bv! GV ? LmX? ^ P h / 5L? SzDv & V <~ in +. ~ ^ OOdCFpyt] Tu8FSmGE} @ ||, Pe ​​(: (1% CjjAwhq {Gi # J- '); \ Ndefine (' LOGGED_IN_KEY ",
'BJ6c9 # / XDBVDB-8Q + ctK9DLZiKUzPYbM & COMFORT .v7COPb8 = [9HdU &! Y7% Zee {& XH'); \ ndefine ('NONCE_KEY', ". X <code> B: 3 | / # | ^ 2 * JMh6 + T $ Ek: DG + wEqyO4: QZmMo} r | Meži ~ LrvNpJ-r (8 / S, P., N '); \ ndefine (' AUTH_SALT ',' -pzZ6 L40 ^ 8 ++ A @ t_sldjcode> _CK {{V%] and- # cK44dAig% vol <'); \ ndefine (' SECURE_AUTH_SALT ", '? ONDE {- {6CQT_Jrn0N4xHhI |} Rz2y1cc9Cj22XOkITU |) BJm@BgPd5 ;'); 'LOGGED_IN_SALT ',' O_Q7} Q.fx, Gt # 0m30 - @ $ k + ~> dSk k6gz / I +> $ k ~ H9) <6 (M ~ W +} UFU: "Y + = rP o1:> p1S : 2FB6)e~vO_

# [- i1ur} V? y $> EOyF; {lkU8Y; y0Znt '); \ n: template error while templating string: unexpected'] '",' failed ': True}

The error does not always occur, only when some special characters are present.

My question is ... How can I just substitute the results from a query without having it? Are there any screens or quotes that will work?

Thanks
John

+3


source to share


2 answers


So I gave up on the template solution. Instead, I used wp-cli to create a wp-config.php file for me. I only did this because the template solution accidentally didn't work with the template getting confused with the content it was receiving.



+1


source


Dropping certain characters would be tricky because the uri maintainer not only needs to support this, but the templating engine would have to undo as well.

Instead, a workaround:

Modify the task to store the content in a file instead of a variable:



- name: retrieve new wordpress keys and salts
  uri:
    url: "https://api.wordpress.org/secret-key/1.1/salt/"
    method: GET
    dest: wp_keys.php
    return_content: yes

      

Then add a line to the wp-config.php.j2 template that includes wp_keys.php

.

+4


source







All Articles