Merge pull request #1 from saltstack-formulas/master

Updates
This commit is contained in:
Alex Eiswirth 2015-07-29 23:22:50 +02:00
commit d074c098e0
12 changed files with 217 additions and 101 deletions

View file

@ -1,4 +1,4 @@
Copyright (c) 2013 Salt Stack Formulas Copyright (c) 2013-2015 Salt Stack Formulas
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -11,4 +11,3 @@
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.

View file

@ -31,9 +31,23 @@ Example Pillar
.. code:: yaml .. code:: yaml
bind: bind:
config: configured_zones:
name: /etc/named.conf sub.domain.com:
source: salt://bind/files/named.conf type: master
user: root notify: False
group: named configured_views:
mode: 640 myview1:
match_clients:
- client1
- client2
configured_zones:
my.zone:
type: master
notify: False
See *bind/pillar.example*.
Notes
=====
* When using views all zones must be configured in views!

View file

@ -3,6 +3,29 @@
include: include:
- bind - bind
{{ map.log_dir }}:
file.directory:
- user: root
- group: {{ salt['pillar.get']('bind:config:group', map.group) }}
- mode: 775
- require:
- pkg: bind
bind_restart:
service.running:
- name: {{ map.service }}
- reload: False
- watch:
- file: {{ map.log_dir }}/query.log
{{ map.log_dir }}/query.log:
file.managed:
- user: bind
- group: {{ salt['pillar.get']('bind:config:group', map.group) }}
- mode: 644
- require:
- file: {{ map.log_dir }}
named_directory: named_directory:
file.directory: file.directory:
- name: {{ map.named_directory }} - name: {{ map.named_directory }}
@ -13,70 +36,42 @@ named_directory:
- require: - require:
- pkg: bind - pkg: bind
{% if grains['os_family'] == 'RedHat' %}
bind_config: bind_config:
file: file.managed:
- managed
- name: {{ map.config }} - name: {{ map.config }}
- source: 'salt://bind/files/redhat/named.conf' - source: 'salt://{{ map.config_source_dir }}/named.conf'
- template: jinja - template: jinja
- user: {{ salt['pillar.get']('bind:config:user', map.user) }} - user: {{ salt['pillar.get']('bind:config:user', map.user) }}
- group: {{ salt['pillar.get']('bind:config:group', map.group) }} - group: {{ salt['pillar.get']('bind:config:group', map.group) }}
- mode: {{ salt['pillar.get']('bind:config:mode', '640') }} - mode: {{ salt['pillar.get']('bind:config:mode', map.mode) }}
- context:
map: {{ map }}
- require: - require:
- pkg: bind - pkg: bind
- watch_in: - watch_in:
- service: bind - service: bind
bind_local_config: bind_local_config:
file: file.managed:
- managed
- name: {{ map.local_config }} - name: {{ map.local_config }}
- source: 'salt://bind/files/redhat/named.conf.local' - source: 'salt://{{ map.config_source_dir }}/named.conf.local'
- template: jinja - template: jinja
- user: {{ salt['pillar.get']('bind:config:user', map.user) }} - user: {{ salt['pillar.get']('bind:config:user', map.user) }}
- group: {{ salt['pillar.get']('bind:config:group', map.group) }} - group: {{ salt['pillar.get']('bind:config:group', map.group) }}
- mode: {{ salt['pillar.get']('bind:config:mode', '644') }} - mode: {{ salt['pillar.get']('bind:config:mode', '644') }}
- context:
map: {{ map }}
- require: - require:
- pkg: bind - pkg: bind
- file: {{ map.log_dir }}/query.log
- watch_in: - watch_in:
- service: named - service: bind
{% endif %}
{% if grains['os_family'] == 'Debian' %} {% if grains['os_family'] == 'Debian' %}
bind_config:
file:
- managed
- name: {{ map.config }}
- source: 'salt://bind/files/debian/named.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', '644') }}
- require:
- pkg: bind
- watch_in:
- service: bind
bind_key_config: bind_key_config:
file: file.managed:
- managed
- name: {{ map.key_config }} - name: {{ map.key_config }}
- source: 'salt://bind/files/debian/named.conf.key' - source: 'salt://{{ map.config_source_dir }}/named.conf.key'
- 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
bind_local_config:
file:
- managed
- name: {{ map.local_config }}
- source: 'salt://bind/files/debian/named.conf.local'
- template: jinja - template: jinja
- user: {{ salt['pillar.get']('bind:config:user', map.user) }} - user: {{ salt['pillar.get']('bind:config:user', map.user) }}
- group: {{ salt['pillar.get']('bind:config:group', map.group) }} - group: {{ salt['pillar.get']('bind:config:group', map.group) }}
@ -87,10 +82,9 @@ bind_local_config:
- service: bind - service: bind
bind_options_config: bind_options_config:
file: file.managed:
- managed
- name: {{ map.options_config }} - name: {{ map.options_config }}
- source: 'salt://bind/files/debian/named.conf.options' - source: 'salt://{{ map.config_source_dir }}/named.conf.options'
- template: jinja - template: jinja
- user: {{ salt['pillar.get']('bind:config:user', map.user) }} - user: {{ salt['pillar.get']('bind:config:user', map.user) }}
- group: {{ salt['pillar.get']('bind:config:group', map.group) }} - group: {{ salt['pillar.get']('bind:config:group', map.group) }}
@ -101,10 +95,9 @@ bind_options_config:
- service: bind - service: bind
bind_default_zones: bind_default_zones:
file: file.managed:
- managed
- name: {{ map.default_zones_config }} - name: {{ map.default_zones_config }}
- source: 'salt://bind/files/debian/named.conf.default-zones' - source: 'salt://{{ map.config_source_dir }}/named.conf.default-zones'
- template: jinja - template: jinja
- user: {{ salt['pillar.get']('bind:config:user', map.user) }} - user: {{ salt['pillar.get']('bind:config:user', map.user) }}
- group: {{ salt['pillar.get']('bind:config:group', map.group) }} - group: {{ salt['pillar.get']('bind:config:group', map.group) }}
@ -114,30 +107,21 @@ bind_default_zones:
- watch_in: - watch_in:
- service: bind - service: bind
/var/log/bind9: /etc/logrotate.d/{{ map.service }}:
file: file.managed:
- directory - source: salt://{{ map.config_source_dir }}/logrotate_bind
- user: root
- group: bind
- mode: 775
- template: jinja - template: jinja
/etc/logrotate.d/bind9:
file:
- managed
- source: salt://bind/files/debian/logrotate_bind
- user: root - user: root
- group: root - group: root
- context:
map: {{ map }}
{% endif %} {% endif %}
{% for key,args in salt['pillar.get']('bind:configured_zones', {}).iteritems() -%} {% for key, args in salt['pillar.get']('bind:configured_zones', {}).iteritems() -%}
{%- set file = salt['pillar.get']("available_zones:" + key + ":file") %} {%- set file = salt['pillar.get']("bind:available_zones:" + key + ":file") %}
{% if args['type'] == "master" -%} {% if args['type'] == "master" -%}
zones-{{ file }}: zones-{{ file }}:
file: file.managed:
- managed
- name: {{ map.named_directory }}/{{ file }} - name: {{ map.named_directory }}/{{ file }}
- source: 'salt://bind/zones/{{ file }}' - source: 'salt://bind/zones/{{ file }}'
- user: {{ salt['pillar.get']('bind:config:user', map.user) }} - user: {{ salt['pillar.get']('bind:config:user', map.user) }}
@ -146,10 +130,10 @@ zones-{{ file }}:
- watch_in: - watch_in:
- service: bind - service: bind
- require: - require:
- file: {{ map.named_directory }} - file: named_directory
{% if args['dnssec'] is defined and args['dnssec'] -%} {% if args['dnssec'] is defined and args['dnssec'] -%}
signed-{{file}}: signed-{{ file }}:
cmd.run: cmd.run:
- cwd: {{ map.named_directory }} - cwd: {{ map.named_directory }}
- name: zonesigner -zone {{ key }} {{ file }} - name: zonesigner -zone {{ key }} {{ file }}
@ -159,3 +143,32 @@ signed-{{file}}:
{% endif %} {% endif %}
{% endfor %} {% endfor %}
{%- for view, view_data in salt['pillar.get']('bind:configured_views', {}).iteritems() %}
{% for key,args in view_data.get('configured_zones', {}).iteritems() -%}
{%- set file = salt['pillar.get']("bind:available_zones:" + key + ":file") %}
{% if args['type'] == "master" -%}
zones-{{ file }}:
file.managed:
- name: {{ map.named_directory }}/{{ file }}
- source: 'salt://bind/zones/{{ file }}'
- 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:
- file: named_directory
{% if args['dnssec'] is defined and args['dnssec'] -%}
signed-{{ file }}:
cmd.run:
- cwd: {{ map.named_directory }}
- name: zonesigner -zone {{ key }} {{ file }}
- prereq:
- file: zones-{{ file }}
{% endif %}
{% endif %}
{% endfor %}
{% endfor %}

View file

@ -1,4 +1,4 @@
/var/log/bind9/query.log { {{ map.log_dir }}/query.log {
rotate 7 rotate 7
daily daily
missingok missingok
@ -7,5 +7,7 @@
copytruncate copytruncate
compress compress
create 0664 bind root create 0664 bind root
{% if not salt['pkg.version']('logrotate').startswith('3.7')-%}
su su
{% endif %}
} }

View file

@ -6,7 +6,8 @@
// //
// If you are just adding zones, please do that in /etc/bind/named.conf.local // If you are just adding zones, please do that in /etc/bind/named.conf.local
include "/etc/bind/named.conf.key"; include "{{ map.options_config }}";
include "/etc/bind/named.conf.options"; include "{{ map.local_config }}";
include "/etc/bind/named.conf.local"; {%- if salt['pillar.get']('bind:keys', {}) is defined %}
include "/etc/bind/named.conf.default-zones"; include "{{ map.key_config }}";
{% endif %}

View file

@ -7,15 +7,29 @@
// organization // organization
//include "/etc/bind/zones.rfc1918"; //include "/etc/bind/zones.rfc1918";
{% for key,args in salt['pillar.get']('bind:configured_zones', {}).iteritems() -%} {%- macro zone(key, args, file, masters) %}
{%- set file = salt['pillar.get']("available_zones:" + key + ":file") %}
{%- set masters = salt['pillar.get']("available_zones:" + key + ":masters") %}
zone "{{ key }}" { zone "{{ key }}" {
type {{ args['type'] }}; type {{ args['type'] }};
{% if args['dnssec'] is defined and args['dnssec'] -%}
file "zones/{{ file }}.signed";
{% else -%}
file "zones/{{ file }}"; file "zones/{{ file }}";
{% if args['allow-update'] is defined -%} {%- endif %}
{% if args['allow-update'] is defined -%}
allow-update { {{args['allow-update']}}; }; allow-update { {{args['allow-update']}}; };
{%- endif %} {%- endif %}
{%- if args.update_policy is defined %}
update-policy {
{%- for policy in args.update_policy %}
{{ policy }};
{%- endfor %}
};
{%- endif %}
allow-transfer {
{% for remote in args.get('allow-transfer', {}) %}
{{ remote }};
{% endfor %}
};
{% if args['type'] == "master" -%} {% if args['type'] == "master" -%}
{% if args['notify'] -%} {% if args['notify'] -%}
notify yes; notify yes;
@ -27,9 +41,43 @@ zone "{{ key }}" {
masters { {{ masters }} }; masters { {{ masters }} };
{%- endif %} {%- endif %}
}; };
{%- endmacro %}
{%- if salt['pillar.get']('bind:configured_views', {}) is not defined %}
include "{{ map.default_zones_config }}";
{%- endif %}
{% for key, args in salt['pillar.get']('bind:configured_zones', {}).iteritems() -%}
{%- set file = salt['pillar.get']("bind:available_zones:" + key + ":file") %}
{%- set masters = salt['pillar.get']("bind:available_zones:" + key + ":masters") %}
{{ zone(key, args, file, masters) }}
{% endfor %} {% endfor %}
{% for view, view_data in salt['pillar.get']('bind:configured_views', {}).iteritems() %}
view {{ view }} {
{%- if view == 'default' %}
include "{{ map.default_zones_config }}";
{%- endif %}
match-clients {
{%- for acl in view_data.get('match_clients', {}) %}
{{ acl }};
{%- endfor %}
};
{% for key, args in view_data.get('configured_zones', {}).iteritems() -%}
{%- set file = salt['pillar.get']("bind:available_zones:" + key + ":file") %}
{%- set masters = salt['pillar.get']("bind:available_zones:" + key + ":masters") %}
{{ zone(key, args, file, masters) }}
{%- endfor %}
};
{%- endfor %}
logging { logging {
channel "querylog" { file "/var/log/bind9/query.log"; print-time yes; }; channel "querylog" {
file "{{ map.log_dir }}/query.log";
print-time yes;
};
category queries { querylog; }; category queries { querylog; };
}; };

View file

@ -15,7 +15,21 @@ options {
// }; // };
auth-nxdomain no; # conform to RFC1035 auth-nxdomain no; # conform to RFC1035
{% if salt['pillar.get']('bind:config:ipv6', 'False') %}
{%- if salt['pillar.get']('bind:config:ipv6', False) %}
listen-on-v6 { {{ salt['pillar.get']('bind:config:ipv6_listen', 'any') }}; }; listen-on-v6 { {{ salt['pillar.get']('bind:config:ipv6_listen', 'any') }}; };
{% endif %} {%- endif -%}
{#- Allow inclusion of arbitrary statements #}
{%- for statement, value in salt['pillar.get']('bind:config:options', {}).iteritems() -%}
{%- if value is iterable and value is not string %}
{{ statement }} {
{%- for item in value %}
{{ item }};
{%- endfor %}
};
{%- else %}
{{ statement }} {{ value }};
{%- endif %}
{%- endfor %}
}; };

View file

@ -41,5 +41,5 @@ zone "." IN {
}; };
include "/etc/named.rfc1912.zones"; include "/etc/named.rfc1912.zones";
include "/etc/named.conf.local"; include "{{ map.local_config }}";
include "/etc/named.root.key"; include "/etc/named.root.key";

View file

@ -7,8 +7,8 @@
//include "/etc/bind/zones.rfc1918"; //include "/etc/bind/zones.rfc1918";
{% for key,args in salt['pillar.get']('bind:configured_zones', {}).iteritems() -%} {% for key,args in salt['pillar.get']('bind:configured_zones', {}).iteritems() -%}
{%- set file = salt['pillar.get']("available_zones:" + key + ":file") %} {%- set file = salt['pillar.get']("bind:available_zones:" + key + ":file") %}
{%- set masters = salt['pillar.get']("available_zones:" + key + ":masters") %} {%- set masters = salt['pillar.get']("bind:available_zones:" + key + ":masters") %}
zone "{{ key }}" { zone "{{ key }}" {
type {{ args['type'] }}; type {{ args['type'] }};
file "data/{{ file }}"; file "data/{{ file }}";

View file

@ -1,11 +1,9 @@
{% from "bind/map.jinja" import map with context %} {% from "bind/map.jinja" import map with context %}
bind: bind:
pkg: pkg.installed:
- installed
- pkgs: {{ map.pkgs|json }} - pkgs: {{ map.pkgs|json }}
service: service.running:
- running
- name: {{ map.service }} - name: {{ map.service }}
- enable: True - enable: True
- reload: True - reload: True

View file

@ -1,23 +1,33 @@
{% set map = salt['grains.filter_by']({ {% set map = salt['grains.filter_by']({
'Debian': { 'Debian': {
'pkgs': ['bind9', 'bind9utils'], 'pkgs': ['bind9', 'bind9utils', 'dnssec-tools'],
'service': 'bind9', 'service': 'bind9',
'config_source_dir': 'bind/files/debian',
'config': '/etc/bind/named.conf', 'config': '/etc/bind/named.conf',
'local_config': '/etc/bind/named.conf.local', 'local_config': '/etc/bind/named.conf.local',
'key_config': '/etc/bind/named.conf.key', 'key_config': '/etc/bind/named.conf.key',
'options_config': '/etc/bind/named.conf.options', 'options_config': '/etc/bind/named.conf.options',
'default_zones_config': '/etc/bind/named.conf.default-zones', 'default_zones_config': '/etc/bind/named.conf.default-zones',
'named_directory': '/var/cache/bind/zones', 'named_directory': '/var/cache/bind/zones',
'log_dir': '/var/log/bind9',
'user': 'root', 'user': 'root',
'group': 'bind' 'group': 'bind',
'mode': '644'
}, },
'RedHat': { 'RedHat': {
'pkgs': ['bind'], 'pkgs': ['bind'],
'service': 'named', 'service': 'named',
'config_source_dir': 'bind/files/redhat',
'config': '/etc/named.conf', 'config': '/etc/named.conf',
'local_config': '/etc/named.conf.local', 'local_config': '/etc/named.conf.local',
'named_directory': '/var/named/data', 'named_directory': '/var/named/data',
'log_dir': '/var/log/named',
'user': 'root', 'user': 'root',
'group': 'named' 'group': 'named',
'mode': '640'
}, },
}, merge=salt['pillar.get']('bind:lookup')) %} }, merge=salt['grains.filter_by']({
'Ubuntu': {
'log_dir': '/var/log/named'
},
}, grain='os', merge=salt['pillar.get']('bind:lookup'))) %}

View file

@ -11,6 +11,8 @@ bind:
user: root user: root
group: named group: named
mode: 640 mode: 640
options:
allow-recursion: '{ any; };' # Never include this on a public resolver
bind: bind:
keys: keys:
@ -23,12 +25,27 @@ bind:
1.168.192.in-addr.arpa: 1.168.192.in-addr.arpa:
type: master type: master
notify: False notify: False
allow-transfer:
- 1.1.1.1
- 2.2.2.2
dynamic.domain.com: dynamic.domain.com:
type: master type: master
allow-update: "key core_dhcp" allow-update: "key core_dhcp"
notify: True notify: True
configured_views:
myview1:
match_clients:
- client1
- client2
configured_zones:
my.zone:
type: master
notify: False
update_policy:
- "grant core_dhcp name dns_entry_allowed_to_update. ANY"
available_zones: bind:
sub.domain.org: available_zones:
file: db.sub.domain.org sub.domain.org:
masters: "192.168.0.1;" file: db.sub.domain.org
masters: "192.168.0.1;"