Friday, 20 September 2013

Set IPs on vagrant-lxc VMs

Cross-communication is always nice.

VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

  config.vm.define "web", primary: true do |web|
    web.vm.box = "quantal64"
    web.vm.provider :lxc do |lxc|
      lxc.customize 'network.ipv4', '10.0.3.100/32'
    end
  end

  config.vm.define "db" do |db|
    db.vm.box = "quantal64"
    db.vm.provider :lxc do |lxc|
      lxc.customize 'network.ipv4', '10.0.3.101/32'
    end
  end

end


FYI, versioning info:

vagrant -v
Vagrant 1.3.3

vagrant plugin list
vagrant-lxc (0.6.0)

2 comments:

  1. If you use "config.vm.hostname", the ip will defined will be deleted.
    That is because setting the hostname makes:
    comm.sudo("ifdown -a; ifup -a; ifup -a --allow=hotplug")
    https://github.com/mitchellh/vagrant/blob/079a6edade732f13f42d266c8536d437a521154e/plugins/guests/ubuntu/cap/change_host_name.rb

    And that command deletes our defined ip.

    ReplyDelete
  2. Another approach:
    Vagrantfile:
    config.vm.provision "shell", inline: "/sbin/ip addr add 10.0.3.100/32 dev eth0"


    vagrant provision puppetmaster --provision-with shell

    ReplyDelete

Note: only a member of this blog may post a comment.

Interview questions: 2020-12

Terraform provider vs provisioner Load balancing Network Load Balancer vs Application Load Balancer  Networking Layer 1 vs Layer 4 haproxy u...