Skip to content

Instantly share code, notes, and snippets.

@lukassup
Created April 29, 2017 15:33
Show Gist options
  • Select an option

  • Save lukassup/514fcb12c0b66fb2c9fc06507cfb36f2 to your computer and use it in GitHub Desktop.

Select an option

Save lukassup/514fcb12c0b66fb2c9fc06507cfb36f2 to your computer and use it in GitHub Desktop.

Vagrant multiple hosts

$ vagrant up --parallel --provider libvirt
Bringing machine 'node1' up with 'libvirt' provider...
Bringing machine 'node2' up with 'libvirt' provider...
==> node2: Creating image (snapshot of base box volume).
==> node1: Creating image (snapshot of base box volume).
==> node2: Creating domain with the following settings...
==> node2:  -- Name:              centos-6_node2
==> node1: Creating domain with the following settings...
==> node2:  -- Domain type:       kvm
==> node1:  -- Name:              centos-6_node1
==> node2:  -- Cpus:              1
==> node1:  -- Domain type:       kvm
==> node2:  -- Memory:            512M
==> node1:  -- Cpus:              1
==> node2:  -- Management MAC:
==> node1:  -- Memory:            512M
==> node2:  -- Loader:
==> node1:  -- Management MAC:
==> node2:  -- Base box:          centos/6
==> node1:  -- Loader:
==> node2:  -- Storage pool:      default
==> node1:  -- Base box:          centos/6
==> node2:  -- Image:             /var/lib/libvirt/images/centos-6_node2.img (41G)
==> node1:  -- Storage pool:      default
==> node2:  -- Volume Cache:      default
==> node1:  -- Image:             /var/lib/libvirt/images/centos-6_node1.img (41G)
==> node2:  -- Kernel:
==> node1:  -- Volume Cache:      default
==> node2:  -- Initrd:
==> node1:  -- Kernel:
==> node2:  -- Graphics Type:     vnc
==> node1:  -- Initrd:
==> node2:  -- Graphics Port:     5900
==> node1:  -- Graphics Type:     vnc
==> node2:  -- Graphics IP:       127.0.0.1
==> node1:  -- Graphics Port:     5900
==> node2:  -- Graphics Password: Not defined
==> node1:  -- Graphics IP:       127.0.0.1
==> node2:  -- Video Type:        cirrus
==> node1:  -- Graphics Password: Not defined
==> node2:  -- Video VRAM:        9216
==> node1:  -- Video Type:        cirrus
==> node2:  -- Keymap:            en-us
==> node1:  -- Video VRAM:        9216
==> node2:  -- TPM Path:
==> node1:  -- Keymap:            en-us
==> node2:  -- INPUT:             type=mouse, bus=ps2
==> node1:  -- TPM Path:
==> node2:  -- Command line :
==> node1:  -- INPUT:             type=mouse, bus=ps2
==> node1:  -- Command line :
==> node2: Creating shared folders metadata...
==> node1: Creating shared folders metadata...
==> node2: Starting domain.
==> node1: Starting domain.
==> node2: Waiting for domain to get an IP address...
==> node1: Waiting for domain to get an IP address...
==> node1: Waiting for SSH to become available...
==> node2: Waiting for SSH to become available...
    node2:
    node2: Vagrant insecure key detected. Vagrant will automatically replace
    node2: this with a newly generated keypair for better security.
    node1:
    node1: Vagrant insecure key detected. Vagrant will automatically replace
    node1: this with a newly generated keypair for better security.
    node2:
    node2: Inserting generated public key within guest...
    node2: Removing insecure key from the guest if it's present...
    node2: Key inserted! Disconnecting and reconnecting using new SSH key...
    node1:
    node1: Inserting generated public key within guest...
    node1: Removing insecure key from the guest if it's present...
    node1: Key inserted! Disconnecting and reconnecting using new SSH key...
==> node2: Configuring and enabling network interfaces...
==> node1: Configuring and enabling network interfaces...
==> node2: Rsyncing folder: /home/user/dev/infra/centos-6/ => /vagrant
==> node1: Rsyncing folder: /home/user/dev/infra/centos-6/ => /vagrant

Login to the first node

$ vagrant ssh node1
[vagrant@localhost ~]$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 52:54:00:13:7d:c4 brd ff:ff:ff:ff:ff:ff
    inet 192.168.121.187/24 brd 192.168.121.255 scope global eth0
    inet6 fe80::5054:ff:fe13:7dc4/64 scope link
       valid_lft forever preferred_lft forever
[vagrant@localhost ~]$ logout

Login to the second node

$ vagrant ssh node2
[vagrant@localhost ~]$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 52:54:00:3e:ac:54 brd ff:ff:ff:ff:ff:ff
    inet 192.168.121.237/24 brd 192.168.121.255 scope global eth0
    inet6 fe80::5054:ff:fe3e:ac54/64 scope link
       valid_lft forever preferred_lft forever

Check connectivity

[vagrant@localhost ~]$ ping 192.168.121.187
PING 192.168.121.187 (192.168.121.187) 56(84) bytes of data.
64 bytes from 192.168.121.187: icmp_seq=1 ttl=64 time=0.708 ms
64 bytes from 192.168.121.187: icmp_seq=2 ttl=64 time=0.704 ms
64 bytes from 192.168.121.187: icmp_seq=3 ttl=64 time=0.166 ms
64 bytes from 192.168.121.187: icmp_seq=4 ttl=64 time=0.585 ms
^C
--- 192.168.121.187 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3472ms
rtt min/avg/max/mdev = 0.166/0.540/0.708/0.223 ms
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
%w(node1 node2).each do |vm_name|
config.vm.define vm_name do |node|
node.vm.box = "centos/6"
end
end
# config.vm.provision "shell", inline: <<-SHELL
# apt-get update
# apt-get install -y apache2
# SHELL
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment