-
Notifications
You must be signed in to change notification settings - Fork 1
/
CentOS7x_Initiate-MongoDB-Replication-on-a-Three-Member-Set-playbook.yml
51 lines (38 loc) · 2.13 KB
/
CentOS7x_Initiate-MongoDB-Replication-on-a-Three-Member-Set-playbook.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
---
################################################################################
# description: Initiate MongoDB replication on three (3) speciic MongoDB 3x hosts on CentOS7x
# usage: ansible-playbook CentOS7x_Initiate-MongoDB-Replication-on-a-Three-Member-Set-playbook.yml --extra-vars 'ReplicaMaster=MongoReplicaMasterHostNameOrIpGoesHere ReplicaSlave1=MongoReplicaSlave1HostNameOrIpGoesHere ReplicaSlave2=MongoReplicaSlave2HostNameOrIpGoesHere MongoAdminPassword=mongodb'
# author: Ernest G. Wilson II <[email protected]> (https://github.com/ernestgwilsonii)
# license: MIT
################################################################################
# Ansible Playbook options
# REF: http://docs.ansible.com/ansible/playbooks.html
#####################################################
- name: Preparing to start the intial MongoDB replication on three MongoDB hosts
hosts: "{{ReplicaMaster}}"
serial: "100%"
gather_facts: False
tasks:
# Use the template module to populate files with data
# REF: http://docs.ansible.com/ansible/template_module.html
###########################################################
# Copy the replication initialization script to the master /tmp/ directory
- name: Copy the initial replication script from Ansible to the host that will be the starting MongoDB replication master
template:
src=templates/MongoDB/initiateReplication.js.j2
dest=/tmp/initiateReplication.js
owner=root
group=mongod
mode=0644
# Execute raw command(s)
# REF: http://docs.ansible.com/ansible/raw_module.html
##########################################################
- name: Initializing MongoDB replication
raw: mongo -ssl --sslAllowInvalidCertificates --port 27017 -u "admin" -p "{{MongoAdminPassword|default ('mongodb')}}" --authenticationDatabase "admin" < /tmp/initiateReplication.js
# Use the file module
# REF: http://docs.ansible.com/ansible/file_module.html
#######################################################
- name: Remove the temporary file from the replication master - rm /tmp/initiateReplication.js
file:
path: /tmp/initiateReplication.js
state: absent