+++ /dev/null
-#
-# Cookbook Name:: fail2ban
-# Provider:: fail2ban_filter
-#
-# Copyright 2015, OpenStreetMap Foundation
-#
-# 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.
-#
-
-def whyrun_supported?
- true
-end
-
-use_inline_resources
-
-action :create do
- if new_resource.source
- remote_file "/etc/fail2ban/filter.d/#{new_resource.name}.conf" do
- source new_resource.source
- owner "root"
- group "root"
- mode 0o644
- end
- else
- template "/etc/fail2ban/filter.d/#{new_resource.name}.conf" do
- cookbook "fail2ban"
- source "filter.erb"
- owner "root"
- group "root"
- mode 0o644
- variables :failregex => new_resource.failregex,
- :ignoreregex => new_resource.ignoreregex
- end
- end
-end
-
-action :delete do
- file "/etc/fail2ban/filter.d/#{new_resource.name}.conf" do
- action :delete
- end
-end
+++ /dev/null
-#
-# Cookbook Name:: fail2ban
-# Provider:: fail2ban_jail
-#
-# Copyright 2015, OpenStreetMap Foundation
-#
-# 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.
-#
-
-def whyrun_supported?
- true
-end
-
-use_inline_resources
-
-action :create do
- template "/etc/fail2ban/jail.d/50-#{new_resource.name}.conf" do
- cookbook "fail2ban"
- source "jail.erb"
- owner "root"
- group "root"
- mode 0o644
- variables :name => new_resource.name,
- :filter => new_resource.filter,
- :logpath => new_resource.logpath,
- :protocol => new_resource.protocol,
- :ports => new_resource.ports,
- :maxretry => new_resource.maxretry,
- :ignoreips => new_resource.ignoreips
- end
-end
-
-action :delete do
- file "/etc/fail2ban/jail.d/50-#{new_resource.name}.conf" do
- action :delete
- end
-end
# limitations under the License.
#
-actions :create, :delete
default_action :create
-attribute :name, :kind_of => String, :name_attribute => true
-attribute :source, :kind_of => String
-attribute :failregex, :kind_of => [String, Array]
-attribute :ignoreregex, :kind_of => [String, Array]
+property :filter, :kind_of => String, :name_attribute => true
+property :source, :kind_of => String
+property :failregex, :kind_of => [String, Array]
+property :ignoreregex, :kind_of => [String, Array]
+
+action :create do
+ if new_resource.source
+ remote_file "/etc/fail2ban/filter.d/#{new_resource.filter}.conf" do
+ source new_resource.source
+ owner "root"
+ group "root"
+ mode 0o644
+ end
+ else
+ template "/etc/fail2ban/filter.d/#{new_resource.filter}.conf" do
+ cookbook "fail2ban"
+ source "filter.erb"
+ owner "root"
+ group "root"
+ mode 0o644
+ variables :failregex => new_resource.failregex,
+ :ignoreregex => new_resource.ignoreregex
+ end
+ end
+end
+
+action :delete do
+ file "/etc/fail2ban/filter.d/#{new_resource.filter}.conf" do
+ action :delete
+ end
+end
def after_created
notifies :reload, "service[fail2ban]"
# limitations under the License.
#
-actions :create, :delete
default_action :create
-attribute :name, :kind_of => String, :name_attribute => true
-attribute :filter, :kind_of => String
-attribute :logpath, :kind_of => String
-attribute :protocol, :kind_of => String
-attribute :ports, :kind_of => Array, :default => []
-attribute :maxretry, :kind_of => Integer
-attribute :ignoreips, :kind_of => Array
+property :jail, :kind_of => String, :name_attribute => true
+property :filter, :kind_of => String
+property :logpath, :kind_of => String
+property :protocol, :kind_of => String
+property :ports, :kind_of => Array, :default => []
+property :maxretry, :kind_of => Integer
+property :ignoreips, :kind_of => Array
+
+action :create do
+ template "/etc/fail2ban/jail.d/50-#{new_resource.jail}.conf" do
+ cookbook "fail2ban"
+ source "jail.erb"
+ owner "root"
+ group "root"
+ mode 0o644
+ variables :name => new_resource.jail,
+ :filter => new_resource.filter,
+ :logpath => new_resource.logpath,
+ :protocol => new_resource.protocol,
+ :ports => new_resource.ports,
+ :maxretry => new_resource.maxretry,
+ :ignoreips => new_resource.ignoreips
+ end
+end
+
+action :delete do
+ file "/etc/fail2ban/jail.d/50-#{new_resource.jail}.conf" do
+ action :delete
+ end
+end
def after_created
notifies :reload, "service[fail2ban]"
include_recipe "munin"
ohai_plugin "hardware" do
- template "ohai.rb.erb"
+ template_source "ohai.rb.erb"
end
case node[:cpu][:"0"][:vendor_id]
end
nginx_site "default" do
- template "nginx_default.conf.erb"
+ template_source "nginx_default.conf.erb"
directory "/srv/imagery/default"
restart_nginx false
end
end
nginx_site new_resource.site do
- template "nginx_imagery.conf.erb"
+ template_source "nginx_imagery.conf.erb"
directory "/srv/imagery/#{new_resource.site}"
restart_nginx false
variables new_resource.to_hash.merge(:resolvers => resolvers)
end
munin_plugin_conf "memcached_multi" do
- template "munin.erb"
+ template_source "munin.erb"
end
%w[bytes commands conns evictions items memory].each do |stat|
+++ /dev/null
-#
-# Cookbook Name:: munin
-# Provider:: munin_plugin
-#
-# Copyright 2013, OpenStreetMap Foundation
-#
-# 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.
-#
-
-def whyrun_supported?
- true
-end
-
-use_inline_resources
-
-action :create do
- link_action = case target_path
- when nil then :delete
- else :create
- end
-
- link plugin_path do
- action link_action
- to target_path
- end
-
- if new_resource.conf # ~FC023
- munin_plugin_conf new_resource.name do
- cookbook new_resource.conf_cookbook
- template new_resource.conf
- variables new_resource.conf_variables
- restart_munin false
- end
- end
-end
-
-action :delete do
- link plugin_path do
- action :delete
- end
-
- if new_resource.conf # ~FC023
- munin_plugin_conf new_resource.name do
- action :delete
- restart_munin false
- end
- end
-end
-
-def plugin_path
- "/etc/munin/plugins/#{new_resource.name}"
-end
-
-def target_path
- if ::File.exist?(target)
- target
- elsif ::File.exist?("/usr/local/share/munin/plugins/#{target}")
- "/usr/local/share/munin/plugins/#{target}"
- elsif ::File.exist?("/usr/share/munin/plugins/#{target}")
- "/usr/share/munin/plugins/#{target}"
- end
-end
-
-def target
- new_resource.target || new_resource.name
-end
+++ /dev/null
-#
-# Cookbook Name:: munin
-# Provider:: munin_plugin_conf
-#
-# Copyright 2013, OpenStreetMap Foundation
-#
-# 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.
-#
-
-def whyrun_supported?
- true
-end
-
-use_inline_resources
-
-action :create do
- template config_file do
- cookbook new_resource.cookbook
- source new_resource.template
- owner "root"
- group "root"
- mode 0o644
- variables new_resource.variables.merge(:name => new_resource.name)
- end
-end
-
-action :delete do
- file config_file do
- action :delete
- end
-end
-
-def config_file
- "/etc/munin/plugin-conf.d/#{new_resource.name}"
-end
end
munin_plugin_conf "df" do
- template "df.erb"
+ template_source "df.erb"
end
munin_plugin "df"
node[:hardware][:network] &&
node[:hardware][:network][ifname][:device] =~ /^virtio/
munin_plugin_conf "if_#{ifname}" do
- template "if.erb"
+ template_source "if.erb"
variables :ifname => ifname
end
else
end
else
munin_plugin_conf "ipmi" do
- template "ipmi.erb"
+ template_source "ipmi.erb"
end
munin_plugin "ipmi_fans" do
#
# Cookbook Name:: munin
-# Resource:: munin_plugin
+# Provider:: munin_plugin
#
# Copyright 2013, OpenStreetMap Foundation
#
# 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
+# 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,
# limitations under the License.
#
-actions :create, :delete
default_action :create
-attribute :name, :kind_of => String, :name_attribute => true
-attribute :target, :kind_of => String
-attribute :conf, :kind_of => String
-attribute :conf_cookbook, :kind_of => String
-attribute :conf_variables, :kind_of => Hash, :default => {}
-attribute :restart_munin, :kind_of => [TrueClass, FalseClass], :default => true
+property :plugin, :kind_of => String, :name_attribute => true
+property :target, :kind_of => String
+property :conf, :kind_of => String
+property :conf_cookbook, :kind_of => String
+property :conf_variables, :kind_of => Hash, :default => {}
+property :restart_munin, :kind_of => [TrueClass, FalseClass], :default => true
+
+action :create do
+ link_action = case target_path
+ when nil then :delete
+ else :create
+ end
+
+ link plugin_path do
+ action link_action
+ to target_path
+ end
+
+ if new_resource.conf # ~FC023
+ munin_plugin_conf new_resource.plugin do
+ cookbook new_resource.conf_cookbook
+ template_source new_resource.conf
+ variables new_resource.conf_variables
+ restart_munin false
+ end
+ end
+end
+
+action :delete do
+ link plugin_path do
+ action :delete
+ end
+
+ if new_resource.conf # ~FC023
+ munin_plugin_conf new_resource.plugin do
+ action :delete
+ restart_munin false
+ end
+ end
+end
+
+action_class do
+ def plugin_path
+ "/etc/munin/plugins/#{new_resource.plugin}"
+ end
+
+ def target_path
+ if ::File.exist?(target)
+ target
+ elsif ::File.exist?("/usr/local/share/munin/plugins/#{new_resource.target}")
+ "/usr/local/share/munin/plugins/#{new_resource.target}"
+ elsif ::File.exist?("/usr/share/munin/plugins/#{new_resource.target}")
+ "/usr/share/munin/plugins/#{new_resource.target}"
+ end
+ end
+
+ def target
+ new_resource.target || new_resource.plugin
+ end
+end
def after_created
notifies :restart, "service[munin-node]" if restart_munin && node[:recipes].include?("munin")
# limitations under the License.
#
-actions :create, :delete
default_action :create
-attribute :name, :kind_of => String, :name_attribute => true
-attribute :cookbook, :kind_of => [String, nil]
-attribute :template, :kind_of => String, :required => true
-attribute :variables, :kind_of => Hash, :default => {}
-attribute :restart_munin, :kind_of => [TrueClass, FalseClass], :default => true
+property :plugin_conf, :kind_of => String, :name_attribute => true
+property :cookbook, :kind_of => [String, nil]
+property :template_source, :kind_of => String, :required => true
+property :variables, :kind_of => Hash, :default => {}
+property :restart_munin, :kind_of => [TrueClass, FalseClass], :default => true
+
+action :create do
+ template config_file do
+ cookbook new_resource.cookbook
+ source new_resource.template_source
+ owner "root"
+ group "root"
+ mode 0o644
+ variables new_resource.variables.merge(:name => new_resource.plugin_conf)
+ end
+end
+
+action :delete do
+ file config_file do
+ action :delete
+ end
+end
+
+action_class do
+ def config_file
+ "/etc/munin/plugin-conf.d/#{new_resource.plugin_conf}"
+ end
+end
def after_created
notifies :restart, "service[munin-node]" if restart_munin
+++ /dev/null
-#
-# Cookbook Name:: nginx
-# Provider:: nginx_site
-#
-# Copyright 2015, OpenStreetMap Foundation
-#
-# 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.
-#
-
-def whyrun_supported?
- true
-end
-
-use_inline_resources
-
-action :create do
- template conf_path do
- cookbook new_resource.cookbook
- source new_resource.template
- owner "root"
- group "root"
- mode 0o644
- variables new_resource.variables.merge(:name => new_resource.name, :directory => directory)
- end
-end
-
-action :delete do
- file conf_path do
- action :delete
- end
-end
-
-def conf_path
- "/etc/nginx/conf.d/#{new_resource.name}.conf"
-end
-
-def directory
- new_resource.directory || "/var/www/#{new_resource.name}"
-end
# limitations under the License.
#
-actions :create, :delete
default_action :create
-attribute :name, :kind_of => String, :name_attribute => true
-attribute :directory, :kind_of => String
-attribute :cookbook, :kind_of => String
-attribute :template, :kind_of => String, :required => true
-attribute :variables, :kind_of => Hash, :default => {}
-attribute :restart_nginx, :kind_of => [TrueClass, FalseClass], :default => true
+property :site, :kind_of => String, :name_attribute => true
+property :directory, :kind_of => String
+property :cookbook, :kind_of => String
+property :template_source, :kind_of => String, :required => true
+property :variables, :kind_of => Hash, :default => {}
+property :restart_nginx, :kind_of => [TrueClass, FalseClass], :default => true
+
+action :create do
+ template conf_path do
+ cookbook new_resource.cookbook
+ source new_resource.template_source
+ owner "root"
+ group "root"
+ mode 0o644
+ variables new_resource.variables.merge(:name => new_resource.site, :directory => directory)
+ end
+end
+
+action :delete do
+ file conf_path do
+ action :delete
+ end
+end
+
+action_class do
+ def conf_path
+ "/etc/nginx/conf.d/#{new_resource.site}.conf"
+ end
+
+ def directory
+ new_resource.directory || "/var/www/#{new_resource.site}"
+ end
+end
def after_created
notifies :restart, "service[nginx]" if restart_nginx
end
munin_plugin_conf "nominatim" do
- template "munin.erb"
+ template_source "munin.erb"
variables :db => node[:nominatim][:dbname],
:querylog => "#{node[:nominatim][:logdir]}/query.log"
end
+++ /dev/null
-#
-# Cookbook Name:: ohai
-# Provider:: ohai_plugin
-#
-# Copyright 2015, OpenStreetMap Foundation
-#
-# 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.
-#
-
-def whyrun_supported?
- true
-end
-
-use_inline_resources
-
-action :create do
- ohai new_resource.name do
- action :nothing
- end
-
- template plugin_path do
- source new_resource.template
- owner "root"
- group "root"
- mode 0o644
- notifies :reload, "ohai[#{new_resource.name}]"
- end
-end
-
-action :delete do
- template plugin_path do
- action :delete
- end
-end
-
-def plugin_path
- "/etc/chef/ohai/#{new_resource.name}.rb"
-end
# limitations under the License.
#
-actions :create, :delete
default_action :create
-attribute :name, :kind_of => String, :name_attribute => true
-attribute :template, :kind_of => String, :required => true
+property :plugin, :kind_of => String, :name_attribute => true
+property :template_source, :kind_of => String, :required => true
+
+action :create do
+ ohai new_resource.plugin do
+ action :nothing
+ end
+
+ template plugin_path do
+ source new_resource.template_source
+ owner "root"
+ group "root"
+ mode 0o644
+ notifies :reload, "ohai[#{new_resource.plugin}]"
+ end
+end
+
+action :delete do
+ template plugin_path do
+ action :delete
+ end
+end
+
+action_class do
+ def plugin_path
+ "/etc/chef/ohai/#{new_resource.plugin}.rb"
+ end
+end
end
ohai_plugin "postgresql" do
- template "ohai.rb.erb"
+ template_source "ohai.rb.erb"
end
package "ptop"
action :install do
if version.nil?
- execute "pip-install-#{name}" do
+ execute "pip-install-#{new_resource.package_name}" do
command "#{pip_command} install #{new_resource.package_name}"
not_if "#{pip_command} show #{new_resource.package_name}"
end
else
- execute "pip-install-#{name}" do
+ execute "pip-install-#{new_resource.package_name}" do
command "#{pip_command} install #{new_resource.package_name}==#{new_resource.version}"
not_if "#{pip_command} show #{new_resource.package_name} | fgrep -q #{new_resource.version}"
end
end
action :remove do
- execute "pip-uninstall-#{name}" do
+ execute "pip-uninstall-#{new_resource.package_name}" do
command "#{pip_command} uninstall #{new_resource.package_name}"
only_if "#{pip_command} show #{new_resource.package_name}"
end
end
-def pip_command
- "pip#{python_version}"
+action_class do
+ def pip_command
+ "pip#{new_resource.python_version}"
+ end
end
action :create do
path_variables = new_resource.to_hash
- template "/etc/systemd/system/#{path}.path" do
+ template "/etc/systemd/system/#{new_resource.path}.path" do
cookbook "systemd"
source "path.erb"
owner "root"
variables path_variables
end
- execute "systemctl-reload-#{path}.path" do
+ execute "systemctl-reload-#{new_resource.path}.path" do
action :nothing
command "systemctl daemon-reload"
user "root"
group "root"
- subscribes :run, "template[/etc/systemd/system/#{path}.path]"
+ subscribes :run, "template[/etc/systemd/system/#{new_resource.path}.path]"
end
end
action :delete do
- file "/etc/systemd/system/#{path}.path" do
+ file "/etc/systemd/system/#{new_resource.path}.path" do
action :delete
end
- execute "systemctl-reload-#{path}.path" do
+ execute "systemctl-reload-#{new_resource.path}.path" do
action :nothing
command "systemctl daemon-reload"
user "root"
group "root"
- subscribes :run, "file[/etc/systemd/system/#{path}.path]"
+ subscribes :run, "file[/etc/systemd/system/#{new_resource.path}.path]"
end
end
service_variables = new_resource.to_hash
if environment_file.is_a?(Hash)
- template "/etc/default/#{service}" do
+ template "/etc/default/#{new_resource.service}" do
cookbook "systemd"
source "environment.erb"
owner "root"
variables :environment => environment_file
end
- service_variables[:environment_file] = "/etc/default/#{service}"
+ service_variables[:environment_file] = "/etc/default/#{new_resource.service}"
end
- template "/etc/systemd/system/#{service}.service" do
+ template "/etc/systemd/system/#{new_resource.service}.service" do
cookbook "systemd"
source "service.erb"
owner "root"
variables service_variables
end
- execute "systemctl-reload-#{service}.service" do
+ execute "systemctl-reload-#{new_resource.service}.service" do
action :nothing
command "systemctl daemon-reload"
user "root"
group "root"
- subscribes :run, "template[/etc/systemd/system/#{service}.service]"
+ subscribes :run, "template[/etc/systemd/system/#{new_resource.service}.service]"
end
end
action :delete do
- file "/etc/default/#{service}" do
+ file "/etc/default/#{new_resource.service}" do
action :delete
only_if { environment_file.is_a?(Hash) }
end
- file "/etc/systemd/system/#{service}.service" do
+ file "/etc/systemd/system/#{new_resource.service}.service" do
action :delete
end
- execute "systemctl-reload-#{service}.service" do
+ execute "systemctl-reload-#{new_resource.service}.service" do
action :nothing
command "systemctl daemon-reload"
user "root"
group "root"
- subscribes :run, "file[/etc/systemd/system/#{service}.service]"
+ subscribes :run, "file[/etc/systemd/system/#{new_resource.service}.service]"
end
end
end
end
-def unit_name
- path.sub(%r{^/}, "").gsub(%r{/}, "-")
+action_class do
+ def unit_name
+ path.sub(%r{^/}, "").gsub(%r{/}, "-")
+ end
end
end
nginx_site "tile-ssl" do
- template "nginx_tile_ssl.conf.erb"
+ template_source "nginx_tile_ssl.conf.erb"
variables :resolvers => resolvers, :caches => tilecaches
end