Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ support, please pin your environment to version 0.4.0.
* Create json for organization, user, and (optionally) client(s)
* Run chef-solo

See the `default[:chef_server_populator][:solo_org]` and
`default[:chef_server_populator][:solo_org_user]` attribute hashes in
See the `default['chef_server_populator']['solo_org']` and
`default['chef_server_populator']['solo_org_user']` attribute hashes in
`attributes/default.rb` for the required attribute structure.

**When converging with chef-client:**
Expand All @@ -29,7 +29,7 @@ See the `default[:chef_server_populator][:solo_org]` and

Applicable attributes:

* `node[:chef_server_populator][:databag]` - name of the data bag
* `node['chef_server_populator']['databag']` - name of the data bag

Structure of the data bag item:

Expand Down Expand Up @@ -97,15 +97,15 @@ the full name will be used, as the option is not parsed correctly

**Restoring from a backup:**

* Set path to restore file with node[:chef_server_populator][:restore][:file]
* Set path to restore file with `node['chef_server_populator']['restore']['file']`
* The restore recipe is run if a restore file is set
* The restore file can be remote or local

**When enabling backups:**

* Include chef-server-populator::restore recipe
* Set backup cron interval with node[:chef_server_populator][:schedule]
* Optionally set a remote storage location with node[:chef_server_populator][:backup][:remote][:connection]
* Set backup cron interval with `node['chef_server_populator']['schedule']`
* Optionally set a remote storage location with `node['chef_server_populator']['backup']['remote']['connection']`
* Backups include both a pg_dump of the entire chef database and a tarball of the Chef data directory

## Public Key Format
Expand All @@ -130,14 +130,14 @@ openssl rsa -in <path_to_keyfile>.pem -pubout

## Extras

Need to use the IP address of the node for a bit, or another name instead of
having `node[:fqdn]`?
Need to use the IP address of the node for a bit, or another name instead of
having `node['fqdn']`?

* `node[:chef_server_populator][:servername_override]`
* `node['chef_server_populator']['servername_override']`

Keep chef server configured via chef client:

* `node[:chef_server_populator][:chef_server]`
* `node['chef_server_populator']['chef_server']`

If the hash is non-empty, it will write the chef-server `dna.json` and trigger a
`reconfigure` when ever the attributes are updated.
Expand Down
68 changes: 34 additions & 34 deletions attributes/default.rb
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
default[:chef_server_populator][:configuration_directory] = '/etc/chef-server/populator'
default[:chef_server_populator][:base_path] = '/tmp/chef-server-populator'
default[:chef_server_populator][:clients] = {}
default[:chef_server_populator][:knife_exec] = '/usr/bin/knife'
default[:chef_server_populator][:user] = 'admin'
default[:chef_server_populator][:pem] = '/etc/chef-server/admin.pem'
default[:chef_server_populator][:databag] = nil
default[:chef_server_populator][:user_databag] = nil
default['chef_server_populator']['configuration_directory'] = '/etc/chef-server/populator'
default['chef_server_populator']['base_path'] = '/tmp/chef-server-populator'
default['chef_server_populator']['clients'] = {}
default['chef_server_populator']['knife_exec'] = '/usr/bin/knife'
default['chef_server_populator']['user'] = 'admin'
default['chef_server_populator']['pem'] = '/etc/chef-server/admin.pem'
default['chef_server_populator']['databag'] = nil
default['chef_server_populator']['user_databag'] = nil

default[:chef_server_populator][:endpoint] = nil
default['chef_server_populator']['endpoint'] = nil

default[:chef_server_populator][:backup_gems][:miasma] = '~> 0.2'
default['chef_server_populator']['backup_gems']['miasma'] = '~> 0.2'

# Deprecated in favor of endpoint
default[:chef_server_populator][:servername_override] = nil
default['chef_server_populator']['servername_override'] = nil

# The :chef_server attribute is passed to chef-server cookbook
# Default the ttl since it kills runs with 403s on templates with
# annoying frequency
default[:chef_server_populator][:chef_server][:configuration][:opscode_erchef][:s3_url_ttl] = 3600
default['chef_server_populator']['chef_server']['configuration']['opscode_erchef']['s3_url_ttl'] = 3600

default[:chef_server_populator][:cookbook_auto_install] = true
default['chef_server_populator']['cookbook_auto_install'] = true

default[:chef_server_populator][:restore][:file] = ''
default[:chef_server_populator][:restore][:data] = ''
default[:chef_server_populator][:restore][:local_path] = '/tmp/'
default['chef_server_populator']['restore']['file'] = ''
default['chef_server_populator']['restore']['data'] = ''
default['chef_server_populator']['restore']['local_path'] = '/tmp/'

default[:chef_server_populator][:backup][:dir] = '/tmp/chef-server/backup'
default[:chef_server_populator][:backup][:filename] = 'chef-server-full'
default[:chef_server_populator][:backup][:remote][:connection] = nil
default[:chef_server_populator][:backup][:remote][:directory] = nil
default[:chef_server_populator][:backup][:remote][:file_prefix] = nil
default[:chef_server_populator][:backup][:schedule] = {
default['chef_server_populator']['backup']['dir'] = '/tmp/chef-server/backup'
default['chef_server_populator']['backup']['filename'] = 'chef-server-full'
default['chef_server_populator']['backup']['remote']['connection'] = nil
default['chef_server_populator']['backup']['remote']['directory'] = nil
default['chef_server_populator']['backup']['remote']['file_prefix'] = nil
default['chef_server_populator']['backup']['schedule'] = {
:minute => '33',
:hour => '3'
}
Expand All @@ -39,20 +39,20 @@
#imaginable case you will want to replace some or all of these with
#your own values.

default[:chef_server_populator][:solo_org] = {
:org_name => 'inception_llc',
:full_name => 'Chef Inception Organization',
:validator_pub_key => 'validator_pub.pem'
default['chef_server_populator']['solo_org'] = {
'org_name' => 'inception_llc',
'full_name' => 'Chef Inception Organization',
'validator_pub_key' => 'validator_pub.pem'
}

default[:chef_server_populator][:solo_org_user] = {
:name => 'populator',
:first => 'Populator',
:last => 'User',
:email => '[email protected]',
:pub_key => 'user_pub.pem'
default['chef_server_populator']['solo_org_user'] = {
'name' => 'populator',
'first' => 'Populator',
'last' => 'User',
'email' => '[email protected]',
'pub_key' => 'user_pub.pem',
}

default[:chef_server_populator][:server_org] = 'inception_llc'
default['chef_server_populator']['server_org'] = 'inception_llc'
#If this is set to nil, the configurator recipe will set it to the server_org.
default[:chef_server_populator][:default_org] = nil
default['chef_server_populator']['default_org'] = nil
14 changes: 7 additions & 7 deletions recipes/backups.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
directory node[:chef_server_populator][:backup][:dir] do
directory node['chef_server_populator']['backup']['dir'] do
recursive true
owner 'opscode-pgsql'
mode '0755'
end

#Upload to Remote Storage
# Include fog
case node[:platform_family]
case node['platform_family']
when 'debian'
packages = %w(gcc libxml2 libxml2-dev libxslt-dev)
when 'rhel'
Expand All @@ -16,7 +16,7 @@
package fog_dep
end

node[:chef_server_populator][:backup_gems].each_pair do |gem_name, gem_version|
node['chef_server_populator']['backup_gems'].each_pair do |gem_name, gem_version|
gem_package gem_name do
if !gem_version.nil?
version gem_version
Expand All @@ -25,15 +25,15 @@
end
end

directory node[:chef_server_populator][:configuration_directory] do
directory node['chef_server_populator']['configuration_directory'] do
recursive true
owner 'root'
mode 0700
end

file File.join(node[:chef_server_populator][:configuration_directory], 'backup.json') do
file File.join(node['chef_server_populator']['configuration_directory'], 'backup.json') do
content Chef::JSONCompat.to_json_pretty(
node[:chef_server_populator][:backup].merge(
node['chef_server_populator']['backup'].merge(
:cookbook_version => node.run_context.cookbook_collection['chef-server-populator'].version
)
)
Expand All @@ -49,7 +49,7 @@

cron 'Chef Server Backups' do
command '/usr/local/bin/chef-server-backup'
node[:chef_server_populator][:backup][:schedule].each do |k,v|
node['chef_server_populator']['backup']['schedule'].each do |k,v|
send(k,v)
end
path "/opt/chef/embedded/bin/:/usr/bin:/usr/local/bin:/bin"
Expand Down
32 changes: 16 additions & 16 deletions recipes/client.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
include_recipe 'chef-server-populator::configurator'

knife_cmd = "#{node[:chef_server_populator][:knife_exec]}"
knife_cmd = node['chef_server_populator']['knife_exec']
knife_opts = '-c /etc/opscode/pivotal.rb'

ssl_port = %w(chef-server configuration nginx ssl_port).inject(node) do |memo, key|
Expand All @@ -10,14 +10,14 @@

pg_cmd = "/opt/chef-server/embedded/bin/psql -d opscode_chef"

if(node[:chef_server_populator][:databag])
if(node['chef_server_populator']['databag'])
begin
items = data_bag(node[:chef_server_populator][:databag]).map do |bag_item|
item = data_bag_item(node[:chef_server_populator][:databag], bag_item).fetch('chef_server', {})
items = data_bag(node['chef_server_populator']['databag']).map do |bag_item|
item = data_bag_item(node['chef_server_populator']['databag'], bag_item).fetch('chef_server', {})
if item.empty?
Chef::Log.info("No chef-server data for #{bag_item['id']}")
end
item.merge('client' => data_bag_item(node[:chef_server_populator][:databag], bag_item)['id'],
item.merge('client' => data_bag_item(node['chef_server_populator']['databag'], bag_item)['id'],
'pub_key' => item['client_key'],
'enabled' => item['enabled'],
'admin' => item.fetch('admin', false),
Expand All @@ -36,7 +36,7 @@
item.merge('full_name' => item.fetch('full_name', item['client'].capitalize))
command "chef-server-ctl org-create #{item['client']} #{item['full_name']}"
not_if "chef-server-ctl org-list | grep '^#{item['client']}$'"
if item['client'] == node[:chef_server_populator][:default_org]
if item['client'] == node['chef_server_populator']['default_org']
notifies :reconfigure, 'chef_server_ingredient[chef-server-core]', :immediately
end
end
Expand All @@ -49,7 +49,7 @@
end
end
execute "add org validator key: #{item['client']}" do
if (node['chef-server'][:version].to_f >= 12.1 || node['chef-server'][:version].to_f == 0.0)
if (node['chef-server']['version'].to_f >= 12.1 || node['chef-server']['version'].to_f == 0.0)
command "chef-server-ctl add-client-key #{item['client']} #{item['client']}-validator --public-key-path #{key_file} --key-name populator"
else
command "chef-server-ctl add-client-key #{item['client']} #{item['client']}-validator #{key_file} --key-name populator"
Expand Down Expand Up @@ -102,7 +102,7 @@
not_if "chef-server-ctl user-list | grep '^#{item['client']}$'"
end
execute "set user key: #{item['client']}" do
if (node['chef-server'][:version].to_f >= 12.1 || node['chef-server'][:version].to_f == 0.0)
if (node['chef-server']['version'].to_f >= 12.1 || node['chef-server']['version'].to_f == 0.0)
command "chef-server-ctl add-user-key #{item['client']} --public-key-path #{key_file} --key-name populator"
else
command "chef-server-ctl add-user-key #{item['client']} #{key_file} --key-name populator"
Expand Down Expand Up @@ -130,10 +130,10 @@
end
if(options)
if(options.has_key?('enabled'))
item[:enabled] = options[:enabled]
item['enabled'] = options['enabled']
end
if(options.has_key?('admin'))
item[:admin] = options[:admin]
item['admin'] = options['admin']
end
end
if(item['enabled'] == false)
Expand All @@ -158,16 +158,16 @@
end
if(item['pub_key'])
execute "set client key: #{item['client']}" do
if (node['chef-server'][:version].to_f >= 12.1 || node['chef-server'][:version].to_f == 0.0)
command "chef-server-ctl add-client-key #{org || node[:chef_server_populator][:default_org]} #{item['client']} --public-key-path #{key_file} --key-name populator"
if (node['chef-server']['version'].to_f >= 12.1 || node['chef-server']['version'].to_f == 0.0)
command "chef-server-ctl add-client-key #{org || node['chef_server_populator']['default_org']} #{item['client']} --public-key-path #{key_file} --key-name populator"
else
command "chef-server-ctl add-client-key #{org || node[:chef_server_populator][:default_org]} #{item['client']} #{key_file} --key-name populator"
command "chef-server-ctl add-client-key #{org || node['chef_server_populator']['default_org']} #{item['client']} #{key_file} --key-name populator"
end
not_if "chef-server-ctl list-client-keys #{org || node[:chef_server_populator][:default_org]} #{item['client']} | grep 'name: populator$'"
not_if "chef-server-ctl list-client-keys #{org || node['chef_server_populator']['default_org']} #{item['client']} | grep 'name: populator$'"
end
execute "delete default client key: #{item['client']}" do
command "chef-server-ctl delete-client-key #{org || node[:chef_server_populator][:default_org]} #{item['client']} default"
only_if "chef-server-ctl list-client-keys #{org || node[:chef_server_populator][:default_org]} #{item['client']} | grep 'name: default$'"
command "chef-server-ctl delete-client-key #{org || node['chef_server_populator']['default_org']} #{item['client']} default"
only_if "chef-server-ctl list-client-keys #{org || node['chef_server_populator']['default_org']} #{item['client']} | grep 'name: default$'"
end
end
end
Expand Down
50 changes: 25 additions & 25 deletions recipes/configurator.rb
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
if(node[:chef_server_populator][:default_org])
node.default[:chef_server_populator][:chef_server][:configuration][:default_orgname] = node[:chef_server_populator][:default_org]
if(node['chef_server_populator']['default_org'])
node.default['chef_server_populator']['chef_server']['configuration']['default_orgname'] = node['chef_server_populator']['default_org']
end

unless(node[:chef_server_populator][:endpoint])
node.default[:chef_server_populator][:endpoint] = node[:chef_server_populator][:servername_override]
unless(node['chef_server_populator']['endpoint'])
node.default['chef_server_populator']['endpoint'] = node['chef_server_populator']['servername_override']
end

if(node[:chef_server_populator][:endpoint])
node.set['chef-server'][:api_fqdn] =
node.set[:chef_server_populator][:chef_server][:configuration][:nginx][:server_name] =
node.set[:chef_server_populator][:chef_server][:configuration][:bookshelf][:vip] =
node.set[:chef_server_populator][:chef_server][:configuration][:lb][:api_fqdn] =
node.set[:chef_server_populator][:chef_server][:configuration][:lb][:web_ui_fqdn] = node[:chef_server_populator][:endpoint]
node.set[:chef_server_populator][:chef_server][:configuration][:nginx][:url] =
node.set[:chef_server_populator][:chef_server][:configuration][:bookshelf][:url] = "https://#{node[:chef_server_populator][:endpoint]}"
if(node['chef_server_populator']['endpoint'])
node.set['chef-server']['api_fqdn'] =
node.set['chef_server_populator']['chef_server']['configuration']['nginx']['server_name'] =
node.set['chef_server_populator']['chef_server']['configuration']['bookshelf']['vip'] =
node.set['chef_server_populator']['chef_server']['configuration']['lb']['api_fqdn'] =
node.set['chef_server_populator']['chef_server']['configuration']['lb']['web_ui_fqdn'] = node['chef_server_populator']['endpoint']
node.set['chef_server_populator']['chef_server']['configuration']['nginx']['url'] =
node.set['chef_server_populator']['chef_server']['configuration']['bookshelf']['url'] = "https://#{node['chef_server_populator']['endpoint']}"
else
node.set['chef-server'][:api_fqdn] =
node.set[:chef_server_populator][:chef_server][:configuration][:nginx][:server_name] =
node.set[:chef_server_populator][:chef_server][:configuration][:bookshelf][:vip] =
node.set[:chef_server_populator][:chef_server][:configuration][:lb][:api_fqdn] =
node.set[:chef_server_populator][:chef_server][:configuration][:lb][:web_ui_fqdn] = node[:fqdn]
node.set[:chef_server_populator][:chef_server][:configuration][:nginx][:url] =
node.set[:chef_server_populator][:chef_server][:configuration][:bookshelf][:url] = "https://#{node[:fqdn]}"
node.set['chef-server']['api_fqdn'] =
node.set['chef_server_populator']['chef_server']['configuration']['nginx']['server_name'] =
node.set['chef_server_populator']['chef_server']['configuration']['bookshelf']['vip'] =
node.set['chef_server_populator']['chef_server']['configuration']['lb']['api_fqdn'] =
node.set['chef_server_populator']['chef_server']['configuration']['lb']['web_ui_fqdn'] = node['fqdn']
node.set['chef_server_populator']['chef_server']['configuration']['nginx']['url'] =
node.set['chef_server_populator']['chef_server']['configuration']['bookshelf']['url'] = "https://#{node['fqdn']}"
end

mash_maker = lambda do |x|
Expand All @@ -39,17 +39,17 @@
end

current_server_config = mash_maker.call(node['chef-server'])
populator_server_config = mash_maker.call(node[:chef_server_populator][:chef_server] || {})
populator_server_config = mash_maker.call(node['chef_server_populator']['chef_server'] || {})

if(current_server_config[:configuration].is_a?(Hash))
populator_server_config[:configuration] = Chef::Mixin::DeepMerge.deep_merge(
current_server_config[:configuration],
if(current_server_config['configuration'].is_a?(Hash))
populator_server_config['configuration'] = Chef::Mixin::DeepMerge.deep_merge(
current_server_config['configuration'],
populator_server_config.fetch(:configuration, Mash.new)
)
end

if(populator_server_config[:configuration])
populator_server_config[:configuration] = populator_server_config[:configuration].map do |k,v|
if(populator_server_config['configuration'])
populator_server_config['configuration'] = populator_server_config['configuration'].map do |k,v|
"#{k}(#{v.inspect})"
end.join("\n")
end
Expand Down
4 changes: 2 additions & 2 deletions recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
include_recipe 'chef-server-populator::client'
end

if(!node[:chef_server_populator][:restore][:file].empty? &&
node[:chef_server_populator][:restore][:file] != 'none')
if(!node['chef_server_populator']['restore']['file'].empty? &&
node['chef_server_populator']['restore']['file'] != 'none')
include_recipe 'chef-server-populator::restore'
end
Loading