diff --git a/resources/libraries/minio_helpers.rb b/resources/libraries/minio_helpers.rb index 0e42425..d12b216 100644 --- a/resources/libraries/minio_helpers.rb +++ b/resources/libraries/minio_helpers.rb @@ -23,5 +23,19 @@ def self.check_remote_hosts(hosts) end all_alive end + + def self.s3_ready? + command_output = `serf members list` + + nodes = command_output.split("\n") + leader_node = nodes.find { |node| node.include?('leader=ready') } + + if leader_node + s3_tag = leader_node[/s3=([a-zA-Z0-9_-]+)/, 1] + return s3_tag == 'ready' + else + return false + end + end end end diff --git a/resources/providers/config.rb b/resources/providers/config.rb index 3749081..aaa7924 100644 --- a/resources/providers/config.rb +++ b/resources/providers/config.rb @@ -4,13 +4,10 @@ user = new_resource.user s3_bucket = new_resource.s3_bucket s3_endpoint = new_resource.s3_endpoint - s3_databag = Chef::DataBagItem.load('passwords','s3_secrets') rescue nil - im_solo = false - if s3_databag.nil? + if !Minio::Helpers.s3_ready? s3_user = Minio::Helpers.generate_random_key(20) s3_password = Minio::Helpers.generate_random_key(40) - im_solo = true else s3_user = new_resource.access_key_id s3_password = new_resource.secret_key_id @@ -60,7 +57,6 @@ s3_bucket: s3_bucket, s3_endpoint: s3_endpoint ) - only_if { im_solo } end template '/root/.s3cfg_initial' do @@ -70,7 +66,6 @@ s3_password: s3_password, s3_endpoint: s3_endpoint ) - only_if { im_solo } end Chef::Log.info('Minio cookbook has been processed')