New pxe server structure

No submodule and string replace script, j2 templates only
This commit is contained in:
Khue Doan 2021-02-12 12:37:29 +07:00
parent 45e72a3d2b
commit c2744838ab
10 changed files with 145 additions and 9 deletions

@ -1 +0,0 @@
Subproject commit a3a0e46aa64b30903d6caf394edc6d9d1e5e86da

View File

@ -0,0 +1,11 @@
FROM alpine:3
RUN apk add dhcp gettext
RUN touch /var/lib/dhcp/dhcpd.leases
COPY dhcpd.conf /etc/dhcp/dhcpd.conf
COPY start.sh /start.sh
CMD [ "/start.sh" ]

View File

@ -0,0 +1,27 @@
version: "3"
services:
dhcp:
build: ./dhcp
network_mode: host
environment:
- SUBNET
- NETMASK
- GATEWAY
- RANGE_START
- RANGE_END
- PXE_SERVER
tftp:
build: ./tftp
network_mode: host
environment:
- PXE_SERVER
volumes:
- ./mnt:/mnt
http:
build: ./http
network_mode: host
volumes:
- ./mnt:/usr/share/nginx/html/CentOS
environment:
NGINX_PORT: 80

View File

@ -0,0 +1,9 @@
FROM nginx:1.19-alpine
RUN apk add gettext
COPY ./kickstart /usr/share/nginx/html/kickstart
COPY start.sh /start.sh
CMD [ "/start.sh" ]

View File

@ -0,0 +1,10 @@
FROM alpine:3
RUN apk add tftp-hpa gettext
COPY grub.cfg /var/lib/tftpboot/grub.cfg
COPY start.sh /start.sh
CMD [ "/start.sh" ]

View File

@ -1,13 +1,13 @@
# - name: Start PXE server
# community.general.docker_compose:
# project_src: "{{ role_path }}/files/pxe-servers"
- name: Download ISO
get_url:
url: "{{ iso_url }}"
dest: "{{ role_path }}/files/images/"
# - name: Download ISO
# get_url:
# url: "{{ iso_url }}"
# dest: "{{ role_path }}/files/images/"
- name: Render environment file
template:
src: "{{ role_path }}/files/.env.j2"
dest: "{{ role_path }}/files/.env"
- name: Start PXE server
community.general.docker_compose:
project_src: "{{ role_path }}/files/pxe-servers"

View File

@ -0,0 +1,53 @@
%pre --interpreter=/bin/sh
MAC=$(ip --brief link show dev $NETWORK_DEVICE | tr -s ' ' | cut -d ' ' -f 3 | sed 's/:/-/g')
curl "http://$PXE_SERVER/kickstart/network/$MAC.ks" > /tmp/network.ks
%end
#version=RHEL8
ignoredisk --only-use=$DISK
autopart --type=lvm
# Partition clearing information
clearpart --all --initlabel --drives=$DISK
# Do not use graphical install
text
# Keyboard layouts
keyboard --vckeymap=us --xlayouts='us'
# System language
lang en_US.UTF-8
# Network information
%include /tmp/network.ks
repo --name="AppStream" --baseurl=http://$PXE_SERVER/CentOS/AppStream
# Use network installation
url --url="http://$PXE_SERVER/CentOS/"
# Disable Setup Agent on first boot
firstboot --disable
# Do not configure the X Window System
skipx
# System services
services --enabled="chronyd"
# System timezone
timezone Asia/Ho_Chi_Minh --isUtc
# Create user
user --groups=wheel --name=$USERNAME --password=$ENCRYPTED_PASSWORD --iscrypted --gecos="$USERNAME"
# Add SSH key
sshkey --username=root "$SSH_PUBLIC_KEY"
%packages
@^minimal-environment
kexec-tools
%end
%addon com_redhat_kdump --enable --reserve-mb='auto'
%end
%anaconda
pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
%end
reboot

View File

@ -0,0 +1,20 @@
option space pxelinux;
option pxelinux.magic code 208 = string;
option pxelinux.configfile code 209 = text;
option pxelinux.pathprefix code 210 = text;
option pxelinux.reboottime code 211 = unsigned integer 32;
option architecture-type code 93 = unsigned integer 16;
subnet $SUBNET netmask $NETMASK {
option routers $GATEWAY;
range $RANGE_START $RANGE_END;
class "pxeclients" {
match if substring (option vendor-class-identifier, 0, 9) = "PXEClient";
next-server $PXE_SERVER;
if option architecture-type = 00:07 {
filename "grubx64.efi";
}
}
}

View File

@ -0,0 +1,5 @@
set timeout=5
menuentry 'CentOS' {
linuxefi vmlinuz ip=dhcp inst.repo=http://$PXE_SERVER/CentOS ks=http://$PXE_SERVER/kickstart/centos8.ks
initrdefi initrd.img
}

View File

@ -0,0 +1,2 @@
network --bootproto=static --device=$NETWORK_DEVICE --ip=$IP --gateway=$GATEWAY --nameserver=$DNS --netmask=$NETMASK --ipv6=auto --activate
network --hostname=$HOSTNAME