-
Notifications
You must be signed in to change notification settings - Fork 46
WIP: PXE boot server (for kickstarting hardware) #181
Changes from all commits
5e4e388
7d5a110
756ff02
b450c67
f3ac30b
5cdab13
fc58844
ee31738
ecbb36d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[pxeserver] | ||
vmtest1.i.gensoukyou.net ansible_host=10.21.3.31 | ||
|
||
[pxeserver:vars] | ||
pxeboot_nameservers=10.21.254.1 | ||
pxeboot_server_address=10.21.3.31 | ||
pxeboot_netmask=255.255.255.0 | ||
pxeboot_gateway=10.21.3.1 | ||
pxeboot_subnet=10.21.3.0 | ||
pxeboot_next_server=127.0.0.1 | ||
pxeboot_range_low=10.21.3.10 | ||
pxeboot_range_high=10.21.3.20 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
--- | ||
# Variables for the infrastructure are in inventory/pxeinventory | ||
- name: Configure PXE Server | ||
hosts: pxeserver | ||
become: true | ||
|
||
# This is to try to avoid the handler issue in pre/post tasks | ||
handlers: | ||
- include: handlers/main.yml | ||
|
||
pre_tasks: | ||
- name: Check if ansible cannot be run here | ||
stat: | ||
path: /etc/no-ansible | ||
register: no_ansible | ||
|
||
- name: Verify if we can run ansible | ||
assert: | ||
that: | ||
- "not no_ansible.stat.exists" | ||
msg: "/etc/no-ansible exists - skipping run on this node" | ||
#- name: Verify parameters | ||
# assert: | ||
# that: | ||
# - '{{ pxeboot_nameservers }}' | ||
# - '{{ pxeboot_server_address }}' | ||
# - '{{ pxeboot_netmask }}' | ||
# - '{{ pxeboot_gateway }}' | ||
# - '{{ pxeboot_subnet }}' | ||
# - '{{ pxeboot_next_server }}' | ||
# - '{{ pxeboot_range_low }}' | ||
# - '{{ pxeboot_range_high }}' | ||
|
||
roles: | ||
- role: pxeserver | ||
state: present | ||
|
||
post_tasks: | ||
- name: Touching run file that ansible has ran here | ||
file: | ||
path: /var/log/ansible.run | ||
state: touch | ||
mode: '0644' | ||
owner: root | ||
group: root |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--- | ||
centos_8_kickstart_mirror: 'https://mirror.phx1.us.spryservers.net/centos/8.3.2011/BaseOS/x86_64/kickstart' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# This kind of file should live in /var/lib/tftpboot/uefi/grub.cfg.01-host-mac-here | ||
# $ cat grub.cfg-01-00-50-56-ba-2b-e6 | ||
set default="Reboot" | ||
|
||
function load_video { | ||
insmod efi_gop | ||
insmod efi_uga | ||
insmod video_bochs | ||
insmod video_cirrus | ||
insmod all_video | ||
} | ||
|
||
load_video | ||
set gfxpayload=keep | ||
insmod gzio | ||
insmod part_gpt | ||
insmod ext2 | ||
|
||
# Infinite | ||
set timeout=-1 | ||
|
||
menuentry 'Reboot' { | ||
reboot | ||
} | ||
|
||
### BEGIN /etc/grub.d/10_linux ### | ||
menuentry 'Install centos-8-x86_64 for host (DESTROYS DATA!)' --class fedora --class gnu-linux --class gnu --class os { | ||
linuxefi centos-8-x86_64-vmlinuz nofb ks=http://10.21.3.31/testkickstart.cfg mpath console=tty0 | ||
initrdefi centos-8-x86_64-initrd.img | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
- name: 'reload nginx' | ||
service: | ||
name: nginx | ||
state: restarted | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
--- | ||
- name: 'install tftp, nginx for serving kickstart configuration' | ||
package: | ||
name: | ||
- tftp-server | ||
- nginx | ||
|
||
- name: 'ensure /var/www' | ||
file: | ||
path: '/var/www' | ||
state: directory | ||
mode: '0755' | ||
owner: root | ||
group: root | ||
|
||
- name: 'ensure /var/www/html' | ||
file: | ||
path: '/var/www/html' | ||
state: directory | ||
mode: '0755' | ||
owner: root | ||
group: nginx | ||
|
||
- name: 'nginx configuration' | ||
template: | ||
src: nginx.conf.j2 | ||
dest: /etc/nginx/nginx.conf | ||
notify: 'reload nginx' | ||
|
||
- name: 'Ensure nginx is running' | ||
service: | ||
name: nginx | ||
state: started | ||
enabled: true | ||
|
||
- name: Enable tftp server socket | ||
systemd: | ||
name: tftp.socket | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would really rather not use tftp. It's insecure, old as heck, and udp i.e. Slow. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. UEFI can probably load the boot files over HTTP, but I'm not sure if that's an option for BIOS. Since this is only for loading the boot files when initially installing a host, is the slowness / security an issue? The TFTP server should only be exposed to the network from which the servers get installed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. UEFI not only supports HTTP, but HTTPS (with certificate verification). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TFTP also has other nasty problems: being able to send a UDP packet to the client is Game Over. I strongly recommend making sure the “network” is just a single cable. |
||
state: started | ||
enabled: true | ||
|
||
- name: 'Create UEFI PXE-boot configuration directory' | ||
file: | ||
mode: '0755' | ||
path: '/var/lib/tftpboot/uefi' | ||
state: directory | ||
|
||
# Are there better ways to get these same files into the tftpboot directory? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can add a reposync to a local mirror later on. This is good enough for now. Can you log an issue and link to it in this via an @todo or something? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. EDIT: oops, replied to the wrong comment :-) |
||
# Downloading things from the internet feels wrong... | ||
- name: 'Download CentOS 8 UEFI boot files into the tftpboot directory' | ||
get_url: | ||
mode: '0644' | ||
url: '{{ centos_8_kickstart_mirror | mandatory }}/{{ item.value }}' | ||
dest: '/var/lib/tftpboot/{{ item.key }}' | ||
loop: "{{ bootfiles | dict2items }}" | ||
vars: | ||
bootfiles: | ||
# values are relative to the value of the mirror | ||
'uefi/BOOTX64.EFI': 'EFI/BOOT/BOOTX64.EFI' | ||
'uefi/grubx64.efi': 'EFI/BOOT/grubx64.efi' | ||
'centos-8-x86_64-vmlinuz': 'images/pxeboot/vmlinuz' | ||
'centos-8-x86_64-initrd.img': 'images/pxeboot/initrd.img' | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Simple HTTP-only server for serving kickstart files from under /var/www/html | ||
user nginx; | ||
worker_processes auto; | ||
error_log /var/log/nginx/error.log; | ||
pid /run/nginx.pid; | ||
|
||
# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic. | ||
include /usr/share/nginx/modules/*.conf; | ||
|
||
events { | ||
worker_connections 1024; | ||
} | ||
|
||
http { | ||
log_format main '$remote_addr - $remote_user [$time_local] "$request" ' | ||
'$status $body_bytes_sent "$http_referer" ' | ||
'"$http_user_agent" "$http_x_forwarded_for"'; | ||
|
||
access_log /var/log/nginx/access.log main; | ||
|
||
sendfile on; | ||
tcp_nopush on; | ||
tcp_nodelay on; | ||
keepalive_timeout 65; | ||
types_hash_max_size 2048; | ||
|
||
include /etc/nginx/mime.types; | ||
default_type application/octet-stream; | ||
|
||
include /etc/nginx/conf.d/*.conf; | ||
|
||
server { | ||
listen 80 default_server; | ||
listen [::]:80 default_server; | ||
server_name _; | ||
root /var/www/html; | ||
|
||
location / { | ||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leaving a note here so as not to be forgotten. Please update the include statement with the new
import_tasks
as ansible docs suggest.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a lint check to reject commits which perform this (unwanted) behavior? Is it possible?