diff --git a/README.md b/README.md index fdfb239..95b538d 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,16 @@ Optionally: If you want to adjust the allow-query option globally, here is a sam bind_config_allow_query: [ '127.1.0.1', '127.1.0.2' ] +Optionally: You can enable logging (this creates one file per channel): + + bind_logging_enabled: on + +Optionally: You can configure log files size, versions, logging severity and path: + bind_logging_path: /var/log/named + bind_logging_file_versions: 3 + bind_logging_file_size: 5m + bind_logging_severity: dynamic + ## Dependencies None. @@ -75,3 +85,4 @@ MIT ## Author Information René Moser +Logging configuration borrowed from Steven Carr from a StackOverflow's answer. diff --git a/defaults/main.yml b/defaults/main.yml index 6a6e3df..59ef477 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -13,3 +13,8 @@ bind_masterzones_path: "masters" bind_slavezones_path: "slaves" bind_config_listen_on: any bind_config_allow_query: [] +bind_logging_enabled: off +bind_logging_path: /var/log/named +bind_logging_file_versions: 3 +bind_logging_file_size: 5m +bind_logging_severity: dynamic diff --git a/tasks/main.yml b/tasks/main.yml index 50b442c..b2825a1 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -31,5 +31,9 @@ notify: reload bind tags: bind-zones +- name: Create log directory + file: path={{ bind_logging_path }} state=directory owner={{ bind_user }} group={{ bind_group }} mode=0755 + when: bind_logging_enabled + - name: start/stop bind service service: name={{ bind_service_name }} state={{ bind_service_state }} enabled={{ bind_service_enabled }} diff --git a/templates/named.conf.options.j2 b/templates/named.conf.options.j2 index 7a1deb6..64d58fc 100644 --- a/templates/named.conf.options.j2 +++ b/templates/named.conf.options.j2 @@ -62,3 +62,111 @@ options { recursion {{ bind_config_recursion }}; // Do not provide recursive service zone-statistics yes; }; + +{% if bind_logging_enabled %} +logging { + channel default_file { + file "{{ bind_logging_path }}/default.log" versions {{ bind_logging_file_versions }} size {{ bind_logging_file_size }}; + severity {{ bind_logging_severity }}; + print-time yes; + }; + channel general_file { + file "{{ bind_logging_path }}/general.log" versions {{ bind_logging_file_versions }} size {{ bind_logging_file_size }}; + severity {{ bind_logging_severity }}; + print-time yes; + }; + channel database_file { + file "{{ bind_logging_path }}/database.log" versions {{ bind_logging_file_versions }} size {{ bind_logging_file_size }}; + severity {{ bind_logging_severity }}; + print-time yes; + }; + channel security_file { + file "{{ bind_logging_path }}/security.log" versions {{ bind_logging_file_versions }} size {{ bind_logging_file_size }}; + severity {{ bind_logging_severity }}; + print-time yes; + }; + channel config_file { + file "{{ bind_logging_path }}/config.log" versions {{ bind_logging_file_versions }} size {{ bind_logging_file_size }}; + severity {{ bind_logging_severity }}; + print-time yes; + }; + channel resolver_file { + file "{{ bind_logging_path }}/resolver.log" versions {{ bind_logging_file_versions }} size {{ bind_logging_file_size }}; + severity {{ bind_logging_severity }}; + print-time yes; + }; + channel xfer-in_file { + file "{{ bind_logging_path }}/xfer-in.log" versions {{ bind_logging_file_versions }} size {{ bind_logging_file_size }}; + severity {{ bind_logging_severity }}; + print-time yes; + }; + channel xfer-out_file { + file "{{ bind_logging_path }}/xfer-out.log" versions {{ bind_logging_file_versions }} size {{ bind_logging_file_size }}; + severity {{ bind_logging_severity }}; + print-time yes; + }; + channel notify_file { + file "{{ bind_logging_path }}/notify.log" versions {{ bind_logging_file_versions }} size {{ bind_logging_file_size }}; + severity {{ bind_logging_severity }}; + print-time yes; + }; + channel client_file { + file "{{ bind_logging_path }}/client.log" versions {{ bind_logging_file_versions }} size {{ bind_logging_file_size }}; + severity {{ bind_logging_severity }}; + print-time yes; + }; + channel unmatched_file { + file "{{ bind_logging_path }}/unmatched.log" versions {{ bind_logging_file_versions }} size {{ bind_logging_file_size }}; + severity {{ bind_logging_severity }}; + print-time yes; + }; + channel queries_file { + file "{{ bind_logging_path }}/queries.log" versions {{ bind_logging_file_versions }} size {{ bind_logging_file_size }}; + severity {{ bind_logging_severity }}; + print-time yes; + }; + channel network_file { + file "{{ bind_logging_path }}/network.log" versions {{ bind_logging_file_versions }} size {{ bind_logging_file_size }}; + severity {{ bind_logging_severity }}; + print-time yes; + }; + channel update_file { + file "{{ bind_logging_path }}/update.log" versions {{ bind_logging_file_versions }} size {{ bind_logging_file_size }}; + severity {{ bind_logging_severity }}; + print-time yes; + }; + channel dispatch_file { + file "{{ bind_logging_path }}/dispatch.log" versions {{ bind_logging_file_versions }} size {{ bind_logging_file_size }}; + severity {{ bind_logging_severity }}; + print-time yes; + }; + channel dnssec_file { + file "{{ bind_logging_path }}/dnssec.log" versions {{ bind_logging_file_versions }} size {{ bind_logging_file_size }}; + severity {{ bind_logging_severity }}; + print-time yes; + }; + channel lame-servers_file { + file "{{ bind_logging_path }}/lame-servers.log" versions {{ bind_logging_file_versions }} size {{ bind_logging_file_size }}; + severity {{ bind_logging_severity }}; + print-time yes; + }; + + category default { default_file; }; + category general { general_file; }; + category database { database_file; }; + category security { security_file; }; + category config { config_file; }; + category resolver { resolver_file; }; + category xfer-in { xfer-in_file; }; + category xfer-out { xfer-out_file; }; + category notify { notify_file; }; + category client { client_file; }; + category unmatched { unmatched_file; }; + category queries { queries_file; }; + category network { network_file; }; + category update { update_file; }; + category dispatch { dispatch_file; }; + category dnssec { dnssec_file; }; + category lame-servers { lame-servers_file; }; +}; +{% endif %}