Add option to boot slave using pxe into bootstrap image
This functionality is required in order to perform partitioning/provisioning.
This commit is contained in:
parent
f79f81ac3b
commit
5da5f18760
32
Vagrantfile
vendored
32
Vagrantfile
vendored
@ -39,6 +39,7 @@ SYNC_TYPE = cfg["sync_type"]
|
||||
MASTER_CPUS = cfg["master_cpus"]
|
||||
SLAVES_CPUS = cfg["slaves_cpus"]
|
||||
PARAVIRT_PROVIDER = cfg.fetch('paravirtprovider', false)
|
||||
PREPROVISIONED = cfg.fetch('preprovisioned', true)
|
||||
|
||||
def ansible_playbook_command(filename, args=[])
|
||||
"ansible-playbook -v -i \"localhost,\" -c local /vagrant/bootstrap/playbooks/#{filename} #{args.join ' '}"
|
||||
@ -52,6 +53,9 @@ master_celery = ansible_playbook_command("celery.yaml", ["--skip-tags", "slave"]
|
||||
|
||||
slave_celery = ansible_playbook_command("celery.yaml", ["--skip-tags", "master"])
|
||||
|
||||
master_pxe = ansible_playbook_command("pxe.yaml")
|
||||
|
||||
|
||||
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
||||
|
||||
config.vm.define "solar-dev", primary: true do |config|
|
||||
@ -59,6 +63,7 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
||||
|
||||
config.vm.provision "shell", inline: solar_script, privileged: true
|
||||
config.vm.provision "shell", inline: master_celery, privileged: true
|
||||
config.vm.provision "shell", inline: master_pxe, privileged: true unless PREPROVISIONED
|
||||
config.vm.provision "file", source: "~/.vagrant.d/insecure_private_key", destination: "/vagrant/tmp/keys/ssh_private"
|
||||
config.vm.provision "file", source: "bootstrap/ansible.cfg", destination: "/home/vagrant/.ansible.cfg"
|
||||
config.vm.network "private_network", ip: "10.0.0.2"
|
||||
@ -101,17 +106,26 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
||||
index = i + 1
|
||||
ip_index = i + 3
|
||||
config.vm.define "solar-dev#{index}" do |config|
|
||||
# standard box with all stuff preinstalled
|
||||
config.vm.box = SLAVES_IMAGE
|
||||
|
||||
# Standard box with all stuff preinstalled
|
||||
config.vm.box = SLAVES_IMAGE
|
||||
config.vm.host_name = "solar-dev#{index}"
|
||||
|
||||
if PREPROVISIONED
|
||||
config.vm.provision "file", source: "bootstrap/ansible.cfg", destination: "/home/vagrant/.ansible.cfg"
|
||||
config.vm.provision "shell", inline: slave_script, privileged: true
|
||||
config.vm.provision "shell", inline: solar_script, privileged: true
|
||||
config.vm.provision "shell", inline: slave_celery, privileged: true
|
||||
config.vm.network "private_network", ip: "10.0.0.#{ip_index}"
|
||||
config.vm.host_name = "solar-dev#{index}"
|
||||
else
|
||||
config.vm.network "private_network", adapter: 1, ip: "10.0.0.#{ip_index}"
|
||||
config.vbguest.no_install = true
|
||||
config.ssh.username = 'root'
|
||||
config.ssh.insert_key = false
|
||||
end
|
||||
|
||||
config.vm.provider :virtualbox do |v|
|
||||
boot_order(v, ['net', 'disk'])
|
||||
v.customize [
|
||||
"modifyvm", :id,
|
||||
"--memory", SLAVES_RAM,
|
||||
@ -133,6 +147,7 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
||||
libvirt.volume_cache = 'unsafe'
|
||||
end
|
||||
|
||||
if PREPROVISIONED
|
||||
if SYNC_TYPE == 'nfs'
|
||||
config.vm.synced_folder ".", "/vagrant", type: "nfs"
|
||||
end
|
||||
@ -141,6 +156,17 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
||||
rsync__args: ["--verbose", "--archive", "--delete", "-z"]
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def boot_order(virt_config, order)
|
||||
# Boot order is specified with special flag:
|
||||
# --boot<1-4> none|floppy|dvd|disk|net
|
||||
4.times do |idx|
|
||||
device = order[idx] || 'none'
|
||||
virt_config.customize ['modifyvm', :id, "--boot#{idx + 1}", device]
|
||||
end
|
||||
end
|
||||
|
13
bootstrap/playbooks/files/dnsmasq_pxe.conf
Normal file
13
bootstrap/playbooks/files/dnsmasq_pxe.conf
Normal file
@ -0,0 +1,13 @@
|
||||
# Specify interface for dhcp server
|
||||
interface={{dhcp_interface}}
|
||||
bind-interfaces
|
||||
|
||||
# Specify IP addresses range
|
||||
dhcp-range={{dhcp_range_start}},{{dhcp_range_end}},12h
|
||||
|
||||
# Net boot file name
|
||||
dhcp-boot=tag:!nopxe,pxelinux.0
|
||||
|
||||
# Configure tftp
|
||||
enable-tftp
|
||||
tftp-root={{tftp_root}}
|
8
bootstrap/playbooks/files/nginx.cfg
Normal file
8
bootstrap/playbooks/files/nginx.cfg
Normal file
@ -0,0 +1,8 @@
|
||||
server {
|
||||
listen 8000;
|
||||
root /var/lib/tftp;
|
||||
|
||||
location / {
|
||||
autoindex on;
|
||||
}
|
||||
}
|
11
bootstrap/playbooks/files/pxelinux.cfg
Normal file
11
bootstrap/playbooks/files/pxelinux.cfg
Normal file
@ -0,0 +1,11 @@
|
||||
default vesamenu.c32
|
||||
menu title Live CD Choices
|
||||
prompt 0
|
||||
timeout 3
|
||||
menu autoboot
|
||||
|
||||
label ubuntu
|
||||
menu label Ubuntu
|
||||
kernel /ubuntu/linux
|
||||
append initrd=/ubuntu/initramfs.img verbose fetch=http://{{http_ip}}:{{http_port}}/ubuntu/root.squashfs ip=dhcp boot=live
|
||||
iappend 2
|
50
bootstrap/playbooks/pxe.yaml
Normal file
50
bootstrap/playbooks/pxe.yaml
Normal file
@ -0,0 +1,50 @@
|
||||
---
|
||||
|
||||
- name: Setup dhcp server with bootstrap image
|
||||
hosts: all
|
||||
sudo: yes
|
||||
vars:
|
||||
tftp_root: /var/lib/tftp
|
||||
dhcp_range_start: 10.0.0.42
|
||||
dhcp_range_end: 10.0.0.53
|
||||
dhcp_interface: eth1
|
||||
pxe_netboot_image: http://archive.ubuntu.com/ubuntu/dists/trusty-updates/main/installer-amd64/current/images/netboot/pxelinux.0
|
||||
pxe_netboot_menu: http://archive.ubuntu.com/ubuntu/dists/trusty-updates/main/installer-amd64/current/images/netboot/ubuntu-installer/amd64/boot-screens/vesamenu.c32
|
||||
insecure_pub_key: https://raw.githubusercontent.com/mitchellh/vagrant/master/keys/vagrant.pub
|
||||
insecure_pub_key_path: /tmp/ssh_insecure.pub
|
||||
image_builder_path: /tmp/image_builder
|
||||
http_ip: 10.0.0.2
|
||||
http_port: 8000
|
||||
|
||||
tasks:
|
||||
# Istall and configure dnsmasq
|
||||
- apt: name=dnsmasq state=present
|
||||
- file: path={{tftp_root}} state=directory
|
||||
- template: src=files/dnsmasq_pxe.conf dest=/etc/dnsmasq.d/pxe.conf
|
||||
- service: name=dnsmasq state=restarted
|
||||
- file: path="{{tftp_root}}/pxelinux.cfg" state=directory
|
||||
- template: src=files/pxelinux.cfg dest="{{tftp_root}}/pxelinux.cfg/default"
|
||||
|
||||
# Prepare pxe configs and download pxe image
|
||||
- get_url: url={{pxe_netboot_image}} dest="{{tftp_root}}/pxelinux.0"
|
||||
- get_url: url={{pxe_netboot_menu}} dest="{{tftp_root}}/vesamenu.c32"
|
||||
|
||||
# Build image
|
||||
- get_url: url={{insecure_pub_key}} dest={{insecure_pub_key_path}}
|
||||
- apt: name=debootstrap state=present
|
||||
- file: path={{tftp_root}}/ubuntu state=directory
|
||||
- git: repo=https://github.com/rustyrobot/fuel-bootstrap-image-builder dest={{image_builder_path}}
|
||||
- shell: "{{image_builder_path}}/bin/fuel-bootstrap-image 2>&1 | tee /tmp/image_build.log"
|
||||
environment:
|
||||
BOOTSTRAP_SSH_KEYS: "{{insecure_pub_key_path}}"
|
||||
DESTDIR: "{{tftp_root}}/ubuntu"
|
||||
- file: path="{{tftp_root}}/ubuntu/{{item}}" mode=0644 state=file
|
||||
with_items:
|
||||
- initramfs.img
|
||||
- linux
|
||||
- root.squashfs
|
||||
|
||||
# Configure http server to load root
|
||||
- apt: name=nginx state=present
|
||||
- template: src=files/nginx.cfg dest=/etc/nginx/conf.d/pxe_image.conf
|
||||
- service: name=nginx state=restarted
|
@ -17,3 +17,11 @@ slaves_cpus: 1
|
||||
# Uncomment following option to change it.
|
||||
# Possible options are: rsync, nfs
|
||||
# sync_type: nfs
|
||||
|
||||
# Use vagrant image in order to perform provisioning
|
||||
preprovisioned: true
|
||||
|
||||
# Use pxe bootstrap in order to bootstrap nodes
|
||||
# it should be used in order to provision nodes
|
||||
# by solar
|
||||
# preprovisioned: false
|
||||
|
Loading…
Reference in New Issue
Block a user