Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with setting ip with vagrant-env #7

Open
frezbo opened this issue Oct 10, 2016 · 1 comment
Open

Error with setting ip with vagrant-env #7

frezbo opened this issue Oct 10, 2016 · 1 comment

Comments

@frezbo
Copy link

frezbo commented Oct 10, 2016

I have been using vagrant-env to set ip addresses for the VM's but not being able to set in some use cases, and vagrant up fails with the following error:

Bringing machine 'server' up with 'libvirt' provider...
/usr/share/ruby/ipaddr.rb:560:in `in6_addr': invalid address (IPAddr::InvalidAddressError)
    from /usr/share/ruby/ipaddr.rb:497:in `initialize'
    from /home/technoman/.vagrant.d/gems/gems/vagrant-libvirt-0.0.36/lib/vagrant-libvirt/action/create_networks.rb:264:in `new'
    from /home/technoman/.vagrant.d/gems/gems/vagrant-libvirt-0.0.36/lib/vagrant-libvirt/action/create_networks.rb:264:in `get_host_ip_addr'
    from /home/technoman/.vagrant.d/gems/gems/vagrant-libvirt-0.0.36/lib/vagrant-libvirt/action/create_networks.rb:126:in `handle_ip_option'
    from /home/technoman/.vagrant.d/gems/gems/vagrant-libvirt-0.0.36/lib/vagrant-libvirt/action/create_networks.rb:66:in `block (2 levels) in call'
    from /home/technoman/.vagrant.d/gems/gems/vagrant-libvirt-0.0.36/lib/vagrant-libvirt/action/create_networks.rb:36:in `each'
    from /home/technoman/.vagrant.d/gems/gems/vagrant-libvirt-0.0.36/lib/vagrant-libvirt/action/create_networks.rb:36:in `block in call'
    from /home/technoman/.vagrant.d/gems/gems/vagrant-libvirt-0.0.36/lib/vagrant-libvirt/action/create_networks.rb:33:in `synchronize'
    from /home/technoman/.vagrant.d/gems/gems/vagrant-libvirt-0.0.36/lib/vagrant-libvirt/action/create_networks.rb:33:in `call'
    from /usr/share/vagrant/lib/vagrant/action/warden.rb:34:in `call'
    from /home/technoman/.vagrant.d/gems/gems/vagrant-cachier-1.2.1/lib/vagrant-cachier/action/install_buckets.rb:14:in `call'
    from /usr/share/vagrant/lib/vagrant/action/warden.rb:34:in `call'
    from /usr/share/vagrant/lib/vagrant/action/builtin/provision.rb:80:in `call'
    from /usr/share/vagrant/lib/vagrant/action/warden.rb:34:in `call'
    from /home/technoman/.vagrant.d/gems/gems/vagrant-cachier-1.2.1/lib/vagrant-cachier/action/configure_bucket_root.rb:20:in `call'
    from /usr/share/vagrant/lib/vagrant/action/warden.rb:34:in `call'
    from /usr/share/vagrant/lib/vagrant/action/warden.rb:95:in `block in finalize_action'
    from /usr/share/vagrant/lib/vagrant/action/warden.rb:34:in `call'
    from /usr/share/vagrant/lib/vagrant/action/builder.rb:116:in `call'
    from /usr/share/vagrant/lib/vagrant/action/runner.rb:66:in `block in run'
    from /usr/share/vagrant/lib/vagrant/util/busy.rb:19:in `busy'
    from /usr/share/vagrant/lib/vagrant/action/runner.rb:66:in `run'
    from /usr/share/vagrant/lib/vagrant/action/builtin/call.rb:53:in `call'
    from /usr/share/vagrant/lib/vagrant/action/warden.rb:34:in `call'
    from /usr/share/vagrant/lib/vagrant/action/warden.rb:95:in `block in finalize_action'
    from /usr/share/vagrant/lib/vagrant/action/warden.rb:34:in `call'
    from /usr/share/vagrant/lib/vagrant/action/builder.rb:116:in `call'
    from /usr/share/vagrant/lib/vagrant/action/runner.rb:66:in `block in run'
    from /usr/share/vagrant/lib/vagrant/util/busy.rb:19:in `busy'
    from /usr/share/vagrant/lib/vagrant/action/runner.rb:66:in `run'
    from /usr/share/vagrant/lib/vagrant/action/builtin/call.rb:53:in `call'
    from /usr/share/vagrant/lib/vagrant/action/warden.rb:34:in `call'
    from /usr/share/vagrant/lib/vagrant/action/builtin/config_validate.rb:25:in `call'
    from /usr/share/vagrant/lib/vagrant/action/warden.rb:34:in `call'
    from /usr/share/vagrant/lib/vagrant/action/warden.rb:95:in `block in finalize_action'
    from /usr/share/vagrant/lib/vagrant/action/warden.rb:34:in `call'
    from /usr/share/vagrant/lib/vagrant/action/builder.rb:116:in `call'
    from /usr/share/vagrant/lib/vagrant/action/runner.rb:66:in `block in run'
    from /usr/share/vagrant/lib/vagrant/util/busy.rb:19:in `busy'
    from /usr/share/vagrant/lib/vagrant/action/runner.rb:66:in `run'
    from /usr/share/vagrant/lib/vagrant/action/builtin/call.rb:53:in `call'
    from /usr/share/vagrant/lib/vagrant/action/warden.rb:34:in `call'
    from /usr/share/vagrant/lib/vagrant/action/builtin/config_validate.rb:25:in `call'
    from /usr/share/vagrant/lib/vagrant/action/warden.rb:34:in `call'
    from /home/technoman/.vagrant.d/gems/gems/vagrant-triggers-0.5.3/lib/vagrant-triggers/action/trigger.rb:17:in `call'
    from /usr/share/vagrant/lib/vagrant/action/warden.rb:34:in `call'
    from /home/technoman/.vagrant.d/gems/gems/vagrant-triggers-0.5.3/lib/vagrant-triggers/action/trigger.rb:17:in `call'
    from /usr/share/vagrant/lib/vagrant/action/warden.rb:34:in `call'
    from /home/technoman/.vagrant.d/gems/gems/vagrant-triggers-0.5.3/lib/vagrant-triggers/action/trigger.rb:17:in `call'
    from /usr/share/vagrant/lib/vagrant/action/warden.rb:34:in `call'
    from /usr/share/vagrant/lib/vagrant/action/builder.rb:116:in `call'
    from /usr/share/vagrant/lib/vagrant/action/runner.rb:66:in `block in run'
    from /usr/share/vagrant/lib/vagrant/util/busy.rb:19:in `busy'
    from /usr/share/vagrant/lib/vagrant/action/runner.rb:66:in `run'
    from /usr/share/vagrant/lib/vagrant/machine.rb:224:in `action_raw'
    from /usr/share/vagrant/lib/vagrant/machine.rb:199:in `block in action'
    from /usr/share/vagrant/lib/vagrant/environment.rb:561:in `lock'
    from /usr/share/vagrant/lib/vagrant/machine.rb:185:in `call'
    from /usr/share/vagrant/lib/vagrant/machine.rb:185:in `action'
    from /usr/share/vagrant/lib/vagrant/batch_action.rb:82:in `block (2 levels) in run'

My .env file

export TLD=com
export DOMAIN=test.tld.$TLD
export DOMAIN1=example.$TLD
export REV_DOMAIN=$(echo $DOMAIN | tr "." "\n" | tac | tr "\n" "." | sed 's/.$/\n/g')
export REALM=${DOMAIN^^}
export SERVER_IP=192.168.14.21
export SERVER_IP1=192.168.33.21
export SERVER_IP2=$(echo $SERVER_IP1 | cut -d "." -f 1-3).$((($(echo $SERVER_IP | cut -d "." -f 4)+10)))

My Vagrant file

Vagrant.configure(2) do |config|
config.env.enable 'scripts/.env'
 config.vm.box = "centos/7"
 config.vm.define "server" do |a|
  a.vm.provider "libvirt" do |v|
    v.memory = 1024
    v.cpus = 2
    v.storage :file, :size => '20G'
  end
  a.vm.network "private_network", ip: ENV['SERVER_IP']
  a.vm.network "private_network", ip: ENV['SERVER_IP1']
  a.vm.network "private_network", ip: ENV["SERVER_IP2"]
  a.vm.synced_folder ".", "/vagrant", disabled: true
  a.vm.provision "shell", inline: <<-SHELL
   #chmod u+x /usr/local/scripts/server.sh
   #/usr/local/scripts/server.sh
   sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/g' /etc/ssh/sshd_config
   systemctl restart sshd
  SHELL
  end
end

vagrant up fails but does not fail if i do source scripts/.env before vagrant up.

@beporter
Copy link

For future googlers:

The issue here is probably that when you source .env from your shell, the values such as SERVER_IP2 are properly interpolated by your shell.

When the .env file is imported via this plugin that doesn't happen, so the literal value of ENV('SERVER_IP2') as far as your Vagrantfile is concerned is $(echo $SERVER_IP1 | cut -d "." -f 1-3).$((($(echo $SERVER_IP | cut -d "." -f 4)+10))) instead of the expected 192.168.14.31.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants