-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmongo.yaml
executable file
·77 lines (65 loc) · 2.12 KB
/
mongo.yaml
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
- name: Configure mongo server
hosts: mongo
gather_facts: True
become: false
tasks:
- name: Install mongo server
apt:
name: mongodb-org
state: present
- name: Restart mongo service
service:
name: mongod
state: restarted
- name: Preparing master user configuration
template:
src: conf/controller/mongo/master-user.conf
dest: /tmp/master-user.conf
owner: root
group: root
mode: 0644
when: ansible_ssh_host == hostvars[master].ansible_ssh_host
- name: Configuring master user
command: sh -c "mongo < /tmp/master-user.conf"
when: ansible_ssh_host == hostvars[master].ansible_ssh_host
- file:
path: /var/mongo
state: directory
owner: root
group: root
mode: 0655
- name: Copy mongo communication key
template:
src: keys/keyfile
dest: /var/mongo/keyfile
owner: mongodb
group: mongodb
mode: 0400
- name: Copy mongo configuration
template:
src: conf/controller/mongo/mongod.conf
dest: /etc/mongod.conf
owner: root
group: root
mode: 0644
- name: Preparing master cluster configuration
template:
src: conf/controller/mongo/master-cluster.conf
dest: /tmp/master-cluster.conf
owner: root
group: root
mode: 0644
when: ansible_ssh_host == hostvars[master].ansible_ssh_host
- name: Restart mongo service
service:
name: mongod
state: restarted
- name: Initiating cluster
command: sh -c "mongo -u root -p {{master_password}} --eval 'rs.initiate()' > /tmp/mongo.init"
when: ansible_ssh_host == hostvars[master].ansible_ssh_host
- name: Getting status
command: sh -c "mongo -u root -p {{master_password}} --eval 'rs.status()' > /tmp/mongo.status"
when: ansible_ssh_host == hostvars[master].ansible_ssh_host
- name: Adding nodes
command: sh -c "mongo -u root -p {{master_password}} < /tmp/master-cluster.conf"
when: ansible_ssh_host == hostvars[master].ansible_ssh_host