Skip to content

Commit

Permalink
Merge pull request #19 from ncerny/nc/allow-backend-peers
Browse files Browse the repository at this point in the history
Change the bootstrap_node to peers
  • Loading branch information
ncerny committed Apr 14, 2017
2 parents f547529 + 76e4a2d commit cbb34cb
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 14 deletions.
1 change: 1 addition & 0 deletions metadata.rb
Expand Up @@ -6,6 +6,7 @@
long_description 'Resource Cookbook for Managing Chef Software Inc Product Suite'
issues_url 'https://github.com/ncerny/chef_stack/issues' if respond_to?(:issues_url)
source_url 'https://github.com/ncerny/chef_stack' if respond_to?(:source_url)

version '0.8.0'

depends 'chef-ingredient'
44 changes: 30 additions & 14 deletions resources/backend.rb
Expand Up @@ -24,12 +24,14 @@
property :version, [String, Symbol], default: :latest
property :config, String, default: ''
property :accept_license, [TrueClass, FalseClass], default: false
property :bootstrap_node, String, required: true
property :peers, [String, Array], required: true
property :publish_address, String, default: node['ipaddress']
property :chef_backend_secrets, String
property :chef_backend_secrets, String, default: ''
property :platform, String
property :platform_version, String

alias :bootstrap_node :peers

load_current_value do
# node.run_state['chef-users'] ||= Mixlib::ShellOut.new('chef-server-ctl user-list').run_command.stdout
# current_value_does_not_exist! unless node.run_state['chef-users'].index(/^#{username}$/)
Expand All @@ -53,23 +55,37 @@
content new_resource.config
end

if new_resource.property_is_set?(:chef_backend_secrets)
chef_file '/etc/chef-backend/chef-backend-secrets.json' do
source new_resource.chef_backend_secrets
user 'root'
group 'root'
mode '0600'
not_if { node['fqdn'].eql?(new_resource.bootstrap_node) }
chef_file '/etc/chef-backend/chef-backend-secrets.json' do
source new_resource.chef_backend_secrets
user 'root'
group 'root'
mode '0600'
not_if { new_resource.chef_backend_secrets.empty? }
end

http_retry_count = Chef::Config['http_retry_count']
Chef::Config['http_retry_count'] = 0
existing_peer = false
peers = (new_resource.peers.is_a?(Array) ? new_resource.peers : [new_resource.peers])

peers.each do |peer|
begin
Chef::HTTP.new("http://#{peer}:2379").get('/version')
existing_peer = peer
break
rescue
next
end
end
Chef::Config['http_retry_count'] = http_retry_count

execute 'chef-backend-ctl create-cluster --accept-license --yes' do
only_if { node['fqdn'].eql?(new_resource.bootstrap_node) }
not_if 'chef-backend-ctl cluster-status'
not_if 'chef-backend-ctl cluster-status &> /dev/null'
not_if { existing_peer }
end

execute "chef-backend-ctl join-cluster #{new_resource.bootstrap_node} --accept-license --yes" do
not_if { node['fqdn'].eql?(new_resource.bootstrap_node) }
not_if 'chef-backend-ctl cluster-status'
execute "chef-backend-ctl join-cluster #{existing_peer} --accept-license --yes" do
not_if 'chef-backend-ctl cluster-status &> /dev/null'
only_if { existing_peer }
end
end

0 comments on commit cbb34cb

Please sign in to comment.