Skip to content

Latest commit

 

History

History

dhcp

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

DHCP

This role defines the necessary configuration files to build the site specific data for the configuration files. Installs the necessary dhcp packages and configures the firewall to allow communication.

Requirements

This role expects the dhcpd configuration to be located at /etc/dhcp/dhcp.conf

Role Variables

The following variables are defined in the defaults and should be overridden in the var directory

# vars file for dhcp-config
dhcp_host_entries:
- host: test1
  fqdn: test1.example.com
  hw_addr: e0:07:1b:ec:fd:ec
  ip_addr: 192.168.10

- host: test2
  fqdn: test2.example.com
  hw_addr: e0:07:1b:fd:a5:70
  ip_addr: 192.168.11


#
# Define the subnet entries
#
dhcp_subnet_entries:
- subnet: 192.168.11.0
  netmask: 255.255.255.0
  range: 192.168.11.50 192.168.11.99
  mask: 255.255.255.0
  router: 192.168.11.1
  broadcast: 192.168.11.255
  dns: 8.8.8.8, 8.8.4.4
  domain_search: example.com
  domain_name: example.com
  next_server: 192.168.11.33

- subnet: 192.168.12.0
  netmask: 255.255.255.0
  range: 192.168.12.50 192.168.12.99
  mask: 255.255.255.0
  router: 192.168.12.1
  broadcast: 192.168.12.255
  dns: 8.8.8.8, 8.8.4.4
  domain_search: example.com
  domain_name: example.com
  next_server: 192.168.12.33

dhcp_group_entries:
- group:
  title: '# Test group 1'
  hosts:
  - desc: '# Blade #1 - interface "ens1f0"'
    name: node1
    hw_addr: 00:0a:f7:57:e1:f0
    ip_addr: 192.168.11.121
    fqdn: node3.example.com

  - desc: '# Blade #2 - interface "ens1f0"'
    name: node2
    hw_addr: 00:0a:f7:57:dd:80
    ip_addr: 192.168.11.122
    fqdn: node4.example.com

- group:
  title: '#Test group 2 '
  hosts:
  - desc: '# Blade #3 - interface "ens1f0"'
    name: node3
    hw_addr: 00:0a:f7:57:dd:80
    ip_addr: 192.168.11.123
    fqdn: node5.example.com

  - desc: '# Blade #4 - interface "ens1f0"'
    name: node4
    hw_addr: 00:0a:f7:57:de:54
    ip_addr: 192.168.11.124
    fqdn: node6.example.com

Example generated output

# This file is autogenerated by Ansible 2.3.0.0
authorative;

default-lease-time         3600;
max-lease-time             7200;

option space PXE;
option PXE.mtftp-ip    code 1 = ip-address;
option PXE.mtftp-cport code 2 = unsigned integer 16;
option PXE.mtftp-sport code 3 = unsigned integer 16;
option PXE.mtftp-tmout code 4 = unsigned integer 8;
option PXE.mtftp-delay code 5 = unsigned integer 8;
option arch code 93 = unsigned integer 16; # RFC4578
option pxe-system-type code 93 = unsigned integer 16; # RFC4578
authorative;

# Define the hosts
host test1  {
  hardware ethernet e0:07:1b:ec:fd:ec;
  fixed-address 192.168.10.123;
  option host-name "test1.example.com";
}

host test2  {
  hardware ethernet e0:07:1b:fd:a5:70;
  fixed-address 192.168.11.123;
  option host-name "test2.example.com";
}


# Define the Subnets section of the page
#

subnet 192.168.11.0 netmask 255.255.255.0 {
     range                      192.168.11.50 192.168.11.99;
     option subnet-mask         255.255.255.0;
     option routers             192.168.11.1;
     option broadcast-address   192.168.11.255;
     option domain-name-servers 8.8.8.8, 8.8.4.4;
     option domain-search       "example.com";
     option domain-name         "example.com";

     next-server                192.168.11.33;

     class "pxeclients" {
          match if substring (option vendor-class-identifier, 0, 9) = "PXEClient";
          if option pxe-system-type = 00:02 {
                  filename "ia64/elilo.efi";
          } else if option pxe-system-type = 00:06 {
                  filename "pxelinux/bootia32.efi";
          } else if option pxe-system-type = 00:07 {
                  filename "pxelinux/bootx64.efi";
          } else {
                  filename "pxelinux.0";
          }
     }
}

subnet 192.168.12.0 netmask 255.255.255.0 {
     range                      192.168.12.50 192.168.12.99;
     option subnet-mask         255.255.255.0;
     option routers             192.168.12.1;
     option broadcast-address   192.168.12.255;
     option domain-name-servers 8.8.8.8, 8.8.4.4;
     option domain-search       "example.com";
     option domain-name         "example.com";

     next-server                192.168.12.33;

     class "pxeclients" {
          match if substring (option vendor-class-identifier, 0, 9) = "PXEClient";
          if option pxe-system-type = 00:02 {
                  filename "ia64/elilo.efi";
          } else if option pxe-system-type = 00:06 {
                  filename "pxelinux/bootia32.efi";
          } else if option pxe-system-type = 00:07 {
                  filename "pxelinux/bootx64.efi";
          } else {
                  filename "pxelinux.0";
          }
     }
}

subnet 192.168.100.0 netmask 255.255.255.0 {
     range                      192.168.100.50 192.168.100.99;
     option subnet-mask         255.255.255.0;
     option routers             192.168.100.1;
     option broadcast-address   192.168.100.255;
     option domain-name-servers 8.8.8.8, 8.8.4.4;
     option domain-search       "example.com";
     option domain-name         "example.com";

     next-server                192.168.100.33;

     class "pxeclients" {
          match if substring (option vendor-class-identifier, 0, 9) = "PXEClient";
          if option pxe-system-type = 00:02 {
                  filename "ia64/elilo.efi";
          } else if option pxe-system-type = 00:06 {
                  filename "pxelinux/bootia32.efi";
          } else if option pxe-system-type = 00:07 {
                  filename "pxelinux/bootx64.efi";
          } else {
                  filename "pxelinux.0";
          }
     }
}


#
# build out the server groups
#

# Test group 1
group {

      # Blade #1 - interface "ens1f0"
      host node1  {
      hardware ethernet 00:0a:f7:57:e1:f0;
      fixed-address 192.168.11.121;
      option host-name "node1.example.com";
      }

      # Blade #2 - interface "ens1f0"
      host node2  {
      hardware ethernet 00:0a:f7:57:dd:80;
      fixed-address 192.168.11.122;
      option host-name "node4.example.com";
      }

  }

#Test group 2
group {

      # Blade #3 - interface "ens1f0"
      host node3  {
      hardware ethernet 00:0a:f7:57:dd:80;
      fixed-address 192.168.11.123;
      option host-name "node5.example.com";
      }

      # Blade #4 - interface "ens1f0"
      host node4  {
      hardware ethernet 00:0a:f7:57:de:54;
      fixed-address 192.168.11.124;
      option host-name "node6.example.com";
      }

  }


Dependencies

None:

Example Playbook

  • hosts: dhcp become: yes

    remote_user: userx

build a DHCP server and configured it

pre_tasks:

  • debug: msg: "Development Playbook to install a dhcp server and get it running"

roles:

  • dhcp

NOTE

It does not start the service because without a proper /etc/dhcp/dhcp.conf with correctly defined subnets it will fail.


License
-------

Apache License 2.0


Author Information
------------------

Red Hat Community of Practice & staff of the Red Hat Open Innovation Labs.