X-Git-Url: https://git.openstreetmap.org./chef.git/blobdiff_plain/261e7e9cd1a9882faa4ed7087b5902ebafe25988..e88020178b6617b163bafb500a6cf2d1ab79428d:/cookbooks/openvpn/recipes/default.rb?ds=sidebyside diff --git a/cookbooks/openvpn/recipes/default.rb b/cookbooks/openvpn/recipes/default.rb index fbf6af9b6..060e8e5ee 100644 --- a/cookbooks/openvpn/recipes/default.rb +++ b/cookbooks/openvpn/recipes/default.rb @@ -8,7 +8,7 @@ # 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 +# https://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, @@ -20,14 +20,16 @@ package "openvpn" service "openvpn" do - action [ :enable, :start ] + action [:enable, :start] supports :status => true, :restart => true, :reload => true ignore_failure true end -node[:openvpn][:tunnels].each do |name,details| - if peer = search(:node, "fqdn:#{details[:peer][:host]}").first - if peer[:openvpn] and not details[:peer][:address] +node[:openvpn][:tunnels].each do |name, details| + peer = search(:node, "fqdn:#{details[:peer][:host]}").first + + if peer + if peer[:openvpn] && !details[:peer][:address] node.default[:openvpn][:tunnels][name][:peer][:address] = peer[:openvpn][:address] end @@ -46,14 +48,14 @@ node[:openvpn][:tunnels].each do |name,details| creates "/etc/openvpn/#{name}.key" end - if File.exists?("/etc/openvpn/#{name}.key") - node.set[:openvpn][:keys][name] = IO.read("/etc/openvpn/#{name}.key") + if File.exist?("/etc/openvpn/#{name}.key") + node.normal[:openvpn][:keys][name] = IO.read("/etc/openvpn/#{name}.key") end - elsif peer and peer[:openvpn] + elsif peer && peer[:openvpn] file "/etc/openvpn/#{name}.key" do owner "root" group "root" - mode 0600 + mode 0o600 content peer[:openvpn][:keys][name] end end @@ -63,12 +65,12 @@ node[:openvpn][:tunnels].each do |name,details| source "tunnel.conf.erb" owner "root" group "root" - mode 0644 + mode 0o644 variables :name => name, - :address => node[:openvpn][:address], - :port => node[:openvpn][:tunnels][name][:port], - :mode => node[:openvpn][:tunnels][name][:mode], - :peer => node[:openvpn][:tunnels][name][:peer] + :address => node[:openvpn][:address], + :port => node[:openvpn][:tunnels][name][:port], + :mode => node[:openvpn][:tunnels][name][:mode], + :peer => node[:openvpn][:tunnels][name][:peer] notifies :restart, "service[openvpn]" end else