Commit c1fa9100 authored by Christopher Huhn's avatar Christopher Huhn
Browse files

Eliminated handling of /etc/hosts

parent 828c58cd
default_unless['sys']['hosts']['file'] = Hash.new
default_unless['sys']['hosts']['allow'] = Array.new
default_unless['sys']['hosts']['deny'] = Array.new
default_unless['sys']['hosts']['allow'] = []
default_unless['sys']['hosts']['deny'] = []
......@@ -2,7 +2,13 @@
# Cookbook Name:: sys
# Recipe:: hosts
#
# Copyright 2013, Victor Penso
# Copyright 2013-2019 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH
#
# Authors:
# Christopher Huhn <c.huhn@gsi.de>
# Gabriele Iannetti <g.iannetti@gsi.de>
# Matthias Pausch <m.pausch@gsi.de>
# Victor Penso <v.penso@gsi.de>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
......@@ -19,11 +25,10 @@
unless node['sys']['hosts'].empty?
template '/etc/hosts' do
source 'etc_hosts.erb'
mode '0664' # really group-writeable?
variables( :addresses => node['sys']['hosts']['file'] )
not_if { node['sys']['hosts']['file'].empty? }
log 'sys-hosts-file-deprecated' do
message 'Management of /etc/hosts via sys::hosts has been deprecated'
level :warn
only_if { node['sys']['hosts']['file'] }
end
template '/etc/hosts.allow' do
......
<%= template_header %>
127.0.0.1 localhost
<% @addresses.each do |ip,name| %>
<%= ip %> <%= name %>
<% end %>
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
# Cookbook Name:: sys
# Unit tests for sys::hosts recipe
#
# Copyright 2016-2019 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH
#
# Authors:
# Christopher Huhn <c.huhn@gsi.de>
# Gabriele Iannetti <g.iannetti@gsi.de>
#
# 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.
describe 'sys::hosts' do
let(:chef_run) { ChefSpec::SoloRunner.new.converge(described_recipe) }
it 'check if all resources are present' do
chef_run.run_context.resource_collection.each do |resource|
expect(resource.name).to match(/(^\/etc\/hosts$|^\/etc\/hosts\.(allow|deny)$)/)
end
end
context 'sys.hosts not empty' do
context 'sys.hosts.file not empty' do
......@@ -16,8 +31,9 @@ describe 'sys::hosts' do
chef_run.converge(described_recipe)
end
it 'configures /etc/hosts' do
expect(chef_run).to create_template('/etc/hosts')
it 'warns about deprcation' do
expect(chef_run).to write_log('sys-hosts-file-deprecated')
.with_level(:warn)
end
end
......@@ -34,12 +50,14 @@ describe 'sys::hosts' do
context 'sys.hosts.deny not empty' do
before do
chef_run.node.default['sys']['hosts']['deny'] = {'ALL' => 'ALL'}
chef_run.node.default['sys']['hosts']['deny'] = [ 'ALL: PARANOID' ]
chef_run.converge(described_recipe)
end
it 'configures /etc/hosts.deny' do
expect(chef_run).to create_template('/etc/hosts.deny')
expect(chef_run).to render_file('/etc/hosts.deny')
.with_content('ALL: PARANOID')
end
end
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment