Skip to content

Instantly share code, notes, and snippets.

@jbz
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbz/8828730 to your computer and use it in GitHub Desktop.
Save jbz/8828730 to your computer and use it in GitHub Desktop.
license_file_contents = NIL
if Chef::DataBag.list.key?('pmta_licenses')
Chef::Log.warn("Found pmta_licenses data bag...")
begin
license_file_contents = data_bag_item("pmta_licenses", node['hostname'])['license']
Chef::Log.warn("found hostname license in data bag...")
file "/etc/pmta/license" do
owner 'pmta'
group 'pmta'
mode 0640
action :create
content license_file_contents
end
rescue Net::HTTPServerException
Chef::Log.warn("HTTP Server exception, assuming hostname record not in databag...")
end
begin
if license_file_contents.nil?
license_file_contents = data_bag_item("pmta_licenses", "default_license")['license']
Chef::Log.warn("Found default license in data bag...")
file "/etc/pmta/license" do
owner 'pmta'
group 'pmta'
mode 0640
action :create
content license_file_contents
end
end
rescue Net::HTTPServerException
Chef::Log.warn("HTTP Server exception, assuming default_license record not in databag...")
end
else
Chef::Log.warn("No data bag found; using cookbook_file for license...")
cookbook_file "/etc/pmta/license" do
owner 'pmta'
group 'pmta'
mode 0644
action :create
source 'license'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment