├── LICENSE ├── README.md ├── defaults └── main.yml ├── handlers └── main.yml ├── meta └── main.yml ├── tasks └── main.yml └── templates ├── default ├── dhcpd.conf ├── httpd_pxeboot.conf └── ks.cfg /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014 Steffen Prince 2 | 3 | Permission is hereby granted, free of charge, to any person 4 | obtaining a copy of this software and associated documentation 5 | files (the "Software"), to deal in the Software without 6 | restriction, including without limitation the rights to use, 7 | copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the 9 | Software is furnished to do so, subject to the following 10 | conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 17 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 19 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Ansible Role for PXE Server 2 | =========================== 3 | 4 | Ansible role for deploying a PXE Server for Centos 7 in the manner of: 5 | https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/Installation_Guide/chap-installation-server-setup.html 6 | 7 | Look in defaults/main.yml for variables that can be overridden. 8 | -------------------------------------------------------------------------------- /defaults/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | centos_iso_url: "http://mirror.rackspace.com/CentOS/7.0.1406/isos/x86_64/CentOS-7.0-1406-x86_64-DVD.iso" 4 | centos_iso: "CentOS-7.0-1406-x86_64-DVD.iso" 5 | pxe_server_ip: "192.168.0.1" 6 | rootpw: "changemeimmediately" 7 | -------------------------------------------------------------------------------- /handlers/main.yml: -------------------------------------------------------------------------------- 1 | - name: restart xinetd 2 | service: 3 | name: xinetd 4 | state: restarted 5 | 6 | - name: restart apache 7 | service: 8 | name: httpd 9 | state: restarted 10 | 11 | - name: restart dhcpd 12 | service: 13 | name: dhcpd 14 | state: restarted 15 | -------------------------------------------------------------------------------- /meta/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | galaxy_info: 3 | author: "Steffen Prince" 4 | description: Create a PXE Server for Centos 7 5 | license: MIT 6 | min_ansible_version: 1.4 7 | platforms: 8 | - name: Centos 9 | versions: 10 | - 7 11 | categories: 12 | - clustering 13 | dependencies: [] 14 | -------------------------------------------------------------------------------- /tasks/main.yml: -------------------------------------------------------------------------------- 1 | # PXE Server Role 2 | # https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/Installation_Guide/chap-installation-server-setup.html 3 | # 4 | # Commands will be labeled by section numbers taken from 5 | # 21.1.1. Configuring a PXE Server for BIOS-based Clients 6 | --- 7 | 8 | # Procedure 21.1, Step 1 9 | - name: install packages required for PXE server 10 | yum: pkg={{ item }} 11 | state=present 12 | with_items: 13 | - tftp-server 14 | - httpd 15 | - dhcp 16 | 17 | # Procedure 21.1, Step 2 18 | - name: enable tftp 19 | lineinfile: 20 | dest: /etc/xinetd.d/tftp 21 | regexp: ^disable 22 | line: DNS1={{ pxe_server_ip }} 23 | notify: restart xinetd 24 | 25 | - name: make required directories for centos7 pxe 26 | file: 27 | path: "{{ item }}" 28 | state: directory 29 | with_items: 30 | - /var/images 31 | - /var/lib/tftpboot/centos7 32 | - /tmp/cpio-root 33 | 34 | - name: make directory, readable by apache 35 | file: 36 | path: /var/pxe/centos7 37 | state: directory 38 | group: apache 39 | 40 | # Procedure 21.1, Step 3 41 | - name: template dhcpd.conf 42 | template: 43 | src: dhcpd.conf 44 | dest: /etc/dhcp/dhcpd.conf 45 | notify: restart dhcpd 46 | 47 | - name: download iso 48 | get_url: 49 | url: "{{ centos_iso_url }}" 50 | dest: "/var/images/{{ centos_iso }}" 51 | 52 | - name: create mount for iso 53 | file: 54 | path: /mnt/centos7 55 | state: directory 56 | 57 | - name: mount iso 58 | command: "mount -t iso9660 -o loop,ro /var/images/{{ centos_iso }} /mnt/centos7" 59 | args: 60 | creates: /mnt/centos7/.treeinfo 61 | 62 | # Procedure 21.1, Step 4 63 | - name: rsync iso files to pxe directory 64 | command: rsync -a /mnt/centos7/ /var/pxe/centos7 65 | 66 | - name: chown /var/pxe to group apache 67 | command: chown -R root:apache /var/pxe 68 | 69 | - name: extract syslinux rpm into tmp directory 70 | shell: > 71 | cd /tmp/cpio-root \ 72 | && rpm2cpio /var/pxe/centos7/Packages/syslinux-4.05-8.el7.x86_64.rpm \ 73 | | cpio -dimv 74 | args: 75 | creates: /tmp/cpio-root/usr/share/syslinux/pxelinux.0 76 | 77 | 78 | # Procedure 21.1, Step 5 79 | - name: rsync pxelinux.0 from extracted rpm into /var/lib/tftpboot/centos7 80 | command: > 81 | rsync -a /tmp/cpio-root/usr/share/syslinux/pxelinux.0 /var/pxe/centos7 82 | 83 | 84 | # Procedure 21.1, Step 6 85 | - name: template pxelinux config 86 | template: 87 | src: default 88 | dest: /var/lib/tftpboot/centos7/default 89 | 90 | # Procedure 21.1, Step 7 91 | - name: rsync vmlinuz 92 | command: > 93 | rsync -a /var/pxe/centos7/images/pxeboot/vmlinuz /var/lib/tftpboot/centos7/ 94 | 95 | - name: rsync initrd.img 96 | command: > 97 | rsync /var/pxe/centos7/images/pxeboot/initrd.img /var/lib/tftpboot/centos7/ 98 | 99 | - name: template pxeboot.conf for apache 100 | template: 101 | src: httpd_pxeboot.conf 102 | dest: /etc/httpd/conf.d/pxeboot.conf 103 | notify: restart apache 104 | 105 | - name: template kickstart file into apaches pxe dir 106 | template: 107 | src: ks.cfg 108 | dest: "/var/pxe/{{ boot_target_hostname }}.cfg" 109 | mode: 0640 110 | -------------------------------------------------------------------------------- /templates/default: -------------------------------------------------------------------------------- 1 | timeout 5 2 | default menu.c32 3 | 4 | menu title ########## PXE Boot Menu ########## 5 | label 1 6 | menu label ^1) Install CentOS 7 7 | kernel centos7/vmlinuz 8 | append initrd=centos7/initrd.img method=http://{{ pxe_server_ip }}/pxe/centos7 devfs=nomount console=ttyS1,115200 console=tty1 ks=http://{{ pxe_server_ip }}/pxe/{{ boot_target_hostname }}.cfg 9 | 10 | label 2 11 | menu label ^2) Boot from local drive 12 | 13 | localboot 14 | -------------------------------------------------------------------------------- /templates/dhcpd.conf: -------------------------------------------------------------------------------- 1 | option space pxelinux; 2 | option pxelinux.magic code 208 = string; 3 | option pxelinux.configfile code 209 = text; 4 | option pxelinux.pathprefix code 210 = text; 5 | option pxelinux.reboottime code 211 = unsigned integer 32; 6 | 7 | next-server {{ pxe_server_ip }}; 8 | filename "centos7/pxelinux.0"; 9 | -------------------------------------------------------------------------------- /templates/httpd_pxeboot.conf: -------------------------------------------------------------------------------- 1 | Alias /pxe /var/pxe/ 2 | 3 | Options Indexes FollowSymLinks 4 | 5 | -------------------------------------------------------------------------------- /templates/ks.cfg: -------------------------------------------------------------------------------- 1 | ###################################################### 2 | # Auto-generated kickstart based on rackspace install 3 | # 4 | # 08-08-2014 5 | # 6 | # Update net info and root pw before using 7 | ###################################################### 8 | 9 | #version=RHEL7 10 | # System authorization information 11 | auth --enableshadow --passalgo=sha512 12 | # Install OS instead of upgrade 13 | install 14 | # Reboot after installation 15 | reboot 16 | # Use CDROM installation media 17 | cdrom 18 | # Use text mode install 19 | text 20 | # Firewall configuration 21 | firewall --enabled --service=ssh 22 | firstboot --disable 23 | ignoredisk --only-use=sda 24 | # Keyboard layouts 25 | # old format: keyboard us 26 | # new format: 27 | keyboard --vckeymap=us --xlayouts='us' 28 | # System language 29 | lang en_US.UTF-8 30 | 31 | # Network information 32 | network --bootproto=static --device=eth0 --ip={{ eth0_ip }} --netmask={{ eth0_netmask }} --gateway={{ eth0_gateway }} --noipv6 33 | network --bootproto=static --device=eth1 --ip={{ eth1_ip }} --netmask={{ eth1_netmask }} --gateway={{ eth1_gateway }} --noipv6 34 | # Root password 35 | rootpw --plaintext {{ rootpw }} 36 | # SELinux configuration 37 | selinux --enforcing 38 | # Do not configure the X Window System 39 | skipx 40 | # System timezone 41 | timezone America/Los_Angeles --isUtc 42 | # System bootloader configuration 43 | bootloader --location=mbr --boot-drive=sda --append="net.ifnames=0 biosdevname=0 console=ttyS1,115200 console=tty1" 44 | autopart --type=lvm 45 | # Clear the Master Boot Record 46 | zerombr 47 | # Partition clearing information 48 | clearpart --all --initlabel 49 | 50 | %post 51 | 52 | # Link udev net rules to override dynamic iface naming 53 | ln -s /usr/lib/udev/rules.d/60-net.rules /etc/udev/rules.d/60-net.rules 54 | 55 | %end 56 | 57 | %packages 58 | @Core 59 | 60 | %end 61 | --------------------------------------------------------------------------------