<commit_before>#
# Cookbook Name:: sys
# Recipe:: resolv
#
# Copyright 2012, <NAME>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

unless node['sys']['resolv']['servers'].empty? # ~FC023 Do not break conventions in sys

  template '/etc/resolv.conf' do
    source 'etc_resolv.conf.erb'
    mode "0644"
    variables(
      :servers => node['sys']['resolv']['servers'],
      :domain => node['sys']['resolv']['domain'],
      :search => node['sys']['resolv']['search']
    )
    not_if 'test -L /etc/resolv.conf' # -> managed by resolvconf
  end

end<commit_msg>Add warnings for flawed configs<commit_after>#
# Cookbook Name:: sys
# Recipe:: resolv
#
# Copyright 2012, <NAME>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

return if node['sys']['resolv']['servers'].empty?

# From resolv.conf's man page:
# > The domain and search keywords are mutually exclusive.
# > If more than one instance of these keywords is present,
# > the last instance wins.
log 'domain+search' do
  message "'search' and 'domain' are mutually exclusive, the latter will be ignored"
  level   :info
  only_if { node['sys']['resolv'].key?('domain') && node['sys']['resolv'].key('search') }
end

log 'resolv.conf-symlink' do
  message "/etc/resolv.conf is a symlink - not touching it"
  level   :warn
  only_if 'test -L /etc/resolv.conf'
end

template '/etc/resolv.conf' do
  source 'etc_resolv.conf.erb'
  mode "0644"
  variables(
    servers: node['sys']['resolv']['servers'],
    domain:  node['sys']['resolv']['domain'],
    search:  node['sys']['resolv']['search'],
    options: node['sys']['resolv']['options']
  )
  not_if 'test -L /etc/resolv.conf' # -> managed by resolvconf
end
{'fraction_non_alphanumeric': 0.13208255159474672, 'fraction_numerical': 0.010131332082551596, 'mean_word_length': 4.146718146718147, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '760952', 'n_tokens_mistral': 802, 'n_tokens_neox': 805, 'n_words': 301}