Trellis Provisioning Error

Has anyone ever gotten this error attempting to provision a server? No idea what this means:

PLAY [Determine Remote User] ***************************************************


TASK [remote-user : Determine whether to connect as root or admin_user] ********
Traceback (most recent call last):
  File "/usr/local/Cellar/ansible/2.0.1.0/libexec/bin/ansible", line 110, in
<module>
    display.error("Unexpected Exception: %s" % to_unicode(e),
wrap_text=False)
  File "/usr/local/Cellar/ansible/2.0.1.0/libexec/lib/python2.7/site-
packages/ansible/utils/display.py", line 261, in error
    self.display(new_msg, color='red', stderr=True)
  File "/usr/local/Cellar/ansible/2.0.1.0/libexec/lib/python2.7/site-
packages/ansible/utils/display.py", line 124, in display
    msg2 = to_bytes(msg2, encoding=self._output_encoding(stderr=stderr))
  File "/usr/local/Cellar/ansible/2.0.1.0/libexec/lib/python2.7/site-
packages/ansible/utils/unicode.py", line 208, in to_bytes
    return obj.encode(encoding, errors)
LookupError: unknown encoding:

I’m sure I configured something wrong, but I have no idea what.

What git sha is your version of Trellis? This could help determine which of the many commits in the past couple weeks may be relevant.

The error may be relevant to how Ansible’s Display.display() method can only process unicode strings

I just merged b2b57d1bf8db0afe1f495f72855bcdd6e87429b3 into my local instance, so I have the latest as of this afternoon or so.

Thanks! Could you comment out the stdout_callback = output to disable the new output plugin, run your playbook again, and share the output? Maybe also with -vvvv? Thanks!

That got rid of the exception, but the remote-user role seems to be returning admin instead of root as the user it should connect with. I still see the stack trace in the play’s stderr:

PLAY [Determine Remote User] ***************************************************

TASK [remote-user : Determine whether to connect as root or admin_user] ********
task path: server/roles/remote-user/tasks/main.yml:2
ESTABLISH LOCAL CONNECTION FOR USER: jdigioia
localhost EXEC /bin/sh -c '( umask 22 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1459740301.05-259556847589223 `" && echo "` echo $HOME/.ansible/tmp/ansible-tmp-1459740301.05-259556847589223 `" )'
localhost PUT /var/folders/8k/1w9spjwd0y5cn9tk7631hdf40000gn/T/tmpX38JOw TO /Users/jdigioia/.ansible/tmp/ansible-tmp-1459740301.05-259556847589223/command
localhost EXEC /bin/sh -c 'LANG=en_US LC_ALL=en_US LC_MESSAGES=en_US /usr/bin/python /Users/jdigioia/.ansible/tmp/ansible-tmp-1459740301.05-259556847589223/command; rm -rf "/Users/jdigioia/.ansible/tmp/ansible-tmp-1459740301.05-259556847589223/" > /dev/null 2>&1'
ok: [IPADDRESS -> localhost] => {"changed": false, "cmd": ["ansible", "IPADDRESS", "-m", "ping", "-u", "root"], "delta": "0:00:01.623649", "end": "2016-04-03 23:25:02.745445", "failed": false, "failed_when_result": false, "invocation": {"module_args": {"_raw_params": "ansible IPADDRESS -m ping -u root", "_uses_shell": false, "chdir": null, "creates": null, "executable": null, "removes": null, "warn": true}, "module_name": "command"}, "rc": 1, "start": "2016-04-03 23:25:01.121796", "stderr": "Traceback (most recent call last):\n  File \"/usr/local/Cellar/ansible/2.0.1.0/libexec/bin/ansible\", line 110, in <module>\n    display.error(\"Unexpected Exception: %s\" % to_unicode(e), wrap_text=False)\n  File \"/usr/local/Cellar/ansible/2.0.1.0/libexec/lib/python2.7/site-packages/ansible/utils/display.py\", line 261, in error\n    self.display(new_msg, color='red', stderr=True)\n  File \"/usr/local/Cellar/ansible/2.0.1.0/libexec/lib/python2.7/site-packages/ansible/utils/display.py\", line 124, in display\n    msg2 = to_bytes(msg2, encoding=self._output_encoding(stderr=stderr))\n  File \"/usr/local/Cellar/ansible/2.0.1.0/libexec/lib/python2.7/site-packages/ansible/utils/unicode.py\", line 208, in to_bytes\n    return obj.encode(encoding, errors)\nLookupError: unknown encoding: ", "stdout": "", "stdout_lines": [], "warnings": []}

Hmm, yeah the exception is still there. The plugin was reading and printing the stderr attribute of the json dump (intepretting \n and adding textwrap). So, it all seems to be the same problem, just with the output presented differently.

If you have Ansible Vault enabled (e.g., vault.yml files encrypted) and are using an option like --ask-vault-pass (instead of a .vault_pass file), the ping ad hoc command will need that same option added. I have a fix for that in my queue.

I’ll keep looking at it, but you could try Trellis fc44e94 from March 29 to see if that works, just to narrow down whether the issue is something that was recently introduced to the project.

Hmm, no, not using vault. FWIW, this is the output of the ping command:

± |jamesdigioia.com {4} ✓| → ansible IPADDRESS -m ping -u root
IPADDRESS | SUCCESS => {
    "changed": false, 
    "ping": "pong"
}

My output from ping is the same. My verbose output is pretty much the same but without the stderr message.

However, I wonder if it is significant that where my output reads en_US.UTF-8 yours reads just en_US.

TASK [remote-user : Determine whether to connect as root or admin_user] ********
task path: /Users/philip/projects/roots/example.com/ansible/roles/remote-user/tasks/main.yml:2
ESTABLISH LOCAL CONNECTION FOR USER: philip
localhost EXEC /bin/sh -c '( umask 22 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1459743082.63-28923172239190 `" && echo "` echo $HOME/.ansible/tmp/ansible-tmp-1459743082.63-28923172239190 `" )'
localhost PUT /var/folders/8s/fk0hnnsd19x3_r_3x3vsq_4c0000gn/T/tmpGhPEON TO /Users/philip/.ansible/tmp/ansible-tmp-1459743082.63-28923172239190/command
localhost EXEC /bin/sh -c 'LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 /usr/local/opt/python/bin/python2.7 /Users/philip/.ansible/tmp/ansible-tmp-1459743082.63-28923172239190/command; rm -rf "/Users/philip/.ansible/tmp/ansible-tmp-1459743082.63-28923172239190/" > /dev/null 2>&1'
ok: [198.199.117.230 -> localhost] => {"changed": false, "cmd": ["ansible", "198.199.117.230", "-m", "ping", "-u", "root"], "delta": "0:00:02.464963", "end": "2016-04-03 21:11:25.225280", "failed": false, "failed_when_result": false, "invocation": {"module_args": {"_raw_params": "ansible 198.199.117.230 -m ping -u root", "_uses_shell": false, "chdir": null, "creates": null, "executable": null, "removes": null, "warn": true}, "module_name": "command"}, "rc": 0, "start": "2016-04-03 21:11:22.760317", "stderr": "", "stdout": "198.199.117.230 | SUCCESS => {\n    \"changed\": false, \n    \"ping\": \"pong\"\n}", "stdout_lines": ["198.199.117.230 | SUCCESS => {", "    \"changed\": false, ", "    \"ping\": \"pong\"", "}"], "warnings": []}

Could you check your env var LANG and consider running export LANG=en_US.UTF-8 ?

Looks like Ansible will default to the value of LANG if it is set: os.getenv('LANG', 'en_US.UTF-8')

If I change mine to just en_US I get the same traceback:

~/p/r/e/ansible ❯❯❯ export LANG=en_US 

~/p/r/e/ansible ❮❮❮ ansible-playbook server.yml -e env=staging -vvvv 
Traceback (most recent call last):
  File "/usr/local/bin/ansible-playbook", line 110, in <module>
    display.error("Unexpected Exception: %s" % to_unicode(e), wrap_text=False)
  File "/usr/local/lib/python2.7/site-packages/ansible/utils/display.py", line 261, in error
    self.display(new_msg, color='red', stderr=True)
  File "/usr/local/lib/python2.7/site-packages/ansible/utils/display.py", line 124, in display
    msg2 = to_bytes(msg2, encoding=self._output_encoding(stderr=stderr))
  File "/usr/local/lib/python2.7/site-packages/ansible/utils/unicode.py", line 208, in to_bytes
    return obj.encode(encoding, errors)
LookupError: unknown encoding:

~/p/r/e/ansible ❯❯❯ export LANG=en_US.UTF-8

~/p/r/e/ansible ❮❮❮ ansible-playbook server.yml -e env=staging -vvvv
#back to working!

When I edited my LANG env var as described above, I got the traceback immediately, whereas your traceback was later in the remote-user role. Ansible’s constant DEFAULT_MODULE_LANG also draws on your env var ANSIBLE_MODULE_LANG if set, or on module_lang if you have it set in one of these locations:

  • ANSIBLE_CONFIG (an environment variable)
  • ansible.cfg (in the current directory)
  • .ansible.cfg (in the home directory)
  • /etc/ansible/ansible.cfg

If I leave my LANG as en_US.UTF-8 but set either of the others to en_US, I get the traceback on the same task as you in the remote-user role and the remote-user is set to admin like you experienced.

2 Likes

Thank you so much! Running it with:

LANG=LANG=en_US.UTF-8 ansible-playbook server.yml -e env=production

got it running. I’m still digging into where the LANG is being set (I know I’ve done a lot of customization of my dotfiles, so maybe it got pulled in there?), but at least I can move forward in the meantime.

3 Likes