Skip to content

Commit d1f5d8b

Browse files
committed
Users should be created before the database
Databases in MongoDB are created lazy, meaning there is no `create` command. Thus if a record is inserted the DB is created. When auth is enabled, any attempt to insert data is denied because of missing auth. However the `db.createUser()` function works because of the config option `enableBypassLocalAuth`. For an overview see https://www.mongodb.com/docs/manual/tutorial/deploy-replica-set-with-keyfile-access-control/
1 parent b766033 commit d1f5d8b

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

lib/puppet/type/mongodb_database.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,8 @@
2626
autorequire(:service) do
2727
%w[mongodb mongod]
2828
end
29+
30+
autorequire(:mongodb_database) do
31+
self[:user]
32+
end
2933
end

lib/puppet/type/mongodb_user.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,6 @@ def insync?(_is)
117117
%w[mongodb mongod]
118118
end
119119

120-
autorequire(:mongodb_database) do
121-
self[:database]
122-
end
123-
124120
validate do
125121
if self[:password_hash].nil? && self[:password].nil? && provider.password.nil? && provider.password_hash.nil?
126122
err("Either 'password_hash' or 'password' should be provided")

0 commit comments

Comments
 (0)