Skip to content

Commit

Permalink
updating mongoid.yml to v3 format
Browse files Browse the repository at this point in the history
  • Loading branch information
Ines Sombra committed Sep 11, 2012
1 parent 94ea01d commit 9c31615
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
16 changes: 8 additions & 8 deletions cookbooks/mongodb/recipes/app.rb
Expand Up @@ -2,23 +2,23 @@
# no-op here as there are no utility instances, do not pass. # no-op here as there are no utility instances, do not pass.
else else
user = @node[:users].first user = @node[:users].first

if ['app_master','app'].include?(node[:instance_role]) if ['app_master','app'].include?(node[:instance_role])
mongo_replication_sets = @node[:utility_instances].select { |instance| instance[:name].match(/^mongodb_repl/) }.map { |instance| instance[:name].split("_")[1].sub("repl","") }.uniq mongo_replication_sets = @node[:utility_instances].select { |instance| instance[:name].match(/^mongodb_repl/) }.map { |instance| instance[:name].split("_")[1].sub("repl","") }.uniq
end end
mongo_app_names = @node[:applications].keys mongo_app_names = @node[:applications].keys

# Chef::Log.info "app.rb - mongo_replication_sets = #{mongo_replication_sets} | node app keys = #{@node[:applications].keys}" # Chef::Log.info "app.rb - mongo_replication_sets = #{mongo_replication_sets} | node app keys = #{@node[:applications].keys}"

mongo_app_names.each do |mongo_app_name| mongo_app_names.each do |mongo_app_name|
# Chef::Log.info "looping for mongo_app_name = #{mongo_app_name}" # Chef::Log.info "looping for mongo_app_name = #{mongo_app_name}"

template "/data/#{mongo_app_name}/shared/config/mongodb.yml" do template "/data/#{mongo_app_name}/shared/config/mongodb.yml" do
source "mongodb.yml.erb" source "mongodb.yml.erb"
owner user[:username] owner user[:username]
group user[:username] group user[:username]
mode 0755 mode 0755

if @node[:instance_role] == "solo" && @node[:mongo_utility_instances].length == 0 if @node[:instance_role] == "solo" && @node[:mongo_utility_instances].length == 0
variables(:yaml_file => { variables(:yaml_file => {
node[:environment][:framework_env] => { node[:environment][:framework_env] => {
Expand All @@ -30,15 +30,15 @@
node[:environment][:framework_env] => { node[:environment][:framework_env] => {
:hosts => hosts} }) :hosts => hosts} })
end end

end end


#Mongoid.yml_v3
template "/data/#{mongo_app_name}/shared/config/mongoid.yml" do template "/data/#{mongo_app_name}/shared/config/mongoid.yml" do
source "mongoid.yml.erb" source "mongoid_v3.yml.erb"
owner user[:username] owner user[:username]
group user[:username] group user[:username]
mode 0755 mode 0755

hosts = @node[:mongo_utility_instances].select { |instance| instance[:name].match(/#{mongo_app_name}/) }.map { |instance| [ instance[:hostname], @node[:mongo_port].to_i ] } hosts = @node[:mongo_utility_instances].select { |instance| instance[:name].match(/#{mongo_app_name}/) }.map { |instance| [ instance[:hostname], @node[:mongo_port].to_i ] }
replica_set = @node[:mongo_utility_instances].any? { |instance| instance[:name].match(/^mongodb_repl/) } replica_set = @node[:mongo_utility_instances].any? { |instance| instance[:name].match(/^mongodb_repl/) }
if replica_set if replica_set
Expand Down
12 changes: 12 additions & 0 deletions cookbooks/mongodb/templates/default/mongoid_v3.yml.erb
@@ -0,0 +1,12 @@
<%= @environment %>:
sessions:
default:
hosts:
<% @hosts.each do |host, port| -%>
- <%= host %>:<%= port %>
<% end -%>
database: <%=@mongo_replsetname%>
# Mongoid specific configuration options
options:
consistency: :eventual
max_retries_on_connection_failure: 5

0 comments on commit 9c31615

Please sign in to comment.