Forráskód Böngészése

Added galaxy role for isc dhcp server

Till Klocke 9 éve
szülő
commit
e787b56db0

+ 27 - 0
galaxy-roles/pdellaert.dhcp_server/LICENSE.md

@@ -0,0 +1,27 @@
+Copyright (c) 2013, Philippe Dellaert
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+1. Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright
+   notice, this list of conditions and the following disclaimer in the
+   documentation and/or other materials provided with the distribution.
+3. All advertising materials mentioning features or use of this software
+   must display the following acknowledgement:
+   This product includes software developed by Philippe Dellaert.
+4. Neither the name of Philippe Dellaert nor the
+   names of its contributors may be used to endorse or promote products
+   derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY PHILIPPE DELLAERT ''AS IS'' AND ANY
+EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL PHILIPPE DELLAERT BE LIABLE FOR ANY
+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

+ 149 - 0
galaxy-roles/pdellaert.dhcp_server/README.md

@@ -0,0 +1,149 @@
+dhcp_server
+===========
+
+This role installs and configures a DHCP server.
+
+Requirements
+------------
+
+This role requires Ansible 1.4 or higher and platform requirements are listed
+in the metadata file.
+
+Role Variables
+--------------
+
+The variables that can be passed to this role and a brief description about
+them are as follows. These are all based on the configuration variables of the
+DHCP server configuration.
+
+    # Basic configuration information
+    dhcp_interfaces: eth0
+    dhcp_common_domain: example.org
+    dhcp_common_nameservers: ns1.example.org, ns2.example.org
+    dhcp_common_default_lease_time: 600
+    dhcp_common_max_lease_time: 7200
+    dhcp_common_ddns_update_style: none
+    dhcp_common_authoritative: true
+    dhcp_common_log_facility: local7
+    dhcp_common_options:
+    - opt66 code 66 = string
+    dhcp_common_parameters:
+    - filename "pxelinux.0"
+
+    # Subnet configuration
+    dhcp_subnets:
+    # Required variables example
+    - base: 192.168.1.0
+      netmask: 255.255.255.0
+    # Full list of possibilities
+    - base: 192.168.10.0
+      netmask: 255.255.255.0
+      range_start: 192.168.10.150
+      range_end: 192.168.10.200
+      routers: 192.168.10.1
+      broadcast_address: 192.168.10.255
+      domain_nameservers: 192.168.10.1, 192.168.10.2
+      domain_name: example.org
+      ntp_servers: pool.ntp.org
+      default_lease_time: 3600
+      max_lease_time: 7200
+      pools:
+      - range_start: 192.168.100.10
+        range_end: 192.168.100.20
+        rule: 'allow members of "foo"'
+        parameters:
+        - filename "pxelinux.0"
+      - range_start: 192.168.110.10
+        range_end: 192.168.110.20
+        rule: 'deny members of "foo"'
+      parameters:
+      - filename "pxelinux.0"
+
+    # Fixed lease configuration
+    dhcp_hosts:
+    - name: local-server
+      mac_address: "00:11:22:33:44:55"
+      fixed_address: 192.168.10.10
+      default_lease_time: 43200
+      max_lease_time: 86400
+      parameters:
+      - filename "pxelinux.0"
+
+    # Class configuration
+    dhcp_classes:
+    - name: foo
+      rule: 'match if substring (option vendor-class-identifier, 0, 4) = "SUNW"'
+    - name: CiscoSPA
+      rule: 'match if (( substring (option vendor-class-identifier,0,13) = "Cisco SPA504G" ) or
+             ( substring (option vendor-class-identifier,0,13) = "Cisco SPA303G" ))'
+      options:
+      - opt: 'opt66 "http://utils.opentech.local/cisco/cisco.php?mac=$MAU"'
+      - opt: 'time-offset 21600'
+
+    # Shared network configurations
+    dhcp_shared_networks:
+    - name: shared-net
+      subnets:
+      - base: 192.168.100.0
+        netmask: 255.255.255.0
+        routers: 192.168.10.1
+      parameters:
+      - filename "pxelinux.0"
+      pools:
+      - range_start: 192.168.100.10
+        range_end: 192.168.100.20
+        rule: 'allow members of "foo"'
+        parameters:
+        - filename "pxelinux.0"
+      - range_start: 192.168.110.10
+        range_end: 192.168.110.20
+        rule: 'deny members of "foo"'
+
+    # Custom if else clause
+      dhcp_ifelse:
+      - condition: 'exists user-class and option user-class = "iPXE"'
+        val: 'filename "http://my.web.server/real_boot_script.php";'
+        else:
+          - val: 'filename "pxeboot.0";'
+          - val: 'filename "pxeboot.1";'
+
+Examples
+========
+
+1) Install DHCP server on interface eth0 with one simple subnet:
+
+    - hosts: all
+      roles:
+      - role: dhcp_server
+        dhcp_interfaces: eth0
+        dhcp_common_domain: example.org
+        dhcp_common_nameservers: ns1.example.org, ns2.example.org
+        dhcp_common_default_lease_time: 600
+        dhcp_common_max_lease_time: 7200
+        dhcp_common_ddns_update_style: none
+        dhcp_common_authoritative: true
+        dhcp_common_log_facility: local7
+        dhcp_subnets:
+        - base: 192.168.10.0
+          netmask: 255.255.255.0
+          range_start: 192.168.10.150
+          range_end: 192.168.10.200
+          routers: 192.168.10.1
+
+
+Dependencies
+------------
+
+None
+
+License
+-------
+
+BSD
+
+Author Information
+------------------
+
+Philippe Dellaert
+
+

+ 7 - 0
galaxy-roles/pdellaert.dhcp_server/defaults/main.yml

@@ -0,0 +1,7 @@
+---
+dhcp_interfaces: eth0
+
+dhcp_subnets: []
+dhcp_hosts: []
+dhcp_classes: []
+dhcp_shared_networks: []

+ 4 - 0
galaxy-roles/pdellaert.dhcp_server/handlers/main.yml

@@ -0,0 +1,4 @@
+---
+- name: restart dhcpd
+  service: name={{ dhcp_service }} state=restarted
+  

+ 1 - 0
galaxy-roles/pdellaert.dhcp_server/meta/.galaxy_install_info

@@ -0,0 +1 @@
+{install_date: 'Sat Jul 25 12:30:56 2015', version: master}

+ 29 - 0
galaxy-roles/pdellaert.dhcp_server/meta/main.yml

@@ -0,0 +1,29 @@
+---
+galaxy_info:
+  author: "Philippe Dellaert"
+  company: http://dellaert.org
+  license: BSD
+  min_ansible_version: 1.4
+  platforms:
+   - name: EL
+     versions:
+      - 5
+      - 6
+   - name: Fedora
+     versions:
+      - 16
+      - 17
+      - 18
+   - name: Ubuntu
+     versions:
+      - precise
+      - quantal
+      - raring
+      - saucy
+   - name: Archlinux
+     versions:
+       - all
+  categories:
+   - system
+   - networking
+dependencies: []

+ 35 - 0
galaxy-roles/pdellaert.dhcp_server/tasks/main.yml

@@ -0,0 +1,35 @@
+---
+# Loading vars
+- name: Add the OS specific varibles
+  include_vars: "{{ ansible_os_family }}.yml"
+
+# Install DHCP server
+- name: Install the required  packages in Redhat derivatives
+  yum: name={{ dhcp_server_package }} state=installed
+  when: ansible_os_family == 'RedHat'
+
+- name: Install the required packages in Debian derivatives
+  apt: name={{ dhcp_server_package }} state=installed update_cache=yes
+  when: ansible_os_family == 'Debian'
+
+- name: Install the required packages in ArchLinux derivatives
+  pacman: name={{ dhcp_server_package }} state=installed update_cache=yes
+  when: ansible_os_family == 'Archlinux'
+
+# Generate configuration
+- name: Generate dhcpd.conf
+  template: src=dhcpd.conf.j2 dest={{ dhcp_server_config }} owner=root group=root mode=0644
+  notify:
+    - restart dhcpd
+
+# Generate service configuration
+- name: Generate DHCP service conf
+  template: src=service.conf.{{ ansible_os_family }}.j2 dest={{ dhcp_service_config }} owner=root group=root
+  when: ansible_os_family == 'RedHat' or ansible_os_family == 'Debian'
+  notify:
+    - restart dhcpd
+
+# Enable DHCP server
+- name: Start the dhcp services DHCP
+  service: name={{ dhcp_service }} state=started enabled=yes
+  

+ 212 - 0
galaxy-roles/pdellaert.dhcp_server/templates/dhcpd.conf.j2

@@ -0,0 +1,212 @@
+## dhcpd.conf
+# {{ ansible_managed }}
+# Do not edit manually
+
+{% if dhcp_omapi_port is defined %}
+omapi-port {{ dhcp_omapi_port }};
+{% endif %}
+
+# option definitions common to all supported networks...
+{% if dhcp_common_domain is defined %}
+option domain-name "{{ dhcp_common_domain }}";
+{% endif %}
+{% if dhcp_common_nameservers is defined %}
+option domain-name-servers {{ dhcp_common_nameservers }};
+{% endif %}
+
+{% if dhcp_common_default_lease_time is defined %}
+default-lease-time {{ dhcp_common_default_lease_time }};
+{% endif %}
+{% if dhcp_common_max_lease_time is defined %}
+max-lease-time {{ dhcp_common_max_lease_time }};
+{% endif %}
+
+{% if dhcp_common_ddns_update_style is defined %}
+# Use this to enable / disable dynamic dns updates globally.
+ddns-update-style {{ dhcp_common_ddns_update_style }};
+{% endif %}
+
+{% if dhcp_common_authoritative is defined %}
+# If this DHCP server is the official DHCP server for the local
+# network, the authoritative directive should be uncommented.
+authoritative;
+{% endif %}
+
+{% if dhcp_common_log_facility is defined %}
+# Use this to send dhcp log messages to a different log file (you also
+# have to hack syslog.conf to complete the redirection).
+log-facility {{ dhcp_common_log_facility }};
+{% endif %}
+
+{% if dhcp_common_options is defined %}
+#DHCP options
+{% for o in dhcp_common_options %}
+option {{ o }};
+{% endfor %}
+{% endif %}
+
+{% if dhcp_common_parameters is defined %}
+#DHCP parameters
+{% for p in dhcp_common_parameters %}
+{{ p }};
+{% endfor %}
+{% endif %}
+
+# Classes
+{% for c in dhcp_classes %}
+class "{{ c.name }}" {
+  {{ c.rule }};
+{% if c.options is defined %}
+{% for i in c.options %}
+  option {{ i.opt }};
+{% endfor %}
+{% endif %}
+}
+{% endfor %}
+
+# Subnets
+{% for s in dhcp_subnets %}
+subnet {{ s.base }} netmask {{ s.netmask }} {
+{% if s.range_start is defined %}
+  range {{ s.range_start }} {{ s.range_end }};
+{% endif %}
+{% if s.routers is defined %}
+  option routers {{ s.routers }};
+{% endif %}
+{% if s.broadcast_address is defined %}
+  option broadcast-address {{ s.broadcast_address }};
+{% endif %}
+{% if s.domain_nameservers is defined %}
+  option domain-name-servers {{ s.domain_nameservers }};
+{% endif %}
+{% if s.domain_name is defined %}
+  option domain-name "{{ s.domain_name }}";
+{% endif %}
+{% if s.ntp_servers is defined %}
+  option ntp-servers {{ s.ntp_servers }};
+{% endif %}
+{% if s.default_lease_time is defined %}
+  default-lease-time {{ s.default_lease_time }};
+{% endif %}
+{% if s.max_lease_time is defined %}
+  max-lease-time {{ s.max_lease_time }};
+{% endif %}
+{% if s.pools is defined %}
+{% for p in s.pools %}
+  pool {
+{% if p.rule is defined %}
+    {{ p.rule }};
+{% endif %}
+    range {{ p.range_start }} {{ p.range_end }};
+{% if p.parameters is defined %}
+{% for param in p.parameters %}
+    {{ param }};
+{% endfor %}
+{% endif %}
+  }
+{% endfor %}
+{% endif %}
+{% if s.parameters is defined %}
+{% for p in s.parameters %}
+  {{ p }};
+{% endfor %}
+{% endif %}
+}
+{% endfor %}
+
+# Hosts
+{% for h in dhcp_hosts %}
+host {{ h.name }} {
+  hardware ethernet {{ h.mac_address }};
+{% if h.fixed_address is defined %}
+  fixed-address {{ h.fixed_address }};
+{% endif %}
+{% if h.routers is defined %}
+  option routers {{ h.routers }};
+{% endif %}
+{% if h.broadcast_address is defined %}
+  option broadcast-address {{ h.broadcast_address }};
+{% endif %}
+{% if h.domain_nameservers is defined %}
+  option domain-name-servers {{ h.domain_nameservers }};
+{% endif %}
+{% if h.domain_name is defined %}
+  option domain-name "{{ h.domain_name }}";
+{% endif %}
+{% if h.default_lease_time is defined %}
+  default-lease-time {{ h.default_lease_time }};
+{% endif %}
+{% if h.max_lease_time is defined %}
+  max-lease-time {{ h.max_lease_time }};
+{% endif %}
+{% if h.parameters is defined %}
+{% for p in h.parameters %}
+  {{ p }};
+{% endfor %}
+{% endif %}
+}
+{% endfor %}
+
+# Shared networks
+{% for n in dhcp_shared_networks %}
+shared-network {{ n.name }} {
+{% for s in n.subnets %}
+  subnet {{ s.base }} netmask {{ s.netmask }} {
+{% if s.range_start is defined %}
+    range {{ s.range_start }} {{ s.range_end }};
+{% endif %}
+{% if s.routers is defined %}
+    option routers {{ s.routers }};
+{% endif %}
+{% if s.broadcast_address is defined %}
+    option broadcast-address {{ s.broadcast_address }};
+{% endif %}
+{% if s.domain_nameservers is defined %}
+    option domain-name-servers {{ s.domain_nameservers }};
+{% endif %}
+{% if s.domain_name is defined %}
+    option domain-name "{{ s.domain_name }}";
+{% endif %}
+{% if s.default_lease_time is defined %}
+    default-lease-time {{ s.default_lease_time }};
+{% endif %}
+{% if s.max_lease_time is defined %}
+    max-lease-time {{ s.max_lease_time }};
+{% endif %}
+{% if s.parameters is defined %}
+{% for param in s.parameters %}
+    {{ param }};
+{% endfor %}
+{% endif %}
+  }
+{% endfor %}
+{% for p in n.pools %}
+  pool {
+    {{ p.rule }};
+    range {{ p.range_start }} {{ p.range_end }};
+{% if p.parameters is defined %}
+{% for param in p.parameters %}
+    {{ param }};
+{% endfor %}
+{% endif %}
+  }
+{% endfor %}
+{% if n.parameters is defined %}
+{% for p in n.parameters %}
+  {{ p }};
+{% endfor %}
+{% endif %}
+}
+{% endfor %}
+
+{% if dhcp_ifelse is defined %}
+# If else clauses
+{% for ie in dhcp_ifelse %}
+if {{ ie.condition }} {
+    {{ ie.val }}
+}{% if ie.else is defined %}{% for e in ie.else %} else {
+    {{ e.val }}
+}{% endfor %}
+{% endif %}
+{% endfor %}
+{% endif %}

+ 3 - 0
galaxy-roles/pdellaert.dhcp_server/templates/service.conf.Debian.j2

@@ -0,0 +1,3 @@
+# On what interfaces should the DHCP server (dhcpd) serve DHCP requests?
+#       Separate multiple interfaces with spaces, e.g. "eth0 eth1".
+INTERFACES="{{ dhcp_interfaces }}"

+ 2 - 0
galaxy-roles/pdellaert.dhcp_server/templates/service.conf.RedHat.j2

@@ -0,0 +1,2 @@
+# On what interfaces should the DHCP server (dhcpd) serve DHCP requests?
+DHCPDARGS={{ dhcp_interfaces }}

+ 5 - 0
galaxy-roles/pdellaert.dhcp_server/vars/Archlinux.yml

@@ -0,0 +1,5 @@
+---
+dhcp_server_package: dhcp
+dhcp_server_config: /etc/dhcpd.conf
+dhcp_service: dhcpd4
+dhcp_service_config: []

+ 5 - 0
galaxy-roles/pdellaert.dhcp_server/vars/Debian.yml

@@ -0,0 +1,5 @@
+---
+dhcp_server_package: isc-dhcp-server
+dhcp_server_config: /etc/dhcp/dhcpd.conf
+dhcp_service: isc-dhcp-server
+dhcp_service_config: /etc/default/isc-dhcp-server

+ 5 - 0
galaxy-roles/pdellaert.dhcp_server/vars/RedHat.yml

@@ -0,0 +1,5 @@
+---
+dhcp_server_package: dhcp
+dhcp_server_config: /etc/dhcp/dhcpd.conf
+dhcp_service: dhcpd
+dhcp_service_config: /etc/sysconfig/dhcpd