@@ -23,17 +23,19 @@ def self.instances
23
23
Puppet . debug ( "Fetching user #{ user } " )
24
24
db = if user [ 'db' ] == '$external'
25
25
# For external users, we need to retreive the original DB name from here.
26
- user [ 'customData' ] [ 'createdBy' ] [ %r{.*on db (.*)'\] $} , 1 ]
26
+ user [ 'customData' ] [ 'createdBy' ] [ %r{.* (.*)'\] $} , 1 ]
27
27
else
28
28
user [ 'db' ]
29
29
end
30
- new ( name : user [ '_id' ] ,
30
+ u = new ( name : user [ '_id' ] ,
31
31
ensure : :present ,
32
32
username : user [ 'user' ] ,
33
33
database : db ,
34
34
roles : from_roles ( user [ 'roles' ] , db ) ,
35
35
password_hash : user [ 'credentials' ] [ 'MONGODB-CR' ] ,
36
36
scram_credentials : user [ 'credentials' ] [ 'SCRAM-SHA-1' ] )
37
+ Puppet . debug ( "Fetching users, creating the found resources: #{ u } " )
38
+ u
37
39
end
38
40
else
39
41
Puppet . warning 'User info is available only from master host'
@@ -57,6 +59,7 @@ def create
57
59
password_hash = @resource [ :password_hash ]
58
60
password_hash = Puppet ::Util ::MongodbMd5er . md5 ( @resource [ :username ] , @resource [ :password ] ) if !password_hash && @resource [ :password ]
59
61
62
+
60
63
command = {
61
64
createUser : @resource [ :username ] ,
62
65
customData : {
@@ -88,8 +91,6 @@ def create
88
91
Puppet . debug ( "Creating user for with command #{ command } " )
89
92
mongo_eval ( "db.runCommand(#{ command . to_json } )" , @resource [ :database ] )
90
93
end
91
- else
92
- Puppet . warning 'User creation is available only from master host'
93
94
94
95
@property_hash [ :ensure ] = :present
95
96
@property_hash [ :username ] = @resource [ :username ]
@@ -98,6 +99,9 @@ def create
98
99
@property_hash [ :roles ] = @resource [ :roles ]
99
100
100
101
exists?
102
+
103
+ else
104
+ Puppet . warning 'User creation is available only from master host'
101
105
end
102
106
end
103
107
0 commit comments