]> git.openstreetmap.org Git - chef.git/blobdiff - cookbooks/openvpn/recipes/default.rb
Add #osm-gr
[chef.git] / cookbooks / openvpn / recipes / default.rb
index cbd45ee65c319efcb5ca224fe48e2cff67fe1f8a..9b96183eec2a0452acc920c24159f91d20318e72 100644 (file)
 package "openvpn"
 
 service "openvpn" do
 package "openvpn"
 
 service "openvpn" do
-  action [ :enable, :start ]
+  action [:enable, :start]
   supports :status => true, :restart => true, :reload => true
   ignore_failure true
 end
 
   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
 
       node.default[:openvpn][:tunnels][name][:peer][:address] = peer[:openvpn][:address]
     end
 
@@ -46,10 +48,10 @@ node[:openvpn][:tunnels].each do |name,details|
       creates "/etc/openvpn/#{name}.key"
     end
 
       creates "/etc/openvpn/#{name}.key"
     end
 
-    if File.exists?("/etc/openvpn/#{name}.key")
+    if File.exist?("/etc/openvpn/#{name}.key")
       node.set[:openvpn][:keys][name] = IO.read("/etc/openvpn/#{name}.key")
     end
       node.set[: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"
     file "/etc/openvpn/#{name}.key" do
       owner "root"
       group "root"
@@ -65,11 +67,11 @@ node[:openvpn][:tunnels].each do |name,details|
       group "root"
       mode 0644
       variables :name => name,
       group "root"
       mode 0644
       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]
-      notifies :restart, resources(:service => "openvpn")
+                :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
     file "/etc/openvpn/#{name}.conf" do
     end
   else
     file "/etc/openvpn/#{name}.conf" do