无法通过ansible预编译sinatra资产

Can't precomile sinatra assets via ansible

我正在通过 ansible 部署我的 sinatra 项目,其中一项任务是预编译资产。

一开始我堆成问题how to initialize rbenv properly.

然后,我做的是:

- name: Precompiling assets
  command: bash -lc "cd {{ build_path }} && bundle exec rake assetpack:build"

但是我得到了错误Encoding::UndefinedConversionError at assets/application.js

当我通过 ssh 连接到服务器并且 运行 bundle exec rake assetpack:build - 一切正常。 所以,我推测,这与 setting environment variables

有关

lookup('env', 'LANG') 说是 "msg": "ru_RU.UTF-8" 但 echo $LANG 说是 "C" (look there).

查看this issue。它说:

Ansible sets LANG to C on modules which don't need it

Ansible 模块自动设置“$LANG=C”。

添加环境变量没有得到想要的结果:

environment:
  LANG: ru_RU.UTF-8
command: bash -lc "cd {{ build_path }} && bundle exec rake assetpack:build"

同时 shell 模块似乎对 bundle 一无所知,所以 这也不起作用 :

- name: Precompiling assets
  command: bash -lc "cd {{ build_path }} && bundle exec rake assetpack:build"

我尝试了一大堆命令,例如export LANG=ru_RU.UTF-8command模块、shell模块,但没有任何帮助,我所有的尝试都惨遭失败。

我真的不知道如何解决这个问题。

需要帮助!

command 模块不适用于多个 shell 命令。 shell 应该改用模块:

- name: Precompiling assets
  shell: bundle exec rake assetpack:build chdir={{ build_path }}

在 运行 bundle 之前需要的任何环境变量都可以配置为下一个示例:

- name: Precompiling assets
  shell: RAILS_ENV=development bundle exec rake assetpack:build chdir={{ build_path }}

http://docs.ansible.com/ansible/shell_module.html

我不仅应该更改 LANG 变量,还应该更改 LANGLC_ALL:

- name: Precompiling assets
  environment:
    LANG: "ru_RU.UTF-8"
    LC_ALL: "ru_RU.UTF-8"
  command: bash -lc "cd {{ build_path }} && bundle exec rake assetpack:build"

这对我有用!