How to debug a unexpected char while templating on Trellis deploy


I have a roots fullstack environment workin on local and I’m trying to deploy to digitalocean.

I’ve created the droplet and added the ip to hosts/staging and edited staging/wordpress_sites.yml

When I run

ansible-playbook server.yml -e env=staging -vvvvv

Everithing works untill:

TASK [wordpress-setup : Create/assign database user to db and grant permissions] ***
task path: /Users/miqueladell/code/
fatal: []: FAILED! => {"failed": true, "msg": "ERROR! template error while templating string: unexpected char u'`' at 53"}

If I go to line 11 of


I see nothing that could cause the error:
(I’ve added line numbers)

09    when: not mysql_remote_database and item.value.db_create | default(True)
11    - name: Create/assign database user to db and grant permissions
12      mysql_user: name="{{ item.value.env.db_user }}"
13                  password="{{ vault_wordpress_sites[item.key].env.db_password }}"

I guess ansible is using some data from staging/wordpress_sites.yml to fill database.yml and then run it but I don’t see anything on wordpress_sites.yml that could produce this error:

      disable_wp_cron: true
      wp_env: staging
      db_name: staging
      db_user: staging

How could I see the exact line that it’s failing? I don’t think I can add more -vvv to the command :frowning:

I really don’t know how to debug this further. Any help will be greatly appreciated, thanks.

Strange. I don’t recall the backtick ` ever causing trouble in variable definitions.

As you know, the calling task is having trouble templating out the relevant variables. You could check these variables’ definitions for backticks or inconsistent open/closing quotes (if any quotes at all). In addition to variables you checked in wordpress_sites.yml, check these:

I’m eager to hear what you find. I’m adding some checks to warn users if/when they have the problematic `{{` and `{%` strings in their vault.yml file. Perhaps you’ve stumbled on a new problematic string.


Hi @fullyint,

Thanks for your time.

I was checking vault.yml again and I’ve discovered that I was using a salt that had {% on it so the scaping failed.

There is a comment just above the salts saying:

  # Generate your keys here:
  # These CANNOT contain the characters "{%" in succession

I shoulda have payed more attention to it.

I’ve replaced the offending characters and everything works.

Sorry about the fuzz and thanks a lot again.


Sorry to raise this from the dead, but I just ran into a similar problem, using I ended up with this offending string:

Error msg: template error while templating string: unexpected '|'

Figure it’ll happen to somebody else sooner or later.

@intelligence thanks that’s a good note that should help people if they see a similar error, even just to prompt them to update their Trellis version…

Some good news is that that salts should no longer have problems with special characters after roots/trellis#684. In my test, the latest Trellis (53e7db4) appears to handle the string you posted without error.

If anyone encounters a similar unexpected error on variables other than the salts, consider adding the variable name to the list of raw_vars that are automatically escaped.

1 Like

You guys are the best! Cheers

1 Like