Ansible failing to install dependencies via pipenv

Viewed 1036

I have the following task that fails:

- name: restore dependencies via pipenv
  shell: /home/{{ ansible_user }}/.local/bin/pipenv install
  args:
    executable: /bin/bash
    chdir: "{{ app_dir }}"
  environment:
    LC_ALL=C.UTF-8
    LANG=C.UTF-8

with the following message:

RuntimeError: Click will abort further execution because Python 3 was configured to use ASCII as encoding for the environment. Consult https://click.palletsprojects.com/en/7.x/python3/ for mitigation steps.

This system supports the C.UTF-8 locale which is recommended. You might be able to resolve your issue by exporting the following environment variables:

export LC_ALL=C.UTF-8 export LANG=C.UTF-8

What surprises me is the environment is set at the task level.

Furthermore, the command runs OK when I ssh into the machine and perform the operation manually.

2 Answers

This was some kind of typo into the task. The correct syntax was:

- name: restore dependencies via pipenv
  shell: /home/{{ ansible_user }}/.local/bin/pipenv install
  args:
    executable: /bin/bash
    chdir: "{{ app_dir }}"
  environment:
    LC_ALL: "C.UTF-8"
    LANG: "C.UTF-8"

I came here for the same problem but used the command-module. So it's almost the same as your solution but a bit shorter.

- name: restore dependencies via pipenv
  command: pipenv install
  args:
    chdir: "{{ app_dir }}"
  environment:
    LC_ALL: "C.UTF-8"
    LANG: "C.UTF-8"
Related