What's the best way to set a locale in a shell provisioner?

232 views
Skip to first unread message

Richard Murray

unread,
Jul 6, 2015, 12:35:42 PM7/6/15
to vagra...@googlegroups.com
Hi, 

I'm trying to set a specific locale (ISO-8859-1) with a Vagrant provision script but I'm having trouble getting it to work.

For the locale change to take effect you need to log back into the machine (I think), so I thought having multiple provision scripts would do the trick.

Vagrantfile provision
config.vm.provision "shell", path: "provision_locale.sh"
config.vm.provision "shell", path: "provision.sh"

provision_locale.sh
locale-gen en_GB
update-locale LANG=en_GB.ISO-8859-1

The second provision script installs Java and starts a Jenkins swarm process to connect as a Jenkins Slave.  When I run builds on the VM I get a lot of test failures around the locale (as if its not been set correctly). 

If I remove ""provision_locale.sh" from the Vagrantfile and set the locale using "vagrant ssh" everything seems to work OK.

# This seems to work
vagrant up --no-provision
vagrant ssh -c "sudo locale-gen en_GB"
vagrant ssh -c "sudo update-locale LANG=en_GB.ISO-8859-1"
vagrant provision # single provsion script in Vagrantfile - provision.sh

So why doesn't this work with 2 separate provision scripts?  Does Vagrant only connect to the VM once for all provision scripts, I assumed it would re-connect for each provision script so it would behave in the same was as the "vagrant ssh" commands.

Thanks,
Rich.

Alvaro Miranda Aguilera

unread,
Jul 6, 2015, 6:37:42 PM7/6/15
to vagra...@googlegroups.com
On Tue, Jul 7, 2015 at 4:35 AM, Richard Murray <rich.j...@gmail.com> wrote:
> config.vm.provision "shell", path: "provision_locale.sh"
> config.vm.provision "shell", path: "provision.sh"


hello, this is probably how the shells are created (local shell, subshell, etc)

try this:

config.vm.provision "shell", inline: "source /vagrant/provision_locale.sh"
config.vm.provision "shell", inline: "bash /vagrant/provision.sh"

The first one, using source should set the values for current shell
the second one should create a sub shell, that may inherit the values
of the first

if doesn't work, you can test:

config.vm.provision "shell", inline: "source /vagrant/provision_locale.sh"
config.vm.provision "shell", inline: "source /vagrant/provision.sh"



Alvaro.

Richard Murray

unread,
Jul 7, 2015, 5:40:51 AM7/7/15
to vagra...@googlegroups.com
Hi, 

Thanks for the suggestions, unfortunately neither worked.  At least I have a workaround using the 'vagrant ssh' command to set the locale before running the provision script.

It would be nice to get it working on a 'vagrant up' with simple provisioning scripts (or at least to understand why it doesn't work the way I expect).

Thanks,
Rich.

Alvaro Miranda Aguilera

unread,
Jul 7, 2015, 5:44:20 PM7/7/15
to vagra...@googlegroups.com
can you share a zip with that part file to have a look?
> --
> This mailing list is governed under the HashiCorp Community Guidelines -
> https://www.hashicorp.com/community-guidelines.html. Behavior in violation
> of those guidelines may result in your removal from this mailing list.
>
> GitHub Issues: https://github.com/mitchellh/vagrant/issues
> IRC: #vagrant on Freenode
> ---
> You received this message because you are subscribed to the Google Groups
> "Vagrant" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to vagrant-up+...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/vagrant-up/18cd3264-abe8-45b4-ae8d-ed770043e490%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Richard Murray

unread,
Jul 8, 2015, 5:01:10 PM7/8/15
to vagra...@googlegroups.com
I don't have a simple reproducible I could post, the locale issues are when compiling a large Java project.
Reply all
Reply to author
Forward
0 new messages