我正在使用Ansible的pip模块从requirements.txt文件安装我的应用程序依赖项。它绝对有效,从列表中下载并安装每个软件包,但当它特别到达时,它将失败导致整个ansible-playbook失败并出现Ascii unicode错误。
Ansible-Playbook任务
- 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)
答案 0 :(得分:1)
基于django-s3direct的代码,它尝试读取README.md,它似乎是用UTF8编码的。它失败了,因为python试图用ascii编解码器读取它。
尝试更改python的默认编码,在控制台中运行此命令以设置env变量:
export PYTHONIOENCODING=utf8
编辑:由于错误出现在访客上,请在您的剧本中设置env变量:http://docs.ansible.com/ansible/latest/playbooks_environment.html
- name: Install project requirements
pip:
environment:
PYTHONIOENCODING: utf8