├── Berksfile ├── templates └── default │ ├── ssh.erb │ ├── httpd.erb │ ├── dhcp_port.erb │ ├── isc-dhcp-server.erb │ ├── default.erb │ ├── dhcpd.conf.erb │ ├── upstart-apache2.conf.erb │ └── ks │ └── Centos6-5.minimal.ks ├── test └── integration │ └── default │ └── serverspec │ ├── spec_helper.rb │ └── localhost │ ├── httpd_spec.rb │ └── pxe_spec.rb ├── .travis.yml ├── files └── default │ └── centos_minimal_dl.sh ├── .gitignore ├── Thorfile ├── recipes ├── default.rb ├── deb.rb ├── rhel.rb ├── common.rb └── prepare_minimal_centos.rb ├── CHANGELOG.md ├── metadata.rb ├── Gemfile ├── attributes ├── default_centos_pxe_image.rb └── default.rb ├── .kitchen.yml ├── chefignore ├── .kitchen.cloud.yml ├── README.md ├── Vagrantfile └── LICENSE /Berksfile: -------------------------------------------------------------------------------- 1 | source "https://supermarket.getchef.com" 2 | 3 | metadata 4 | -------------------------------------------------------------------------------- /templates/default/ssh.erb: -------------------------------------------------------------------------------- 1 | # open ssh 2 | -A FWR -p tcp -m tcp --dport 22 -j ACCEPT 3 | -------------------------------------------------------------------------------- /test/integration/default/serverspec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | require 'serverspec' 2 | 3 | set :backend, :exec 4 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: ruby 2 | rvm: 3 | - 1.9.3 4 | script: 5 | - bundle exec foodcritic -f any . 6 | branches: 7 | only: 8 | - master -------------------------------------------------------------------------------- /files/default/centos_minimal_dl.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | URL="http://centos.itt-consulting.com/6.5/isos/x86_64/CentOS-6.5-x86_64-minimal.iso" 3 | 4 | wget -c ${URL} || curl -O ${URL} -------------------------------------------------------------------------------- /templates/default/httpd.erb: -------------------------------------------------------------------------------- 1 | # open apache port 2 | -A FWR -i <%= node['dhcp']['eth'] %> -s <%= node['dhcp']['subnet'] %>/24 -p tcp --dport <%= node['http-chef-pxe']['port'] %> -j ACCEPT 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | *# 3 | .#* 4 | \#*# 5 | .*.sw[a-z] 6 | *.un~ 7 | pkg/ 8 | 9 | # Berkshelf 10 | .vagrant 11 | /cookbooks 12 | Berksfile.lock 13 | 14 | # Bundler 15 | Gemfile.lock 16 | bin/* 17 | .bundle/* 18 | 19 | .kitchen/ 20 | .kitchen.local.yml 21 | -------------------------------------------------------------------------------- /Thorfile: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | 3 | require 'bundler' 4 | require 'bundler/setup' 5 | require 'berkshelf/thor' 6 | 7 | begin 8 | require 'kitchen/thor_tasks' 9 | Kitchen::ThorTasks.new 10 | rescue LoadError 11 | puts ">>>>> Kitchen gem not loaded, omitting tasks" unless ENV['CI'] 12 | end 13 | -------------------------------------------------------------------------------- /recipes/default.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook Name:: pxe 3 | # Recipe:: default 4 | # 5 | # Copyright (C) 2014 Denis Chekirda 6 | # 7 | # All rights reserved - Do Not Redistribute 8 | # 9 | 10 | if platform_family?("rhel") 11 | include_recipe 'pxe::rhel' 12 | elsif platform_family?("debian") 13 | include_recipe 'pxe::deb' 14 | end 15 | -------------------------------------------------------------------------------- /templates/default/dhcp_port.erb: -------------------------------------------------------------------------------- 1 | # open UDP port 2 | -A FWR -i <%= node['dhcp']['eth'] %> -s <%= node['dhcp']['subnet'] %>/24 -p udp --dport 69 -m state --state NEW,ESTABLISHED -j ACCEPT 3 | # open TCP port 4 | -A FWR -i <%= node['dhcp']['eth'] %> -s <%= node['dhcp']['subnet'] %>/24 -p tcp --dport 69 -m state --state NEW,ESTABLISHED -j ACCEPT 5 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # 1.0.5 2 | * Bug fixing. 3 | * Serverspec tests. 4 | 5 | # 1.0.4 6 | * Added checks to prevent multiple executions of mount/umount while converge. 7 | * Added support for Ubuntu 14.04 8 | 9 | # 1.0.3 10 | Chef cookbook to install PXE network booting server. 11 | * Small fixes 12 | * Added support of CentOS 6.5 and Ubuntu 12.04 13 | 14 | # 1.0.0 15 | * Initial release of pxe. 16 | -------------------------------------------------------------------------------- /templates/default/isc-dhcp-server.erb: -------------------------------------------------------------------------------- 1 | # Defaults for dhcp initscript 2 | # sourced by /etc/init.d/dhcp 3 | # installed at /etc/default/isc-dhcp-server by the maintainer scripts 4 | 5 | # 6 | # This is a POSIX shell fragment 7 | # 8 | 9 | # On what interfaces should the DHCP server (dhcpd) serve DHCP requests? 10 | # Separate multiple interfaces with spaces, e.g. "eth0 eth1". 11 | INTERFACES="<%= @eth %>" -------------------------------------------------------------------------------- /templates/default/default.erb: -------------------------------------------------------------------------------- 1 | default menu.c32 2 | prompt 0 3 | 4 | menu title PXE Special Boot Menu 5 | menu INCLUDE pxelinux.cfg/graphics.conf 6 | MENU AUTOBOOT Starting Local System in # seconds 7 | 8 | LABEL install 9 | MENU LABEL ^Install Minimal CentOS 6.5 x86_64 10 | KERNEL centos/x86_64/vmlinuz 11 | APPEND initrd=centos/x86_64/initrd.img ks=http://<%= @config %>:<%= @port %>/ks/Centos6-5.minimal.ks -------------------------------------------------------------------------------- /templates/default/dhcpd.conf.erb: -------------------------------------------------------------------------------- 1 | default-lease-time 600; 2 | max-lease-time 7200; 3 | subnet <%= @config['subnet'] %> netmask <%= @config['subnet_mask'] %> { 4 | range <%= @config['dynamic_range'] %>; 5 | option subnet-mask <%= @config['subnet_mask'] %>; 6 | option routers <%= @config['routers'] %>; 7 | option broadcast-address <%= @config['broadcast'] %>; 8 | filename "pxelinux.0"; 9 | next-server <%= @config['next_server'] %>; 10 | } -------------------------------------------------------------------------------- /recipes/deb.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook Name:: pxe 3 | # Recipe:: deb 4 | # Description:: Recipe for all Debian/Ubuntu based OS. 5 | # Copyright (C) 2014 Denis Chekirda 6 | # 7 | # All rights reserved - Do Not Redistribute 8 | # 9 | 10 | include_recipe 'apt' 11 | include_recipe 'tftp' 12 | 13 | # Installing all necesary packages 14 | node['packages'].each do |pkgs| 15 | package pkgs do 16 | action :upgrade 17 | end 18 | end 19 | 20 | include_recipe 'pxe::common' 21 | -------------------------------------------------------------------------------- /recipes/rhel.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook Name:: pxe 3 | # Recipe:: rhel 4 | # Description:: Recipe for all RHEL based OS. 5 | # Copyright (C) 2014 Denis Chekirda 6 | # 7 | # All rights reserved - Do Not Redistribute 8 | # 9 | 10 | include_recipe 'tftp' 11 | include_recipe 'iptables' 12 | 13 | node['packages'].each do |pkgs| 14 | package pkgs do 15 | action :upgrade 16 | end 17 | end 18 | 19 | iptables_rule "ssh" 20 | iptables_rule "dhcp_port" 21 | iptables_rule "httpd" 22 | 23 | include_recipe 'pxe::common' 24 | -------------------------------------------------------------------------------- /metadata.rb: -------------------------------------------------------------------------------- 1 | name 'pxe' 2 | maintainer 'Denis Chekirda' 3 | maintainer_email 'dchekirda@gmail.com' 4 | license 'All rights reserved' 5 | description 'Installs local bootstraping and installation system via PXE booting.' 6 | long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) 7 | version '1.0.5' 8 | 9 | depends "apt" 10 | depends "yum" 11 | depends "tftp" 12 | depends "apache2" 13 | depends "iptables", "~> 0.14.0" 14 | 15 | %w{rhel centos debian ubuntu}.each do |os| 16 | supports os 17 | end 18 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gem 'berkshelf' 4 | 5 | # Uncomment these lines if you want to live on the Edge: 6 | # 7 | # group :development do 8 | # gem "berkshelf", github: "berkshelf/berkshelf" 9 | # gem "vagrant", github: "mitchellh/vagrant", tag: "v1.6.3" 10 | # end 11 | # 12 | # group :plugins do 13 | # gem "vagrant-berkshelf", github: "berkshelf/vagrant-berkshelf" 14 | # gem "vagrant-omnibus", github: "schisamo/vagrant-omnibus" 15 | # end 16 | 17 | gem 'test-kitchen' 18 | gem 'kitchen-vagrant' 19 | gem 'kitchen-digitalocean' 20 | gem 'foodcritic' -------------------------------------------------------------------------------- /templates/default/upstart-apache2.conf.erb: -------------------------------------------------------------------------------- 1 | # apache2 - http server 2 | # 3 | # Apache is a web server that responds to HTTP and HTTPS requests. 4 | # Required-Start: $local_fs $remote_fs $network $syslog 5 | # Required-Stop: $local_fs $remote_fs $network $syslog 6 | 7 | description "apache2 http server" 8 | 9 | start on runlevel [2345] 10 | stop on runlevel [!2345] 11 | 12 | pre-start script 13 | mkdir -p /var/run/apache2 || true 14 | install -d -o www-data /var/lock/apache2 || true 15 | # ssl_scache shouldn't be here if we're just starting up. 16 | # (this is bad if there are several apache2 instances running) 17 | rm -f /var/run/apache2/*ssl_scache* || true 18 | end script 19 | 20 | # Give up if restart occurs 10 times in 30 seconds. 21 | respawn limit 10 30 22 | 23 | exec /usr/sbin/apache2 -D NO_DETACH 24 | respawn -------------------------------------------------------------------------------- /attributes/default_centos_pxe_image.rb: -------------------------------------------------------------------------------- 1 | default['pxe']['hostname'] = '192.168.56.5' 2 | 3 | # HTTP image dir 4 | default['http-chef-pxe']['image_name'] = 'centos' 5 | default['http-chef-pxe']['http_dir'] = '/var/www/html/' 6 | default['http-chef-pxe']['image_dir'] = "#{node['http-chef-pxe']['http_dir']}#{node['http-chef-pxe']['image_name']}" 7 | default['http-chef-pxe']['image_ks_dir'] = '/var/www/html/ks' 8 | default['http-chef-pxe']['ks_filename'] = 'Centos6-5.minimal.ks' 9 | default['http-chef-pxe']['port'] = 90 10 | default['apache']['listen_ports'] = [node['http-chef-pxe']['port']] 11 | 12 | # ISO Configuration 13 | default['iso']['name'] = 'CentOS-6.5-x86_64-minimal.iso' 14 | default['iso']['tmp_dir'] = "/tmp/#{node['iso']['name']}" 15 | default['iso']['mount_dir'] = "/tmp/mnt" 16 | 17 | # TFTP directory for netboot 18 | default['tftp']['centos_dir'] = '/var/lib/tftpboot/centos' 19 | default['tftp']['centos_arch_dir'] = "#{node['tftp']['centos_dir']}/x86_64" 20 | default['image']['url'] = 'http://ftp.tlk-l.net/pub/mirrors/centos.org/6.5/isos/x86_64/CentOS-6.5-x86_64-minimal.iso' #http://ftp.tlk-l.net/pub/mirrors/centos.org/6.5/isos/x86_64/CentOS-6.5-x86_64-minimal.iso 21 | default['download']['from_web'] = true -------------------------------------------------------------------------------- /test/integration/default/serverspec/localhost/httpd_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | if ['debian', 'ubuntu'].include?(os[:family]) 4 | 5 | describe package('apache2') do 6 | it { should be_installed } 7 | end 8 | 9 | describe service('apache2') do 10 | it { should be_enabled } 11 | it { should be_running } 12 | end 13 | 14 | describe file('/etc/apache2/sites-available/pxe-image-host.conf') do 15 | it { should be_file } 16 | it { should contain 'DocumentRoot /var/www/html/' } 17 | end 18 | 19 | describe file('/etc/apache2/ports.conf') do 20 | it { should contain 'Listen *:90' } 21 | end 22 | 23 | elsif os[:family] == 'redhat' 24 | 25 | describe package('httpd') do 26 | it { should be_installed } 27 | end 28 | 29 | describe service('httpd') do 30 | it { should be_enabled } 31 | it { should be_running } 32 | end 33 | 34 | describe file('/etc/httpd/sites-available/pxe-image-host.conf') do 35 | it { should be_file } 36 | it { should contain 'DocumentRoot /var/www/html/' } 37 | end 38 | 39 | describe file('/etc/httpd/ports.conf') do 40 | it { should contain 'Listen *:90' } 41 | end 42 | end 43 | 44 | describe file('/var/www/html') do 45 | it { should be_directory } 46 | it { should be_mode '755' } 47 | end -------------------------------------------------------------------------------- /.kitchen.yml: -------------------------------------------------------------------------------- 1 | --- 2 | driver: 3 | name: vagrant 4 | 5 | provisioner: 6 | name: chef_solo 7 | 8 | platforms: 9 | - name: ubuntu-14.04 10 | driver: 11 | customize: 12 | memory: 384 13 | cpus: 1 14 | network: 15 | - ["private_network", {'ip': '192.168.56.5'}] 16 | - name: ubuntu-12.04 17 | driver: 18 | customize: 19 | memory: 384 20 | cpus: 1 21 | network: 22 | - ["private_network", {'ip': '192.168.56.5'}] 23 | - name: centos-6.5 24 | driver: 25 | customize: 26 | memory: 384 27 | cpus: 1 28 | network: 29 | - ["private_network", {'ip': '192.168.56.5'}] 30 | - name: centos-7.0 31 | driver: 32 | customize: 33 | memory: 384 34 | cpus: 1 35 | network: 36 | - ["private_network", {'ip': '192.168.56.5'}] 37 | - name: debian-7.6 38 | driver: 39 | customize: 40 | memory: 384 41 | cpus: 1 42 | network: 43 | - ["private_network", {'ip': '192.168.56.5'}] 44 | - name: debian-6.0.10 45 | driver: 46 | customize: 47 | memory: 384 48 | cpus: 1 49 | network: 50 | - ["private_network", {'ip': '192.168.56.5'}] 51 | 52 | suites: 53 | - name: default 54 | run_list: 55 | - recipe[pxe] 56 | attributes: 57 | -------------------------------------------------------------------------------- /chefignore: -------------------------------------------------------------------------------- 1 | # Put files/directories that should be ignored in this file when uploading 2 | # or sharing to the community site. 3 | # Lines that start with '# ' are comments. 4 | 5 | # OS generated files # 6 | ###################### 7 | .DS_Store 8 | Icon? 9 | nohup.out 10 | ehthumbs.db 11 | Thumbs.db 12 | 13 | # SASS # 14 | ######## 15 | .sass-cache 16 | 17 | # EDITORS # 18 | ########### 19 | \#* 20 | .#* 21 | *~ 22 | *.sw[a-z] 23 | *.bak 24 | REVISION 25 | TAGS* 26 | tmtags 27 | *_flymake.* 28 | *_flymake 29 | *.tmproj 30 | .project 31 | .settings 32 | mkmf.log 33 | 34 | ## COMPILED ## 35 | ############## 36 | a.out 37 | *.o 38 | *.pyc 39 | *.so 40 | *.com 41 | *.class 42 | *.dll 43 | *.exe 44 | */rdoc/ 45 | 46 | # Testing # 47 | ########### 48 | .watchr 49 | .rspec 50 | spec/* 51 | spec/fixtures/* 52 | test/* 53 | features/* 54 | Guardfile 55 | Procfile 56 | 57 | # SCM # 58 | ####### 59 | .git 60 | */.git 61 | .gitignore 62 | .gitmodules 63 | .gitconfig 64 | .gitattributes 65 | .svn 66 | */.bzr/* 67 | */.hg/* 68 | */.svn/* 69 | 70 | # Berkshelf # 71 | ############# 72 | cookbooks/* 73 | tmp 74 | 75 | # Cookbooks # 76 | ############# 77 | CONTRIBUTING 78 | CHANGELOG* 79 | 80 | # Strainer # 81 | ############ 82 | Colanderfile 83 | Strainerfile 84 | .colander 85 | .strainer 86 | 87 | # Vagrant # 88 | ########### 89 | .vagrant 90 | Vagrantfile 91 | 92 | # Travis # 93 | ########## 94 | .travis.yml 95 | -------------------------------------------------------------------------------- /test/integration/default/serverspec/localhost/pxe_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | if ['debian', 'ubuntu'].include?(os[:family]) 4 | # Checks installed packages 5 | describe package('tftpd-hpa') do 6 | it { should be_installed } 7 | end 8 | 9 | describe package('isc-dhcp-server') do 10 | it { should be_installed } 11 | end 12 | 13 | describe package('syslinux') do 14 | it { should be_installed } 15 | end 16 | 17 | # Checks enabled and running services. 18 | describe service('isc-dhcp-server') do 19 | it { should be_enabled } 20 | it { should be_running } 21 | end 22 | 23 | describe service('tftpd-hpa') do 24 | it { should be_enabled } 25 | it { should be_running } 26 | end 27 | 28 | elsif os[:family] == 'redhat' 29 | # Check installed packages. 30 | describe package('tftp-server') do 31 | it { should be_installed } 32 | end 33 | 34 | describe package('dhcp') do 35 | it { should be_installed } 36 | end 37 | 38 | describe package('syslinux') do 39 | it { should be_installed } 40 | end 41 | 42 | describe package('xinetd') do 43 | it { should be_installed } 44 | end 45 | 46 | # Checks enabled and running services. 47 | describe service('dhcpd') do 48 | it { should be_enabled } 49 | it { should be_running } 50 | end 51 | 52 | describe service('xinetd') do 53 | it { should be_enabled } 54 | it { should be_running } 55 | end 56 | end 57 | 58 | describe port(69) do 59 | it { should be_listening } 60 | end 61 | 62 | describe file('/var/lib/tftpboot/pxelinux.cfg') do 63 | it { should be_directory } 64 | end 65 | 66 | describe file('/var/lib/tftpboot/pxelinux.0') do 67 | it { should be_file } 68 | end 69 | 70 | describe file('/var/lib/tftpboot/menu.c32') do 71 | it { should be_file } 72 | end 73 | 74 | describe file('/etc/dhcp/dhcpd.conf') do 75 | it { should be_file } 76 | it { should contain 'filename "pxelinux.0";' } 77 | end -------------------------------------------------------------------------------- /.kitchen.cloud.yml: -------------------------------------------------------------------------------- 1 | --- 2 | driver_config: 3 | digitalocean_api_key: <%= ENV['DIGITALOCEAN_ACCESS_TOKEN'] %> 4 | 5 | provisioner: 6 | name: chef_zero 7 | require_chef_omnibus: true 8 | 9 | platforms: 10 | - name: ubuntu-12-04-x64 11 | driver_plugin: digitalocean 12 | driver_config: 13 | image: ubuntu-12-04-x64 14 | size: 512mb 15 | region: nyc3 16 | ssh_key_ids: <%= ENV['DIGITALOCEAN_SSH_KEY_IDS'] %> 17 | ssh_key: <%= ENV['DIGITALOCEAN_SSH_KEY_PATH'] %> 18 | - name: centos-6-5-x64 19 | driver_plugin: digitalocean 20 | driver_config: 21 | image: centos-6-5-x64 22 | size: 512mb 23 | region: nyc3 24 | ssh_key_ids: <%= ENV['DIGITALOCEAN_SSH_KEY_IDS'] %> 25 | ssh_key: <%= ENV['DIGITALOCEAN_SSH_KEY_PATH'] %> 26 | - name: ubuntu-14-04-x64 27 | driver_plugin: digitalocean 28 | driver_config: 29 | image: ubuntu-14-04-x64 30 | size: 512mb 31 | region: nyc3 32 | ssh_key_ids: <%= ENV['DIGITALOCEAN_SSH_KEY_IDS'] %> 33 | ssh_key: <%= ENV['DIGITALOCEAN_SSH_KEY_PATH'] %> 34 | - name: debian-7-0-x64 35 | driver_plugin: digitalocean 36 | driver_config: 37 | image: debian-7-0-x64 38 | size: 512mb 39 | region: nyc3 40 | ssh_key_ids: <%= ENV['DIGITALOCEAN_SSH_KEY_IDS'] %> 41 | ssh_key: <%= ENV['DIGITALOCEAN_SSH_KEY_PATH'] %> 42 | - name: centos-7-0-x64 43 | driver_plugin: digitalocean 44 | driver_config: 45 | image: centos-6-5-x64 46 | size: 512mb 47 | region: nyc3 48 | ssh_key_ids: <%= ENV['DIGITALOCEAN_SSH_KEY_IDS'] %> 49 | ssh_key: <%= ENV['DIGITALOCEAN_SSH_KEY_PATH'] %> 50 | - name: debian-6-0-x64 51 | driver_plugin: digitalocean 52 | driver_config: 53 | image: debian-7-0-x64 54 | size: 512mb 55 | region: nyc3 56 | ssh_key_ids: <%= ENV['DIGITALOCEAN_SSH_KEY_IDS'] %> 57 | ssh_key: <%= ENV['DIGITALOCEAN_SSH_KEY_PATH'] %> 58 | 59 | suites: 60 | - name: default 61 | run_list: 62 | - recipe[pxe] 63 | attributes: {} 64 | -------------------------------------------------------------------------------- /attributes/default.rb: -------------------------------------------------------------------------------- 1 | if platform_family?('debian') 2 | default['packages'] = %w(dhcp3-server syslinux) 3 | elsif platform_family?('rhel') 4 | default['packages'] = %w(dhcp syslinux) 5 | end 6 | 7 | if platform?('ubuntu') && node['platform_version'] >= '14.04' 8 | set['apache']['version'] = '2.4' 9 | end 10 | 11 | # TTFP configuration. 12 | default['tftpd']['config'] = '/etc/default/tftpd-hpa' 13 | default['tftpd']['pxe_cfg'] = '/var/lib/tftpboot/pxelinux.cfg' 14 | default['tftpd']['pxelinux'] = '/var/lib/tftpboot/pxelinux.0' 15 | default['tftpd']['menu_c32'] = '/var/lib/tftpboot/menu.c32' 16 | 17 | # Files needed to TFTP. 18 | if platform_family?('debian') 19 | default['syslinux']['pxelinux'] = '/usr/lib/syslinux/pxelinux.0' 20 | default['syslinux']['menu_c32'] = '/usr/lib/syslinux/menu.c32' 21 | elsif platform_family?('rhel') 22 | default['syslinux']['pxelinux'] = '/usr/share/syslinux/pxelinux.0' 23 | default['syslinux']['menu_c32'] = '/usr/share/syslinux/menu.c32' 24 | end 25 | default['pxelinux']['menu'] = '/var/lib/tftpboot/pxelinux.cfg/default' 26 | 27 | # DHCP configuration 28 | default['dhcp']['config'] = '/etc/dhcp/dhcpd.conf' 29 | default['dhcp']['isc_dhcp'] = '/etc/default/isc-dhcp-server' 30 | default['dhcp']['subnet'] = '192.168.56.0' 31 | default['dhcp']['subnet_mask'] = '255.255.255.0' 32 | default['dhcp']['dynamic_range'] = '192.168.56.100 192.168.56.200' 33 | default['dhcp']['routers'] = '192.168.56.5' 34 | default['dhcp']['broadcast'] = '192.168.56.255' 35 | default['dhcp']['next_server'] = '192.168.56.5' 36 | default['dhcp']['eth'] = 'eth1' 37 | 38 | # Services 39 | if platform_family?('debian') 40 | if platform?('ubuntu') && node['platform_version'] >= '14.04' 41 | default['services'] = ['isc-dhcp-server', 'tftpd-hpa', 'apache2'] 42 | else 43 | default['services'] = ['isc-dhcp-server', 'tftpd-hpa'] 44 | end 45 | elsif platform_family?('rhel') 46 | default['services'] = ['dhcpd', 'xinetd'] 47 | end 48 | 49 | # Default ISO 50 | default['download']['default_image'] = true 51 | default['apache2']['upstart_init'] = '/etc/init/apache2.conf' -------------------------------------------------------------------------------- /recipes/common.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook Name:: pxe 3 | # Recipe:: common 4 | # Description:: Common recipe for RedHat and Debian based OS. 5 | # Copyright (C) 2014 Denis Chekirda 6 | # 7 | # All rights reserved - Do Not Redistribute 8 | # 9 | include_recipe 'apache2' 10 | 11 | template node['apache2']['upstart_init'] do 12 | source 'upstart-apache2.conf.erb' 13 | owner 'root' 14 | group 'root' 15 | 16 | action :create 17 | only_if { platform?('ubuntu') && node['platform_version'] >= '14.04' } 18 | end 19 | 20 | template node['dhcp']['config'] do 21 | source 'dhcpd.conf.erb' 22 | owner 'root' 23 | group 'root' 24 | 25 | variables( 26 | "config" => node['dhcp'] 27 | ) 28 | action :create 29 | end 30 | 31 | template node['dhcp']['isc_dhcp'] do 32 | source 'isc-dhcp-server.erb' 33 | owner 'root' 34 | group 'root' 35 | 36 | variables( 37 | "eth" => node['dhcp']['eth'] 38 | ) 39 | action :create 40 | end 41 | 42 | remote_file "pxelinux.0" do 43 | not_if { File.exist?('/var/lib/tftpboot/pxelinux.0') } 44 | path node['tftpd']['pxelinux'] 45 | source "file://#{node['syslinux']['pxelinux']}" 46 | action :delete 47 | end 48 | 49 | directory node['tftpd']['pxe_cfg'] do 50 | action :delete 51 | action :create 52 | end 53 | 54 | template node['pxelinux']['menu'] do 55 | source 'default.erb' 56 | action :create 57 | 58 | variables( 59 | 'config' => node['pxe']['hostname'], 60 | 'port' => node['http-chef-pxe']['port'] 61 | ) 62 | end 63 | 64 | remote_file "copy_pxelinux.0" do 65 | path node['tftpd']['pxelinux'] 66 | source "file://#{node['syslinux']['pxelinux']}" 67 | end 68 | 69 | remote_file "copy_menu.c32" do 70 | path node['tftpd']['menu_c32'] 71 | source "file://#{node['syslinux']['menu_c32']}" 72 | end 73 | 74 | if node['download']['default_image'] 75 | include_recipe 'pxe::prepare_minimal_centos' 76 | end 77 | 78 | node['services'].each do |srvs| 79 | service srvs do 80 | provider Chef::Provider::Service::Upstart if platform?("ubuntu") && node["platform_version"].to_f >= 14.04 81 | supports :restart => true, :status => true, :reload => true 82 | #if platform?("ubuntu") && node["platform_version"].to_f >= 14.04 83 | # action [:restart] 84 | #else 85 | action [:enable, :restart] 86 | #end 87 | end 88 | end 89 | -------------------------------------------------------------------------------- /recipes/prepare_minimal_centos.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook Name:: pxe 3 | # Recipe:: prepare_minimal_centos 4 | # Description:: Prepare CentOS 6.5 minimal as default netboot image. 5 | # Copyright (C) 2014 Denis Chekirda 6 | # 7 | # All rights reserved - Do Not Redistribute 8 | # 9 | listdirs = [ 10 | node['iso']['mount_dir'], 11 | node['tftp']['centos_dir'], 12 | node['tftp']['centos_arch_dir'], 13 | node['http-chef-pxe']['http_dir'], 14 | node['http-chef-pxe']['image_dir'], 15 | node['http-chef-pxe']['image_ks_dir'] 16 | ] 17 | 18 | listdirs.each do |dirs| 19 | directory dirs do 20 | recursive true 21 | action :create 22 | end 23 | end 24 | 25 | web_app "pxe-image-host" do 26 | server_name node['pxe']['hostname'] 27 | server_port node['http-chef-pxe']['port'] 28 | docroot node['http-chef-pxe']['http_dir'] 29 | allow_override 'All' 30 | directory_options '+FollowSymLinks' 31 | cookbook 'apache2' 32 | notifies :restart, "service['apache2']" 33 | end 34 | 35 | if node['download']['from_web'] 36 | remote_file node['iso']['name'] do 37 | source node['image']['url'] 38 | path node['iso']['tmp_dir'] 39 | end 40 | else 41 | cookbook_file node['iso']['name'] do 42 | path node['iso']['tmp_dir'] 43 | action :create_if_missing 44 | end 45 | end 46 | 47 | mount node['iso']['mount_dir'] do 48 | device node['iso']['tmp_dir'] 49 | fstype 'iso9660' 50 | options 'loop,ro' 51 | action [:mount] 52 | not_if {::File.exists?("#{node['http-chef-pxe']['image_dir']}/images/pxeboot/vmlinuz")} 53 | end 54 | 55 | execute 'Copy' do 56 | command "cp -ar #{node['iso']['mount_dir']}/. #{node['http-chef-pxe']['image_dir']}" 57 | not_if {::File.exists?("#{node['http-chef-pxe']['image_dir']}/images/pxeboot/vmlinuz")} 58 | end 59 | 60 | mount node['iso']['mount_dir'] do 61 | device node['iso']['tmp_dir'] 62 | action [:umount] 63 | not_if {::File.exists?("#{node['http-chef-pxe']['image_dir']}/images/pxeboot/vmlinuz")} 64 | end 65 | 66 | remote_file "initrd.img" do 67 | path "#{node['tftp']['centos_arch_dir']}/initrd.img" 68 | source "file://#{node['http-chef-pxe']['image_dir']}/images/pxeboot/initrd.img" 69 | end 70 | 71 | remote_file "vmlinuz" do 72 | path "#{node['tftp']['centos_arch_dir']}/vmlinuz" 73 | source "file:///#{node['http-chef-pxe']['image_dir']}/images/pxeboot/vmlinuz" 74 | end 75 | 76 | template "#{node['http-chef-pxe']['image_ks_dir']}/#{node['http-chef-pxe']['ks_filename']}" do 77 | source "ks/Centos6-5.minimal.ks" 78 | 79 | variables( 80 | 'hostname' => node['pxe']['hostname'], 81 | 'port' => node['http-chef-pxe']['port'] 82 | ) 83 | action :create 84 | end 85 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [](https://travis-ci.org/Rocklviv/pxe) 2 | # pxe 3 | [](https://gitter.im/Rocklviv/pxe?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) 4 | 5 | PXE boot cookbook. 6 | * Depends on [apt](https://supermarket.getchef.com/cookbooks/apt) cookbook. 7 | * Depends on [yum](https://supermarket.getchef.com/cookbooks/yum) cookbook. 8 | * Depends on [tftp](https://supermarket.getchef.com/cookbooks/tftp) cookbook. 9 | * Depends on [apache2](https://supermarket.getchef.com/cookbooks/apache2) cookbook. 10 | 11 | ## Supported Platforms 12 | Supported systems: 13 |