bind-formula/bind/config.sls

316 lines
11 KiB
Text
Raw Normal View History

{% from "bind/map.jinja" import map with context %}
2018-06-05 15:46:48 +02:00
{% from "bind/reverse_zone.jinja" import generate_reverse %}
{%- set key_directory = salt['pillar.get']('bind:lookup:key_directory', map.key_directory) %}
{%- set key_algorithm = salt['pillar.get']('bind:lookup:key_algorithm', map.key_algorithm) %}
{%- set key_algorithm_field = salt['pillar.get']('bind:lookup:key_algorithm_field', map.key_algorithm_field) %}
{%- set key_size = salt['pillar.get']('bind:lookup:key_size', map.key_size) %}
{%- set key_flags = {'zsk': 256, 'ksk': 257} %}
{%- if map.get('zones_directory') %}
{%- set zones_directory = map.zones_directory %}
{%- else %}
{%- set zones_directory = map.named_directory %}
{%- endif %}
include:
- bind
2018-06-04 16:42:25 +02:00
{{ map.chroot_dir }}{{ map.log_dir }}:
file.directory:
- user: root
2015-03-25 10:31:57 +07:00
- group: {{ salt['pillar.get']('bind:config:group', map.group) }}
- mode: 775
- require:
- pkg: bind
bind_restart:
service.running:
- name: {{ map.service }}
- reload: False
- watch:
2018-06-04 16:42:25 +02:00
- file: {{ map.chroot_dir }}{{ map.log_dir }}/query.log
- file: bind_key_directory
2018-06-04 16:42:25 +02:00
{{ map.chroot_dir }}{{ map.log_dir }}/query.log:
file.managed:
- replace: False
- user: {{ salt['pillar.get']('bind:config:user', map.user) }}
2015-03-25 10:31:57 +07:00
- group: {{ salt['pillar.get']('bind:config:group', map.group) }}
- mode: {{ salt['pillar.get']('bind:config:log_mode', map.log_mode) }}
- require:
2018-06-04 16:42:25 +02:00
- file: {{ map.chroot_dir }}{{ map.log_dir }}
named_directory:
file.directory:
- name: {{ map.named_directory }}
- user: {{ salt['pillar.get']('bind:config:user', map.user) }}
- group: {{ salt['pillar.get']('bind:config:group', map.group) }}
- mode: 775
- makedirs: True
- require:
- pkg: bind
{% if map.get('zones_directory') %}
bind_zones_directory:
file.directory:
- name: {{ zones_directory }}
- user: {{ salt['pillar.get']('bind:config:user', map.user) }}
- group: {{ salt['pillar.get']('bind:config:group', map.group) }}
- mode: 775
- makedirs: True
- require:
- pkg: bind
- file: named_directory
{% endif %}
bind_config:
2014-12-13 00:19:58 -07:00
file.managed:
- name: {{ map.config }}
{%- if salt['pillar.get']('bind:config:tmpl', False) %}
- source: {{ salt['pillar.get']('bind:config:tmpl') }}
{%- else %}
- source: 'salt://{{ map.config_source_dir }}/named.conf'
{%- endif %}
- template: jinja
- user: {{ salt['pillar.get']('bind:config:user', map.user) }}
- group: {{ salt['pillar.get']('bind:config:group', map.group) }}
- mode: {{ salt['pillar.get']('bind:config:mode', map.mode) }}
- context:
map: {{ map }}
- require:
- pkg: bind
- watch_in:
- service: bind
bind_local_config:
2014-12-13 00:19:58 -07:00
file.managed:
- name: {{ map.local_config }}
- source: salt://bind/files/named.conf.local.jinja
- template: jinja
- user: {{ salt['pillar.get']('bind:config:user', map.user) }}
- group: {{ salt['pillar.get']('bind:config:group', map.group) }}
- mode: {{ salt['pillar.get']('bind:config:mode', '644') }}
- context:
map: {{ map }}
zones_directory: {{ zones_directory }}
- require:
- pkg: bind
2018-06-04 16:42:25 +02:00
- file: {{ map.chroot_dir }}{{ map.log_dir }}/query.log
- watch_in:
- service: bind
2019-12-21 12:37:59 +01:00
{% if grains['os_family'] not in ['Arch', 'FreeBSD', 'Gentoo'] %}
bind_default_config:
file.managed:
- name: {{ map.default_config }}
- source: salt://{{ map.config_source_dir }}/default
- template: jinja
- user: root
- group: root
- mode: 644
- context:
map: {{ map }}
- watch_in:
- service: bind_restart
2015-11-09 20:46:35 +11:00
{% endif %}
2018-11-30 01:58:30 +01:00
{%- if salt['pillar.get']('bind:config:use_extensive_logging', False) %}
bind_logging_config:
file.managed:
- name: {{ map.logging_config }}
- source: salt://bind/files/named.conf.logging.jinja
- template: jinja
- user: {{ salt['pillar.get']('bind:config:user', map.user) }}
- group: {{ salt['pillar.get']('bind:config:group', map.group) }}
- mode: {{ salt['pillar.get']('bind:config:mode', '644') }}
- context:
map: {{ map }}
- require:
- pkg: bind
- watch_in:
- service: bind
{%- endif %}
{% if grains['os_family'] == 'Debian' %}
2014-10-16 10:54:02 +00:00
bind_key_config:
2014-12-13 00:19:58 -07:00
file.managed:
2014-10-16 10:54:02 +00:00
- name: {{ map.key_config }}
- source: 'salt://{{ map.config_source_dir }}/named.conf.key'
2014-10-16 10:54:02 +00:00
- template: jinja
- user: {{ salt['pillar.get']('bind:config:user', map.user) }}
- group: {{ salt['pillar.get']('bind:config:group', map.group) }}
- mode: {{ salt['pillar.get']('bind:config:mode', '640') }}
2014-10-16 10:54:02 +00:00
- require:
- pkg: bind
- watch_in:
- service: bind
bind_options_config:
2014-12-13 00:19:58 -07:00
file.managed:
- name: {{ map.options_config }}
- source: 'salt://{{ map.config_source_dir }}/named.conf.options'
- template: jinja
- user: {{ salt['pillar.get']('bind:config:user', map.user) }}
- group: {{ salt['pillar.get']('bind:config:group', map.group) }}
- mode: {{ salt['pillar.get']('bind:config:mode', '644') }}
- context:
key_directory: {{ map.key_directory }}
named_directory: {{ map.named_directory }}
zones_directory: {{ zones_directory }}
- require:
- pkg: bind
- watch_in:
- service: bind
bind_default_zones:
2014-12-13 00:19:58 -07:00
file.managed:
- name: {{ map.default_zones_config }}
- source: 'salt://{{ map.config_source_dir }}/named.conf.default-zones'
- template: jinja
- user: {{ salt['pillar.get']('bind:config:user', map.user) }}
- group: {{ salt['pillar.get']('bind:config:group', map.group) }}
- mode: {{ salt['pillar.get']('bind:config:mode', '644') }}
- require:
- pkg: bind
- watch_in:
- service: bind
/etc/logrotate.d/{{ map.service }}:
2014-12-13 00:19:58 -07:00
file.managed:
- source: salt://{{ map.config_source_dir }}/logrotate_bind
2014-10-19 15:24:41 +02:00
- template: jinja
2014-03-24 10:41:35 +01:00
- user: root
- group: root
- context:
map: {{ map }}
2017-10-18 22:35:21 +02:00
2017-10-29 16:46:24 +00:00
{%- if salt['pillar.get']('bind:rndc_client', False) %}
bind_rndc_client_config:
file.managed:
- name: {{ map.rndc_client_config }}
- source: salt://{{ map.config_source_dir }}/rndc.conf
- template: jinja
- user: {{ salt['pillar.get']('bind:config:user', map.user) }}
- group: {{ salt['pillar.get']('bind:config:group', map.group) }}
- mode: {{ salt['pillar.get']('bind:config:mode', '640') }}
- context:
map: {{ map }}
- require:
- pkg: bind
{%- endif %}
{% endif %}
{%- set views = {False: salt['pillar.get']('bind', {})} %}{# process non-view zones in the same loop #}
{%- do views.update(salt['pillar.get']('bind:configured_views', {})) %}
{%- for view, view_data in views|dictsort %}
Squash commits Update named.conf.local.jinja Some reorganization of the format. In the for-loop that handles configured_views: - Add if-block on lines 124-128 to allow specifying a file for your view, rather than defaulting to the name of the specified zone. This allows multiple views to serve the same zone, but use a different file. Update pillar.example Add documentation and an example on specifying the file to be used for a view, as well as documented that you should not define the top-level 'configured_zones' key when using views. Small comment update. Add comment about using ACLs and views. Create pillar-with-views.example An example of the bind pillar that defines multiple views for internal and external record sets. This doesn't include the other portion of the pillar the defines the bind config - this is zones, views and ACLs only. The config portion is not affected by this. Add more comment clarification. Add comment explaining file name requirements. The filename must match the corresponding zone name (without the .txt extension) because the config.sls jinja logic uses the filename to match to the zone when setting zone_records. It also is hardcoded to replace ".txt" with "" in order to make this match work, and so .txt extension is required for the logic to work. Update config.sls Add logic to detect a file specified in a view, and match it to a zone under available_zones to enable creating that zone file. Revert back Made a bad commit. Update with the required logic. Added an if-block to test for the file argument in the zone_data, and if found, use that view and update the zone variable to match the zone defined under available_zones. Fix variable set. Set zone based on file with the .txt extension removed. Update README.rst Add paragraph about using views. Update pillar-with-views.example Add some more comments for explanation.
2018-11-14 11:11:07 -05:00
{%- set dash_view = '-' + view if view else '' %}
{%- for zone, zone_data in view_data.get('configured_zones', {})|dictsort -%}
{%- if 'file' in zone_data %}
{%- set file = zone_data.file %}
{%- set zone = file|replace(".txt", "") %}
{%- else %}
{%- set file = salt['pillar.get']("bind:available_zones:" + zone + ":file", false) %}
{%- endif %}
{%- set zone_records = salt['pillar.get']('bind:available_zones:' + zone + ':records', {}) %}
{%- if salt['pillar.get']('bind:available_zones:' + zone + ':generate_reverse') %}
{%- do generate_reverse(
zone_records,
salt['pillar.get']('bind:available_zones:' + zone + ':generate_reverse:net'),
salt['pillar.get']('bind:available_zones:' + zone + ':generate_reverse:for_zones'),
salt['pillar.get']('bind:available_zones', {})
) %}
Squash commits Update named.conf.local.jinja Some reorganization of the format. In the for-loop that handles configured_views: - Add if-block on lines 124-128 to allow specifying a file for your view, rather than defaulting to the name of the specified zone. This allows multiple views to serve the same zone, but use a different file. Update pillar.example Add documentation and an example on specifying the file to be used for a view, as well as documented that you should not define the top-level 'configured_zones' key when using views. Small comment update. Add comment about using ACLs and views. Create pillar-with-views.example An example of the bind pillar that defines multiple views for internal and external record sets. This doesn't include the other portion of the pillar the defines the bind config - this is zones, views and ACLs only. The config portion is not affected by this. Add more comment clarification. Add comment explaining file name requirements. The filename must match the corresponding zone name (without the .txt extension) because the config.sls jinja logic uses the filename to match to the zone when setting zone_records. It also is hardcoded to replace ".txt" with "" in order to make this match work, and so .txt extension is required for the logic to work. Update config.sls Add logic to detect a file specified in a view, and match it to a zone under available_zones to enable creating that zone file. Revert back Made a bad commit. Update with the required logic. Added an if-block to test for the file argument in the zone_data, and if found, use that view and update the zone variable to match the zone defined under available_zones. Fix variable set. Set zone based on file with the .txt extension removed. Update README.rst Add paragraph about using views. Update pillar-with-views.example Add some more comments for explanation.
2018-11-14 11:11:07 -05:00
{%- endif %}
{# If we define RRs in pillar, we use the internal template to generate the zone file
otherwise, we fallback to the old behaviour and use the declared file
#}
Squash commits Update named.conf.local.jinja Some reorganization of the format. In the for-loop that handles configured_views: - Add if-block on lines 124-128 to allow specifying a file for your view, rather than defaulting to the name of the specified zone. This allows multiple views to serve the same zone, but use a different file. Update pillar.example Add documentation and an example on specifying the file to be used for a view, as well as documented that you should not define the top-level 'configured_zones' key when using views. Small comment update. Add comment about using ACLs and views. Create pillar-with-views.example An example of the bind pillar that defines multiple views for internal and external record sets. This doesn't include the other portion of the pillar the defines the bind config - this is zones, views and ACLs only. The config portion is not affected by this. Add more comment clarification. Add comment explaining file name requirements. The filename must match the corresponding zone name (without the .txt extension) because the config.sls jinja logic uses the filename to match to the zone when setting zone_records. It also is hardcoded to replace ".txt" with "" in order to make this match work, and so .txt extension is required for the logic to work. Update config.sls Add logic to detect a file specified in a view, and match it to a zone under available_zones to enable creating that zone file. Revert back Made a bad commit. Update with the required logic. Added an if-block to test for the file argument in the zone_data, and if found, use that view and update the zone variable to match the zone defined under available_zones. Fix variable set. Set zone based on file with the .txt extension removed. Update README.rst Add paragraph about using views. Update pillar-with-views.example Add some more comments for explanation.
2018-11-14 11:11:07 -05:00
{%- set zone_source = 'salt://bind/files/zone.jinja' if zone_records != {} else 'salt://' ~ map.zones_source_dir ~ '/' ~ file %}
{%- set serial_auto = salt['pillar.get']('bind:available_zones:' + zone + ':soa:serial', '') == 'auto' %}
{% if file and zone_data['type'] == 'master' and (zone_data['managed'] is not defined or zone_data['managed']) -%}
zones{{ dash_view }}-{{ zone }}{{ '.include' if serial_auto else '' }}:
2014-12-13 00:19:58 -07:00
file.managed:
- name: {{ zones_directory }}/{{ file }}{{ '.include' if serial_auto else '' }}
- source: {{ zone_source }}
- template: jinja
{% if zone_records != {} %}
- context:
zone: zones{{ dash_view }}-{{ zone }}
soa: {{ salt['pillar.get']("bind:available_zones:" + zone + ":soa") | json }}
records: {{ zone_records | json }}
include: False
{% endif %}
- user: {{ salt['pillar.get']('bind:config:user', map.user) }}
- group: {{ salt['pillar.get']('bind:config:group', map.group) }}
- mode: {{ salt['pillar.get']('bind:config:mode', '644') }}
- watch_in:
- service: bind
- require:
2015-03-25 10:30:01 +07:00
- file: named_directory
{% if map.get('zones_directory') %}
- file: bind_zones_directory
{% endif %}
{% if serial_auto %}
zones{{ dash_view }}-{{ zone }}:
module.wait:
- name: dnsutil.serial
- update: True
- zone: zones{{ dash_view }}-{{ zone }}
- watch:
- file: {{ zones_directory }}/{{ file }}.include
2015-03-22 22:07:22 +01:00
file.managed:
- name: {{ zones_directory }}/{{ file }}
- require:
- module: zones{{ dash_view }}-{{ zone }}
- source: {{ zone_source }}
- template: jinja
{% if zone_records != {} %}
- context:
zone: zones{{ dash_view }}-{{ zone }}
soa: {{ salt['pillar.get']("bind:available_zones:" + zone + ":soa") | json }}
include: {{ zones_directory }}/{{ file }}.include
{% endif %}
2015-03-22 22:07:22 +01:00
- user: {{ salt['pillar.get']('bind:config:user', map.user) }}
- group: {{ salt['pillar.get']('bind:config:group', map.group) }}
- mode: {{ salt['pillar.get']('bind:config:mode', '644') }}
- watch_in:
- service: bind
- require:
2015-03-25 10:30:01 +07:00
- file: named_directory
{% if map.get('zones_directory') %}
- file: bind_zones_directory
{% endif %}
{% endif %}
{% if zone_data['dnssec'] is defined and zone_data['dnssec'] -%}
signed{{ dash_view }}-{{ zone }}:
2015-03-22 22:07:22 +01:00
cmd.run:
- cwd: {{ zones_directory }}
- name: zonesigner -zone {{ zone }} {{ file }}
2015-03-22 22:07:22 +01:00
- prereq:
- file: zones{{ dash_view }}-{{ zone }}
{% endif %}
{% endif %}
{% if zone_data['auto-dnssec'] is defined -%}
zsk-{{ zone }}:
cmd.run:
- cwd: {{ key_directory }}
- name: dnssec-keygen -a {{ key_algorithm }} -b {{ key_size }} -n ZONE {{ zone }}
- runas: {{ map.user }}
- unless: "grep {{ key_flags.zsk }} {{ key_directory }}/K{{ zone }}.+{{ key_algorithm_field }}+*.key"
- require:
- file: bind_key_directory
2015-03-22 22:07:22 +01:00
ksk-{{ zone }}:
cmd.run:
- cwd: {{ key_directory }}
- name: dnssec-keygen -f KSK -a {{ key_algorithm }} -b {{ key_size }} -n ZONE {{ zone }}
- runas: {{ map.user }}
- unless: "grep {{ key_flags.ksk }} {{ key_directory }}/K{{ zone }}.+{{ key_algorithm_field }}+*.key"
- require:
- file: bind_key_directory
{% endif %}
{% endfor %}
2015-03-22 22:07:22 +01:00
{% endfor %}