TJB
TJB

Reputation: 3846

Ansible pip module issue reading requirements.txt file

I am using Ansible's pip module to install my applications dependencies from a requirements.txt file. Its definitely working, going down the list and installing each package, but when it gets to one in particular, it will fail causing the whole ansible-playbook to fail with an Ascii unicode error.

Ansible-Playbook task

- name: Install project requirements
  pip:
    state: latest
    requirements: "{{ project_path }}/requirements/base.txt"
    virtualenv: "{{ venv_path }}"
    virtualenv_python: python3.6
    virtualenv_command: /usr/local/bin/virtualenv

Ansible Message

Collecting django-s3direct==1.0.3 (from -r /srv/app/requirements/base.txt (line 35))
Downloading django-s3direct-1.0.3.tar.gz (61kB)
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File \"<string>\", line 1, in <module>
File \"/tmp/pip-build-ab20m5jb/django-s3direct/setup.py\", line 5, in <module>
readme = f.read()
File \"/srv/xena/.virtualenv/lib64/python3.6/encodings/ascii.py\", line 26, in decode
return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 6326: ordinal not in range(128)

Upvotes: 0

Views: 4248

Answers (1)

Syl
Syl

Reputation: 2783

based on the code from django-s3direct, it tries to read the README.md, which seems to be encoded in UTF8. It fails because python tries to read it with an ascii codec.

Try to change the default encoding for python, run this in your console to set the env variable:

export PYTHONIOENCODING=utf8

edit: since the error appears on the guest, set the env variable in your playbook: http://docs.ansible.com/ansible/latest/playbooks_environment.html

- name: Install project requirements
  pip:
      environment:
        PYTHONIOENCODING: utf8

Upvotes: 1

Related Questions