1

I am deploying my sinatra project via ansible, and one of the tasks is precompiling assets.

At first I stacked into question how to initialize rbenv properly.

Then, what I did is:

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

But then I got error Encoding::UndefinedConversionError at assets/application.js

When I connected by ssh to server and run bundle exec rake assetpack:build - everything worked perfectly. So, I presumed, this is related to setting environment variables

lookup('env', 'LANG') says it is "msg": "ru_RU.UTF-8" but echo $LANG says it's "C" (look there).

Look to this issue. It says:

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

Ansible modules set "$LANG=C" automatically.

Adding environment variable didn't give desired result:

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

At the same time shell module seem to know nothing about bundle, so this didn't work as well:

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

I tried huge bunch of commands, such as export LANG=ru_RU.UTF-8, command module, shell module, but nothing helps, all my attempts failed miserably.

I do not really know how to workaround this issue.

Need help!

Community
  • 1
  • 1
Nick Roz
  • 3,918
  • 2
  • 36
  • 57

2 Answers2

0

command module is not intended to be used with multiple shell commands. shell module should be used instead:

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

Any environment variable that is required before running bundle can be configured as in the next example:

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

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

Gregory Shulov
  • 204
  • 1
  • 4
0

I should've changed not only LANG variable, but both LANG and LC_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"

That worked for me!

Nick Roz
  • 3,918
  • 2
  • 36
  • 57