0

Using Chef 11.4, I am trying to get vagrant up to set an environment variable. Specifically, the TZ env variable that sets the VM's timezone.

It works fine manually, if I vagrant ssh then type export TZ=America/Los_Angeles then type date I see the time in West Coast time zone (as opposed to ubuntu's default UTC).

But I cannot figure out how to effective run export TZ=America/Los_Angeles within Vagrantfile so it executes when I run vagrant up

I've tried it 3 different ways, including attempting to write it to the .profile file. None of them work. (Th e.profile file does not get edited, and the TZ variable does not get set.

config.vm.provision :shell, inline: %q{export TZ=America/Los_Angeles}
config.vm.provision :shell, inline: %q{sudo bash -c "export TZ=America/Phoenix" >> ~/.profile}
config.vm.provision :shell, inline: %q{echo "export TZ=America/New_york" >> ~/.profile}

the output after running vagrant up is:

==> default: Running provisioner: shell...
    default: Running: inline script
==> default: stdin: is not a tty
==> default: Running provisioner: shell...
    default: Running: inline script
==> default: stdin: is not a tty
==> default: Running provisioner: shell...
    default: Running: inline script
==> default: stdin: is not a tty

But the environment variable does not get set directly, nor does the .profile fiel get edited

jpw
  • 18,697
  • 25
  • 111
  • 187
  • Are you sure? Chef is run as root, so you are changing /root/.profile. There is also a similar question answered: http://stackoverflow.com/questions/24707986/create-linux-environment-variable-using-vagrant-provisioner – Draco Ater Apr 12 '15 at 18:56

1 Answers1

0

The answer is twofold... the file should be in the .bashrc file (at least for the Linux I'm using), and instead of ~ must use the full path which is /home/vagrant/.bashrc.

kenorb
  • 155,785
  • 88
  • 678
  • 743
jpw
  • 18,697
  • 25
  • 111
  • 187
  • Just note this will set the timezone only for the **vagrant** user (not system wide, any other daemon/user will get the default timezone). If you really wish to set it system wide you should modify `/etc/timezone` under ubuntu and the `ZONE` variable in `/etc/sysconfig/clock` for RHEL5 (can't say for other distro) – Tensibai Apr 14 '15 at 14:05
  • 1
    Excellent point. In our case we're setting it for ruby apps and workers, which use TZ env variable. So the approach I found above works for that case, but probably only for that case. – jpw Apr 14 '15 at 18:47