Created
September 6, 2016 22:23
-
-
Save v1k0d3n/ee17327562c44ea9f99e4bd91af76515 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- mode: ruby -*- | |
# vi: set ft=ruby : | |
# CONFIG OVERRIDES LOCATED IN ./config.rb: | |
CONFIG = File.expand_path("config.rb") | |
if File.exist?(CONFIG) | |
require CONFIG | |
end | |
# PRE-UP DEFINITIONS: | |
# Let's define what plugins our project requires first: | |
missing_plugins_installed = false | |
required_plugins = %w(vagrant-env vagrant-git vagrant-openstack-provider vagrant-address vagrant-compose vagrant-hostmanager) | |
# Plugin not installed? Let's fetch/install them on behalf of the user: | |
required_plugins.each do |plugin| | |
if !Vagrant.has_plugin? plugin | |
system "vagrant plugin install #{plugin}" | |
missing_plugins_installed = true | |
end | |
end | |
# If any plugins were missing and have been installed, re-run vagrant | |
if missing_plugins_installed | |
exec "vagrant #{ARGV.join(" ")}" | |
end | |
# VAGRANT DEFINITIONS: | |
VAGRANTFILE_API_VERSION = "2" | |
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| | |
# USE HOSTMANAGER FOR INVENTORY CREATION: | |
config.hostmanager.enabled = true | |
config.hostmanager.manage_host = true | |
config.hostmanager.manage_guest = true | |
config.hostmanager.ignore_private_ip = false | |
config.hostmanager.include_offline = true | |
config.hostmanager.ip_resolver = proc do |vm, resolving_vm| | |
if hostname = (vm.ssh_info && vm.ssh_info[:host]) | |
`host #{hostname}`.split("\n").last[/(\d+\.\d+\.\d+\.\d+)/, 1] | |
end | |
end | |
config.cluster.compose "#{$kube_prefix}" do |cluster| | |
cluster.nodes($etcd_count, 'etcd') do |etcd| | |
etcd.memory = $etcd_memory | |
etcd.ansible_groups = ['etcd'] | |
end | |
cluster.nodes($master_count, 'master') do |master| | |
master.memory = $master_memory | |
master.ansible_groups = ['kube-master'] | |
end | |
cluster.nodes($worker_count, 'worker') do |worker| | |
worker.memory = $worker_memory | |
worker.ansible_groups = ['kube-node'] | |
end | |
end | |
config.cluster.ansible_groups['k8s-cluster:children'] = ['kube-master', 'kube-node'] | |
# config.hostmanager.enabled = false | |
# config.hostmanager.manage_host = true | |
# config.hostmanager.include_offline = true | |
#cluster creation | |
config.cluster.nodes.each do |node, index| | |
config.vm.define "#{node.boxname}" do |node_vm| | |
node_vm.vm.box = "#{node.box}" | |
node_vm.vm.network :private_network, ip: "#{$subnet}.#{20+node.index+1}" | |
node_vm.vm.hostname = "#{node.fqdn}" | |
# node_vm.vm.network :private_network, ip: "#{$subnet}.#{11+node.index}", # , auto_config: false # "#{node.ip}" | |
# node_vm.vm.hostname = "#{node.boxname}" | |
node_vm.hostmanager.aliases = node.aliases unless node.aliases.empty? | |
node_vm.vm.provision :hostmanager | |
node_vm.vm.provider "virtualbox" do |vb| | |
vb.name = "#{node.boxname}" | |
vb.memory = node.memory | |
vb.cpus = node.cpus | |
# vb.customize ["modifyvm", :id, "--natnet1", "#{$subnet}.0/24"] | |
end | |
if node.index == config.cluster.nodes.size - 1 | |
node_vm.vm.provision "ansible" do |ansible| | |
ansible.limit = 'all' # enable parallel provisioning | |
ansible.playbook = "kargo/cluster.yml" | |
ansible.groups = config.cluster.ansible_groups | |
# ansible.inventory_path = "provisioning/inventory.ini" | |
# Ansible debugging options (comment out when not in use): | |
# ansible.verbose = "-vvvv" | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment