Deploy issue: UnicodeEncodeError: 'ascii' codec can't encode character

I updated Trellis and it works fine in the dev environment. But when I want to deploy the changes, I get this error message:

TASK [deploy : Copy project templates] **********************************************************************
System info:
Ansible 2.3.0.0; Darwin
Trellis at “Add Vagrant config”

UnicodeEncodeError: ‘ascii’ codec can’t encode character u’\xe0’ in position
2: ordinal not in range(128)
failed: [domain.tld] (item={u’dest’: u’.env’, u’src’: u’roles/deploy/templates/env.j2’, u’name’: u’.env config’}) => {“failed”: true, “item”: {“dest”: “.env”, “name”: “.env config”, “src”: “roles/deploy/templates/env.j2”}}

My previous Trellis dated from early February. I updated my copy by overwriting it with yesterday’s version of Trellis, except for the group_var and hosts folder. I then also added the new files: all/known_hosts.yml and helpers.yml. I then destroyed and recreated the vagrant box, provisioned it, then used a copy of the production environment database and files to restore it locally.

I haven’t found much on this error message except an old issue that was patched back in May 2016.
Could you point me in the right direction?

'ascii' codec can't encode character u'\xe0'

$ python -c "print (u'\xe0')"
à

The failing task (Copy project templates) is using Ansible’s template module, drawing on the vault env vars. So, I can reproduce the issue above if I add à to my vault env

vault_wordpress_sites:
  example.com:
    env:
      ...
      auth_key: "generàteme"
      ...

A brief search of Ansible issues shows various appearances of this type of issue with the template module. I didn’t look long enough to figure out the latest status of the issue. It seems there have been a few attempts to resolve it, but it may keep resurfacing in different contexts.

If you didn’t see the problem in your dev environment, but you now see it in staging or production, it is perhaps because secrets (vault file values for env vars, etc.) differ between environments and perhaps staging or production has the à character but development does not.

Presumably you could avoid the issue by replacing the à character.

2 Likes

That was it. My db password contained the accented character. I changed it, reprovisioned then deployed. All fine now. Thank you very much!

2 Likes