1

Vagrant version

Vagrant 1.9.7

Host operating system

Darwin bogon 16.6.0 Darwin Kernel Version 16.6.0: Fri Apr 14 16:21:16 PDT 2017; root:xnu-3789.60.24~6/RELEASE_X86_64 x86_64

Guest operating system

distributor ID: Ubuntu Description: Ubuntu 16.04.2 LTS Release: 16.04 Codename: xenial

Question

How to set environment variables and /etc/hosts through Vagrantfile?

In docker-composer, I can set environment and extra_hosts

In vagrant, how to do this?

fatihyildizhan
  • 8,614
  • 7
  • 64
  • 88

1 Answers1

2

Vagrant manages Virtual Machines when used with Virtual Box, not a container.

If you want to have environment variable defined or specific files, the best is to use vagrant provisioner

You can push file directly using the file provisioner or have a shell script to edit the file and add some lines.

A simple shell script to add environment variable will be

  config.vm.provision "shell", privileged: false, inline: <<-SHELL
    echo "export VARIABLE=VALUE" > /home/vagrant/.profile
  SHELL

so the variable will be available when you ssh into the machine

Frederic Henri
  • 51,761
  • 10
  • 113
  • 139