Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SASC
sentinel-legacy
Commits
a358be84
Commit
a358be84
authored
Jan 24, 2016
by
bow
Browse files
Update Ansible MongoDB role to add regular users
parent
74a0ba8e
Changes
3
Hide whitespace changes
Inline
Side-by-side
deployment/ansible-role-mongodb/defaults/main.yml
View file @
a358be84
---
## User-specific options ##
# Database root user
mongodb_
user_
root_name
:
db
-r
oot
mongodb_
user_
root_password
:
root
mongodb_root_name
:
db
R
oot
mongodb_root_password
:
root
mongodb_user_
sentinel_name
:
sentinel-api
mongodb_user_
sentinel
_password
:
api
mongodb_user_
admin_name
:
dbUserAdmin
mongodb_user_
admin
_password
:
userAdmin
mongodb_users
:
[]
## System options ##
# MongoDB package name (mongodb-org for vendor, mongodb for apt)
...
...
deployment/ansible-role-mongodb/tasks/config_auth.yml
View file @
a358be84
---
-
name
:
ensure database root user exists
shell
:
"
/usr/bin/mongo
--quiet
-u
{{
mongodb_
user_
root_name
}}
-p
{{
mongodb_
user_
root_password
}}
--eval
\"
db.system.users.find({user:
'{{
mongodb_
user_
root_name
}}'}).count()
\"
admin
||
true"
shell
:
"
/usr/bin/mongo
--quiet
-u
{{
mongodb_root_name
}}
-p
{{
mongodb_root_password
}}
--eval
\"
db.system.users.find({user:
'{{
mongodb_root_name
}}'}).count()
\"
admin
||
true"
register
:
root_user_exists
changed_when
:
root_user_exists.stdout != "1" or root_user_exists.rc !=
0
-
name
:
ensure database se
ntinel
user exists
shell
:
"
/usr/bin/mongo
--quiet
-u
{{
mongodb_
user_
root_name
}}
-p
{{
mongodb_
user_
root_password
}}
--eval
\"
db.system.users.find({user:
'{{
mongodb_user_
sentinel
_name
}}'}).count()
\"
admin
||
true"
register
:
sentinel
_user_exists
changed_when
:
sentinel
_user_exists.stdout != "1" or
sentinel
_user_exists.rc !=
0
-
name
:
ensure database
u
se
r admin
user exists
shell
:
"
/usr/bin/mongo
--quiet
-u
{{
mongodb_root_name
}}
-p
{{
mongodb_root_password
}}
--eval
\"
db.system.users.find({user:
'{{
mongodb_user_
admin
_name
}}'}).count()
\"
admin
||
true"
register
:
admin
_user_exists
changed_when
:
admin
_user_exists.stdout != "1" or
admin
_user_exists.rc !=
0
-
name
:
disable auth on mongod.conf if users need to be added
-
name
:
ensure other users exist
shell
:
"
/usr/bin/mongo
--quiet
-u
{{
mongodb_root_name
}}
-p
{{
mongodb_root_password
}}
--eval
\"
db.system.users.find({user:
'{{
item.name
}}'}).count()
\"
admin
||
true"
register
:
other_users_exist
changed_when
:
other_users_exist.stdout != "1" or other_users_exist.rc !=
0
with_items
:
-
"
{{
mongodb_users
}}"
when
:
mongodb_users is defined and mongodb_users
-
name
:
disable auth on mongod.conf if root or admin need to be added
template
:
src=mongod_noauth.conf.j2 dest=/etc/mongod.conf owner=root group=root mode=0644
when
:
root_user_exists|changed or
sentinel
_user_exists|changed
when
:
root_user_exists|changed or
admin
_user_exists|changed
-
name
:
restart mongodb if config changed
service
:
name={{ mongodb_daemon_name }} state=restarted
when
:
root_user_exists|changed or
sentinel
_user_exists|changed
when
:
root_user_exists|changed or
admin
_user_exists|changed
-
name
:
create database root user
in admin
if missing
-
name
:
create database root user if missing
mongodb_user
:
database
:
admin
name
:
"
{{
item.name
}}"
...
...
@@ -28,15 +36,15 @@
state
:
present
with_items
:
-
{
name
:
"
{{
mongodb_
user_
root_name
}}"
,
password
:
"
{{
mongodb_
user_
root_password
}}"
,
roles
:
"
root
"
name
:
"
{{
mongodb_root_name
}}"
,
password
:
"
{{
mongodb_root_password
}}"
,
roles
:
root
}
when
:
root_user_exists|changed
-
name
:
create database
sentinel user in sentinel
if missing
-
name
:
create database
admin user
if missing
mongodb_user
:
database
:
sentinel
database
:
admin
name
:
"
{{
item.name
}}"
password
:
"
{{
item.password
}}"
roles
:
"
{{
item.roles
}}"
...
...
@@ -44,16 +52,31 @@
state
:
present
with_items
:
-
{
name
:
"
{{
mongodb_user_
sentinel
_name
}}"
,
password
:
"
{{
mongodb_user_
sentinel
_password
}}"
,
roles
:
"
readWrite"
name
:
"
{{
mongodb_user_
admin
_name
}}"
,
password
:
"
{{
mongodb_user_
admin
_password
}}"
,
roles
:
userAdminAnyDatabase
}
when
:
sentinel_user_exists|changed
when
:
admin_user_exists|changed
-
name
:
create other users
mongodb_user
:
database
:
"
{{
item.database
}}"
name
:
"
{{
item.name
}}"
password
:
"
{{
item.password
}}"
roles
:
"
{{
item.roles
}}"
login_user
:
"
{{
mongodb_user_admin_name
}}"
login_database
:
admin
login_password
:
"
{{
mongodb_user_admin_password
}}"
login_port
:
"
{{
mongodb_conf_port
}}"
state
:
present
with_items
:
-
"
{{
mongodb_users
}}"
when
:
other_users_exist|changed
-
name
:
restore mongod.conf if auth was disabled
template
:
src=mongod.conf.j2 dest=/etc/mongod.conf owner=root group=root mode=0644
when
:
root_user_exists|changed or
sentinel
_user_exists|changed
when
:
root_user_exists|changed or
admin
_user_exists|changed
-
name
:
restart mongodb if config changed
service
:
name={{ mongodb_daemon_name }} state=restarted
when
:
root_user_exists|changed or
sentinel
_user_exists|changed
when
:
root_user_exists|changed or
admin
_user_exists|changed
deployment/ansible-role-mongodb/tasks/config_db.yml
View file @
a358be84
...
...
@@ -5,7 +5,7 @@
when
:
mongodb_js_script is defined
-
name
:
run database config script
shell
:
/usr/bin/mongo --quiet 127.0.0.1:27017/sentinel {{ mongodb_misc_dir }}/{{ mongodb_js_script }} -u {{ mongodb_
user_
root_name }} -p {{ mongodb_
user_
root_password }} --authenticationDatabase admin
shell
:
/usr/bin/mongo --quiet 127.0.0.1:27017/sentinel {{ mongodb_misc_dir }}/{{ mongodb_js_script }} -u {{ mongodb_root_name }} -p {{ mongodb_root_password }} --authenticationDatabase admin
when
:
mongodb_js_script is defined
register
:
js_script
changed_when
:
js_script.stdout != ""
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment