Ansible: Vagrant: Update to os1 vagrant scripts

Do the /etc/host creation with vagrant, so it uses internal instead of
external ips (hostmanager only knew about the public ip)

Ignore errors on docker failure when 'restarting' docker in flannel
handler. If this is a clean install, we haven't run 'node' yet so docker
isn't installed so it doesn't need to be started. It would be better to
be more specific in ignoring errors though...
This commit is contained in:
Eric Paris 2015-07-07 20:55:21 -04:00
parent a008fe24bb
commit 36e991742b
6 changed files with 141 additions and 94 deletions

1
contrib/ansible/vagrant/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
openstack_config.yml

View File

@ -2,38 +2,46 @@
This deployer sets up a vagrant cluster and installs kubernetes with flannel on it.
The URI's in the Vagrantfile may need to be changed depending on the exact version of openstack which you have.
## Before you start !
If running the openstack provider, then of course, you need to modify the key credentials and so on to match your particular openstack credentials.
At the time of this writing (july 2 2015) no other providers are supported, but this recipe is pretty easy to port to virtualbox, kvm, and so on if you want.
You will need a functioning vagrant provider. Currently supported are openstack.
## USAGE
To use, first modify the Vagrantfile to reflect the machines you want.
In general all that should be needed it to run
This is easy: You just change the number of nodes.
```
vagrant up
```
Then, update the kubernetes ansible data structure to include more nodes if you want them.
If you export an env variable such as
```
export NUM_MINIONS=4
```
## Provider
The system will create that number of nodes. Default is 2.
Now make sure to install openstack provider for vagrant.
`vagrant plugin install vagrant-openstack-provider`
## Provider Specific Information
Vagrant tries to be intelligent and pick the first provider supported by your installation. If you want to specify a provider you can do so by running vagrant like so:
```
vagrant up --provider=openstack
```
### OpenStack
Make sure to install the openstack provider for vagrant.
```
vagrant plugin install vagrant-openstack-provider --plugin-version ">= 0.6.1"
```
NOTE This is a more up-to-date provider than the similar `vagrant-openstack-plugin`.
# Now, vagrant up!
Also note that current (required) versions of `vagrant-openstack-provider` are not compatible with ruby 2.2.
https://github.com/ggiamarchi/vagrant-openstack-provider/pull/237
So make sure you get at least version 0.6.1.
Now lets run it. Again, make sure you look at your openstack dashboard to see the URLs and security groups and tokens that you want. In general, you want an open security group (i.e. for port 8080 and so on) and you want an SSH key that is named that you can use to ssh into all machines, and make sure you set those in the Vagrantfile correctly. ESPECIALLY also make sure you set your tenant-name is right.
`VAGRANT_LOG=info vagrant up --provision-with=shell ; vagrant provision provision-with=ansible`
This will run a first pass provisioning, which sets up the raw machines, followed by a second pass,
which sets up kuberentes, etcd, and so on.
To use the vagrant openstack provider you will need
- Copy `openstack_config.yml.example` to `openstack_config.yml`
- Edit `openstack_config.yml` to include your relevant details.
For vagrant (1.7.2) does not seem to ever want to pick openstack as the provider. So you will need to tell it to use openstack explicitly.
[![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/contrib/ansible/vagrant/README.md?pixel)]()

View File

@ -1,91 +1,109 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :
require 'date'
require "yaml"
### This is a new provider, different then cloudbau's.
### This is a new provider, different then cloudbau's.
### RUN: vagrant plugin uninstall vagrant-openstack-plugin"
### Then RUN: "vagrant plugin install vagrant-openstack-provider"
require 'vagrant-openstack-provider'
Total=3
$num_nodes = (ENV['NUM_NODES'] || 2).to_i
VAGRANTFILE_API_VERSION = "2"
# Openstack + Hostmanager providers are best used with latest versions.
# Openstack providers are best used with latest versions.
Vagrant.require_version ">= 1.7"
### If you want to change variables in all.yml, use this snippet.
### Just add a new line below as necessary...
### Commented out since its not really required for now.
# text = File.read('../group_vars/all.yml')
# new_contents = new_contents.gsub("dns_setup: true", "dns_setup: false")
# File.open('../group_vars/all.yml', "w") {|file| file.puts new_contents }
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
prefix = DateTime.now.strftime('%s')
### vagrant up --provision-with=shell works, but name doesnt :(
config.vm.provision "bootstrap", type: "shell" do |s|
s.path ="provision.sh"
end
(1..Total).each do |i|
# multi vm config
name = "kubernetes-vm-#{i}"
config.hostmanager.enabled = true
config.hostmanager.include_offline = false
config.vm.define "#{name}" do |n|
# common config
n.vm.box = "dummy"
n.vm.box_url = "https://github.com/cloudbau/vagrant-openstack-plugin/raw/master/dummy.box"
# By default, Vagrant 1.7+ automatically inserts a different
# insecure keypair for each new VM created. The easiest way
# to use the same keypair for all the machines is to disable
# this feature and rely on the legacy insecure key.
config.ssh.insert_key = false
# Make sure the private key from the key pair is provided
n.ssh.username = "fedora"
n.ssh.private_key_path = "~/.ssh/id_rsa"
n.vm.provider :openstack do |os|
### The below parameters need to be modified per your openstack instance.
os.username = ENV['OS_USERNAME']
os.password = ENV['OS_PASSWORD']
os.flavor = "m1.small"
os.image = "Fedora 22 Cloud Base x86_64 (final)"
os.openstack_auth_url = "http://os1-public.osop.rhcloud.com:5000/v2.0/tokens/"
os.security_groups = ['default','newgroup']
os.openstack_compute_url = "http://os1-public.osop.rhcloud.com:8774/v2/4f8086dadf9b4e929b7d9f88aa5d548d"
os.server_name = name
config.ssh.username = "fedora" # login for the VM
config.vm.boot_timeout = 60*10
### Dont screw this up. AUTH can fail if you don't have tenant correct ~
os.tenant_name = "ENG Emerging Tech"
os.keypair_name = "JPeerindex"
os.region = "OS1Public"
os.floating_ip_pool = 'os1_public'
### Floating IP AUTO may or may not be a viable option for your openstack instance.
#os.floating_ip = "auto"
# This explicitly sets the order that vagrant will use by default if no --provider given
config.vm.provider "openstack"
config.vm.provider "libvirt"
config.vm.provider "virtualbox"
def set_openstack(os, config, n)
# common config
config.vm.box = "dummy"
config.vm.box_url = "https://github.com/cloudbau/vagrant-openstack-plugin/raw/master/dummy.box"
# this crap is to make it not fail if the file doesn't exist (which is ok if we are using a different provisioner)
__filename = File.join(File.dirname(__FILE__), "openstack_config.yml")
if File.exist?(__filename)
_config = YAML.load(File.open(__filename, File::RDONLY).read)
else
_config = Hash.new("")
_config['security_group'] = []
end
config.ssh.username = "fedora"
config.ssh.private_key_path = "~/.ssh/id_rsa"
config.vm.boot_timeout = 60*10
### The below parameters need to be modified per your openstack instance.
os.username = _config['os_username']
os.password = _config['os_password']
os.tenant_name = _config['os_tenant']
os.keypair_name = _config['os_ssh_key_name']
os.openstack_auth_url = _config['os_auth_url']
os.region = _config['os_region_name']
os.floating_ip_pool = _config['os_floating_ip_pool']
os.flavor = _config['os_flavor']
os.image = _config['os_image']
os.security_groups = _config['os_security_groups']
os.server_name = n.vm.hostname
end
config.vm.synced_folder ".", "/vagrant", disabled: true
nodes = Array.new()
$num_nodes.times do |i|
# multi vm config
name = "kube-node-#{i+1}"
nodes.push(name)
config.vm.define "#{name}" do |n|
n.vm.hostname = name
n.vm.provider :openstack do |os, override|
set_openstack(os, override, n)
end
n.vm.provision "bootstrap", type:"shell", path: "provision.sh"
end
end
# This is how we create the ansible inventory, see it in .vagrant
# if you want to debug, run 'VAGRANT_LOG=info vagrant up'
# and you'll see exactly how the cluster comes up via ansible inv.
groups = {
"etcd" => ["kubernetes-vm-1"],
"masters" => ["kubernetes-vm-2"],
"nodes" => ["kubernetes-vm-3"],
"all_groups:children" => ["etcd","masters","nodes"]
}
# This sets up both flannel and kube.
config.vm.provision "ansible" do |ansible|
ansible.groups = groups
ansible.playbook = "../cluster.yml"
ansible.limit = "all" #otherwise the metadata wont be there for ipv4?
ansible.extra_vars = {
}
# This is how we create the ansible inventory, see it in .vagrant
# if you want to debug, run 'VAGRANT_LOG=info vagrant up'
# and you'll see exactly how the cluster comes up via ansible inv.
groups = {
"etcd" => ["kube-master"],
"masters" => ["kube-master"],
"nodes" => nodes,
"all_groups:children" => ["etcd","masters","nodes"]
}
config.vm.define "kube-master" do |n|
name = "kube-master"
n.vm.hostname = name
n.vm.provider :openstack do |os, override|
set_openstack(os, override, n)
end
# This set up the vagrant hosts before we run the main playbook
# Today this just creates /etc/hosts so machines can talk via their
# 'internal' IPs instead of the openstack public ip.
n.vm.provision :ansible do |ansible|
ansible.groups = groups
ansible.playbook = "./vagrant-ansible.yml"
ansible.limit = "all" #otherwise the metadata wont be there for ipv4?
end
# This sets up both flannel and kube.
n.vm.provision :ansible do |ansible|
ansible.groups = groups
ansible.playbook = "../cluster.yml"
ansible.limit = "all" #otherwise the metadata wont be there for ipv4?
end
end
end

View File

@ -0,0 +1,12 @@
os_username: eparis
os_password: password
os_tenant: "RH US Business Group"
os_auth_url: "http://os1-public.osop.rhcloud.com:5000/v2.0"
os_region_name: "OS1Public"
os_ssh_key_name: "eparis"
os_flavor: "m1.small"
os_image: "Fedora 22 Cloud Base x86_64 (final)"
os_security_groups:
- "default"
#- some_other_group
os_floating_ip_pool: "os1_public"

View File

@ -1,3 +0,0 @@
echo "hello, here is a sample provisioning script that demonstrates everything works"
ls /vagrant
echo "As you can see ^ ... the shared folders even work . yay "

View File

@ -0,0 +1,11 @@
- hosts: all
sudo: yes
tasks:
- name: "Build hosts file"
lineinfile:
dest=/etc/hosts
regexp=".*{{ item }}$"
line="{{ hostvars[item].ansible_default_ipv4.address }} {{item}}"
state=present
when: hostvars[item].ansible_default_ipv4.address is defined
with_items: groups['all']