Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow hosts to be specified for subnet as well #29

Merged
merged 3 commits into from
Jul 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 3 additions & 43 deletions dhcpd/files/dhcpd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ failover peer "{{ failover_peer }}" {
}
{%- endfor %}

{%- set intendation='' %}
{%- set indentation='' %}
{%- for key, config in salt['pillar.get']('dhcpd:keys', {}).items() %}
key {{ key }} {
{%- if 'algorithm' in config %}
Expand Down Expand Up @@ -221,47 +221,7 @@ zone {{ zone }} {
{%- endfor %}

{% for host, config in salt['pillar.get']('dhcpd:hosts', {}).items() %}
{%- if 'comment' in config %}
{%- for line in config.comment.splitlines() %}
# {{ line }}
{%- endfor %}
{%- endif %}
host {{ host }} {
{%- if 'allow' in config %}
{%- if config.allow is iterable and config.allow is not string %}
{%- for item in config.allow %}allow {{ item }};{%- endfor %}
{%- else %}allow {{ config.allow }};{%- endif %}
{%- endif %}
{%- if 'deny' in config %}
{%- if config.deny is iterable and config.deny is not string %}
{%- for item in config.deny %}deny {{ item }};{%- endfor %}
{%- else %}deny {{ config.deny }};{%- endif %}
{%- endif %}
{%- if 'hardware' in config %}
hardware {{ config.hardware }};
{%- endif %}
{%- if 'fixed_address' in config %}
fixed-address {{ config.fixed_address }};
{%- endif %}
{%- if 'filename' in config %}
filename "{{ config.filename }}";
{%- endif %}
{%- if 'next_server' in config %}
next-server {{ config.next_server }};
{%- endif %}
{%- if 'server_name' in config %}
server-name "{{ config.server_name }}";
{%- endif %}
{%- if 'host_name' in config %}
option host-name "{{ config.host_name }}";
{%- endif %}
{%- for option in customized.keys() %}
{%- if option in config %}
{%- if customized[option]['type'] in types_to_quote %} {% set quote = dquote %} {%- endif %}
option {{ option|replace('_', '-') }} {{ quote }}{{ config.get(option) }}{{ quote }};
{%- endif %}
{%- endfor %}
}
{%- include 'dhcpd/files/host.jinja' with context %}
{% endfor %}
{%- for shared_network, config in salt['pillar.get']('dhcpd:shared_networks', {}).items() %}
{%- if 'comment' in config %}
Expand All @@ -270,7 +230,7 @@ host {{ host }} {
{%- endfor %}
{%- endif %}
shared-network {{ shared_network }} {
{%- set intendation=' ' %}
{%- set indentation=' ' %}
{%- for subnet, config in salt['pillar.get'](
'dhcpd:shared_networks:{0}:subnets'.format(shared_network), {}).items() %}
{%- include 'dhcpd/files/subnet.jinja' with context %}
Expand Down
49 changes: 49 additions & 0 deletions dhcpd/files/host.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{%- if 'comment' in config %}
{%- for line in config.comment.splitlines() %}
{{ indentation }}# {{ line }}
{%- endfor %}
{%- endif %}
{{ indentation }}host {{ host }} {
{%- if 'allow' in config %}
{%- if config.allow is iterable and config.allow is not string %}
{%- for item in config.allow %}
{{ indentation }} allow {{ item }};
{%- endfor %}
{%- else %}
{{ indentation }} allow {{ config.allow }};
{%- endif %}
{%- endif %}
{%- if 'deny' in config %}
{%- if config.deny is iterable and config.deny is not string %}
{%- for item in config.deny %}
{{ indentation }} deny {{ item }};
{%- endfor %}
{%- else %}
{{ indentation }} deny {{ config.deny }};
{%- endif %}
{%- endif %}
{%- if 'hardware' in config %}
{{ indentation }} hardware {{ config.hardware }};
{%- endif %}
{%- if 'fixed_address' in config %}
{{ indentation }} fixed-address {{ config.fixed_address }};
{%- endif %}
{%- if 'filename' in config %}
{{ indentation }} filename "{{ config.filename }}";
{%- endif %}
{%- if 'next_server' in config %}
{{ indentation }} next-server {{ config.next_server }};
{%- endif %}
{%- if 'server_name' in config %}
{{ indentation }} server-name "{{ config.server_name }}";
{%- endif %}
{%- if 'host_name' in config %}
{{ indentation }} option host-name "{{ config.host_name }}";
{%- endif %}
{%- for option in customized.keys() %}
{%- if option in config %}
{%- if customized[option]['type'] in types_to_quote %} {% set quote = dquote %} {%- endif %}
{{ indentation }} option {{ option|replace('_', '-') }} {{ quote }}{{ config.get(option) }}{{ quote }};
{%- endif %}
{%- endfor %}
}
61 changes: 32 additions & 29 deletions dhcpd/files/subnet.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -3,89 +3,92 @@
# {{ line }}
{%- endfor %}
{%- endif %}
{{ intendation }}subnet {{ subnet }} netmask {{ config.netmask }} {
{{ indentation }}subnet {{ subnet }} netmask {{ config.netmask }} {
{%- if 'use_host_decl_names' in config %}
{{ intendation }} use-host-decl-names {{ config.use_host_decl_names }};
{{ indentation }} use-host-decl-names {{ config.use_host_decl_names }};
{%- endif %}
{%- if 'range' in config %}
{%- if 'dynamic_bootp' in config and config.dynamic_bootp %}
{{ intendation }} range dynamic-bootp {{ config.range[0] }} {{ config.range[1] }};
{{ indentation }} range dynamic-bootp {{ config.range[0] }} {{ config.range[1] }};
{%- else %}
{{ intendation }} range {{ config.range[0] }} {{ config.range[1] }};
{{ indentation }} range {{ config.range[0] }} {{ config.range[1] }};
{%- endif %}
{%- endif %}
{%- if 'broadcast_address' in config %}
{{ intendation }} option broadcast-address {{ config['broadcast_address'] }};
{{ indentation }} option broadcast-address {{ config['broadcast_address'] }};
{%- endif %}
{%- if 'domain_name_servers' in config %}
{{ intendation }} option domain-name-servers {{ config['domain_name_servers']|join(',') }};
{{ indentation }} option domain-name-servers {{ config['domain_name_servers']|join(',') }};
{%- endif %}
{%- if 'netbios_name_servers' in config %}
{{ intendation }} option netbios-name-servers {{ config['netbios_name_servers']|join(',') }};
{{ indentation }} option netbios-name-servers {{ config['netbios_name_servers']|join(',') }};
{%- endif %}
{%- if 'ntp_servers' in config %}
{{ intendation }} option ntp-servers {{ config['ntp_servers']|join(',') }};
{{ indentation }} option ntp-servers {{ config['ntp_servers']|join(',') }};
{%- endif %}
{%- if 'lpr_servers' in config %}
{{ intendation }} option lpr-servers {{ config['lpr_servers']|join(',') }};
{{ indentation }} option lpr-servers {{ config['lpr_servers']|join(',') }};
{%- endif %}
{%- if 'irc_server' in config %}
{{ intendation }} option irc-server {{ config['irc_server']|join(',') }};
{{ indentation }} option irc-server {{ config['irc_server']|join(',') }};
{%- endif %}
{%- if 'tftp_server_name' in config %}
{{ intendation }} option tftp-server-name "{{ config['tftp_server_name'] }}";
{{ indentation }} option tftp-server-name "{{ config['tftp_server_name'] }}";
{%- endif %}
{%- if 'smtp_server' in config %}
{{ intendation }} option smtp-server {{ config['smtp_server'] }};
{{ indentation }} option smtp-server {{ config['smtp_server'] }};
{%- endif %}
{%- if 'domain_name' in config %}
{{ intendation }} option domain-name "{{ config['domain_name'] }}";
{{ indentation }} option domain-name "{{ config['domain_name'] }}";
{%- endif %}
{%- if 'domain_search' in config %}
{{ intendation }} option domain-search "{{ config['domain_search']|join('","') }}";
{{ indentation }} option domain-search "{{ config['domain_search']|join('","') }}";
{%- endif %}
{%- if 'filename' in config %}
{{ intendation }} filename "{{ config['filename'] }}";
{{ indentation }} filename "{{ config['filename'] }}";
{%- endif %}
{%- if 'next_server' in config %}
{{ intendation }} next-server {{ config['next_server'] }};
{{ indentation }} next-server {{ config['next_server'] }};
{%- endif %}
{%- if 'default_lease_time' in config %}
{{ intendation }} default-lease-time {{ config['default_lease_time'] }};
{{ indentation }} default-lease-time {{ config['default_lease_time'] }};
{%- endif %}
{%- if 'max_lease_time' in config %}
{{ intendation }} max-lease-time {{ config['max_lease_time'] }};
{{ indentation }} max-lease-time {{ config['max_lease_time'] }};
{%- endif %}
{%- if 'routers' in config and config.routers is string %}
{{ intendation }} option routers {{ config.routers }};
{{ indentation }} option routers {{ config.routers }};
{%- elif 'routers' in config and config.routers is sequence %}
{{ intendation }} option routers
{{ indentation }} option routers
{%- for router in config.routers %} {{ router }}
{%- if not loop.last %},{% else %};{% endif %}
{%- endfor %}
{%- endif %}
{%- for option in customized.keys() %}
{%- if option in config %}
{%- if customized[option]['type'] in types_to_quote %} {% set quote = dquote %} {%- endif %}
{{ intendation }} option {{ option|replace('_', '-') }} {{ quote }}{{ config.get(option) }}{{ quote }};
{{ indentation }} option {{ option|replace('_', '-') }} {{ quote }}{{ config.get(option) }}{{ quote }};
{%- endif %}
{%- endfor %}
{%- for pool in salt['pillar.get']('dhcpd:subnets:{0}:pools'.format(subnet), []) %}
{{ intendation }} pool {
{{ indentation }} pool {
{%- if 'failover_peer' in pool %}
{{ intendation }} failover peer "{{ pool['failover_peer'] }}";
{{ indentation }} failover peer "{{ pool['failover_peer'] }}";
{%- endif %}
{%- if 'max_lease_time' in pool %}
{{ intendation }} max-lease-time {{ pool.max_lease_time }};
{{ indentation }} max-lease-time {{ pool.max_lease_time }};
{%- endif %}
{%- if 'range' in pool %}
{{ intendation }} range {{ pool.range[0] }} {{ pool.range[1] }};
{{ indentation }} range {{ pool.range[0] }} {{ pool.range[1] }};
{%- endif %}
{%- if 'allow' in pool %}
{{ intendation }} allow {{ pool.allow }};
{{ indentation }} allow {{ pool.allow }};
{%- elif 'deny' in pool %}
{{ intendation }} deny {{ pool.deny }};
{{ indentation }} deny {{ pool.deny }};
{%- endif %}
{{ intendation }} }
{{ indentation }} }
{%- endfor %}
{{ intendation }}}
{%- for host, config in salt['pillar.get']('dhcpd:subnets:{0}:hosts'.format(subnet), {}).items() %}
{%- include 'dhcpd/files/host.jinja' with context %}
{%- endfor %}
{{ indentation }}}
6 changes: 6 additions & 0 deletions pillar.example
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ dhcpd:
broadcast_address: 10.5.5.31
default_lease_time: 600
max_lease_time: 7200
hosts:
jake:
comment: |
Hosts can be specified for subnets, taking subnets defaults
hardware: ethernet 08:00:a7:26:c0:a9
fixed_address: 10.5.5.27

# End of subnets

Expand Down