Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions tasks/configure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@
recurse: true
follow: true

- name: Configure auto connection
template:
src: mongorc.js.j2
dest: /root/.mongorc.js
owner: root
group: root
mode: 0600

- name: Configure mongodb
template:
src: mongod.conf.j2
Expand Down
2 changes: 1 addition & 1 deletion tasks/install.redhat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

- name: Install MongoDB package
yum:
name: "{{ mongodb_package }}{% if (mongodb_version | length > 3) %}={{ mongodb_version }}{% endif %}"
name: "{{ mongodb_package }}{% if (mongodb_version | length > 3) %}-{{ mongodb_version }}{% endif %}"
state: "{{ mongodb_package_state }}"
lock_timeout: "{{ yum_lock_timeout }}"

Expand Down
13 changes: 12 additions & 1 deletion tasks/replication.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
when: mongodb_security_authorization == 'enabled'
with_items:
- "{{ mongodb_replication_params|default([]) }}"
retries: 60
delay: 10
register: result
until: result is succeeded

- name: Replication configuration without auth on master
mongodb_replication:
Expand All @@ -36,6 +40,10 @@
and mongodb_master is defined and mongodb_master )
with_items:
- "{{ mongodb_replication_params|default([]) }}"
retries: 60
delay: 10
register: result
until: result is succeeded

- name: Replication configuration without auth on replicas and arbiters
mongodb_replication:
Expand All @@ -54,4 +62,7 @@
and ( mongodb_master is not defined or not mongodb_master) )
with_items:
- "{{ mongodb_replication_params|default([]) }}"

retries: 60
delay: 10
register: result
until: result is succeeded
26 changes: 26 additions & 0 deletions templates/mongorc.js.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
function authRequired() {
try {
if (db.serverCmdLineOpts().code == 13) {
return true;
}
return false;
}
catch (err) {
return false;
}
}

if (authRequired()) {
try {
{% if mongodb_replication_replset -%}
rs.slaveOk()
{% endif %}
var prev_db = db
db = db.getSiblingDB('admin')
db.auth( '{{ mongodb_root_admin_name }}', '{{ mongodb_root_admin_password }}')
db = db.getSiblingDB(prev_db)
}
catch (err) {
abort('Unknown error')
}
}