File tree 20 files changed +205
-44
lines changed
20 files changed +205
-44
lines changed Original file line number Diff line number Diff line change 9
9
become : yes
10
10
roles :
11
11
- {role: base, tags: ['base']}
12
+ - {role: storage, tags: ['storage']}
12
13
- {role: ssh_access, tags: ['ssh_access']}
13
14
- {role: mongodb, tags: ['mongodb']}
Original file line number Diff line number Diff line change 1
1
- name : restart NTP daemon
2
- service : name=ntp state=restarted
2
+ service : name=ntp state=restarted
3
+
4
+ - name : dpkg-reconfigure locales
5
+ command : /usr/sbin/dpkg-reconfigure --frontend noninteractive locales
Original file line number Diff line number Diff line change 16
16
- curl
17
17
18
18
- name : install nl_NL.UTF-8 locale
19
- shell : locale-gen nl_NL.UTF-8
19
+ locale_gen :
20
+ name=nl_NL.UTF-8
21
+ state=present
22
+ notify : dpkg-reconfigure locales
23
+
24
+ - name : Set LC_LANG
25
+ lineinfile :
26
+ dest=/etc/environment
27
+ state=present
28
+ regexp='^LC_LANG'
29
+ line='LC_LANG="nl_NL.UTF-8"'
30
+
31
+ - name : Set LC_ALL
32
+ lineinfile :
33
+ dest=/etc/environment
34
+ state=present
35
+ regexp='^LC_ALL'
36
+ line='LC_ALL="nl_NL.UTF-8"'
20
37
21
38
- name : set timezone to UTC
22
39
when : ansible_date_time.tz != 'UTC'
Original file line number Diff line number Diff line change
1
+ ACTION=="add", KERNEL=="xvdf", ATTR{bdi/read_ahead_kb}="16"
Original file line number Diff line number Diff line change
1
+ * soft nofile 64000
2
+ * hard nofile 64000
3
+ * soft nproc 64000
4
+ * hard nproc 64000
Original file line number Diff line number Diff line change
1
+ ---
2
+ - name : create persistent storage directory
3
+ file :
4
+ dest=/persistent_storage/mongodb
5
+ state=directory
6
+ recurse=true
7
+ owner=mongodb
8
+ group=mongodb
9
+ mode=755
10
+
11
+ - name : create subdirectories for mongodb within persistent storage directory
12
+ file :
13
+ dest=/persistent_storage/mongodb/{{ item }}
14
+ state=directory
15
+ recurse=true
16
+ owner=mongodb
17
+ group=mongodb
18
+ mode=755
19
+ with_items :
20
+ - log
21
+ - data
22
+
23
+ - name : create journal subdirectory
24
+ file :
25
+ dest=/persistent_storage/mongodb/data/journal
26
+ state=directory
27
+ recurse=true
28
+ owner=mongodb
29
+ group=mongodb
30
+ mode=755
31
+
32
+ - name : create symobolic link for /journal
33
+ file :
34
+ src=/persistent_storage/mongodb/data/journal
35
+ dest=/persistent_storage/mongodb/journal
36
+ owner=mongodb
37
+ group=mongodb
38
+ state=link
39
+
40
+ - name : adjust ulimits for mongodb
41
+ copy :
42
+ src : 90-mongodb.conf
43
+ dest : " /etc/security/limits.d/90-mongodb.conf"
44
+
45
+ - name : set udev config for mongodb
46
+ copy :
47
+ src : 85-ebs.rules
48
+ dest : " /etc/udev/rules.d/85-ebs.rules"
49
+
Original file line number Diff line number Diff line change
1
+ # This is a very basic playbook for installing mongodb.
2
+ # If we want something more advanced, we might consider using
3
+ # https://github.com/UnderGreen/ansible-role-mongodb
4
+ ---
5
+ - name : import the public key used by the package management system
6
+ apt_key : keyserver=hkp://keyserver.ubuntu.com:80 id=EA312927 state=present
7
+
8
+ - name : add MongoDB repository
9
+ apt_repository : repo='deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.2 multiverse' state=present
10
+
11
+ - name : set correct (advised by mongodb) kernelsettings
12
+ copy :
13
+ src : mongo_vm_settings.conf
14
+ dest : " /etc/init/mongod_vm_settings.conf"
15
+
16
+ - name : load custom config file to allow incoming traffic
17
+ template :
18
+ src : templates/mongod.conf.j2
19
+ dest : " /etc/mongod.conf"
20
+ notify :
21
+ - start mongodb
22
+
23
+ - name : install mongodb
24
+ apt : pkg=mongodb-org state=latest update_cache=yes
25
+ notify :
26
+ - start mongodb
27
+
28
+ - name : check if mongodb is running and accepting connections
29
+ wait_for :
30
+ port : 27017
31
+ timeout : 10
Original file line number Diff line number Diff line change 1
- # This is a very basic playbook for installing mongodb.
2
- # If we want something more advanced, we might consider using
3
- # https://github.com/UnderGreen/ansible-role-mongodb
4
1
---
5
- - name : import the public key used by the package management system
6
- apt_key : keyserver=hkp://keyserver.ubuntu.com:80 id=EA312927 state=present
7
-
8
- - name : add MongoDB repository
9
- apt_repository : repo='deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.2 multiverse' state=present
10
-
11
- - name : set correct (advised by mongodb) kernelsettings
12
- copy :
13
- src : mongo_vm_settings.conf
14
- dest : " /etc/init/mongod_vm_settings.conf"
15
-
16
- - name : load custom config file to allow incoming traffic
17
- template :
18
- src : templates/mongod.conf.j2
19
- dest : " /etc/mongod.conf"
20
- notify :
21
- - start mongodb
22
-
23
- - name : install mongodb
24
- apt : pkg=mongodb-org state=latest update_cache=yes
25
- notify :
26
- - start mongodb
27
-
28
- - name : check if mongodb is running and accepting connections
29
- wait_for :
30
- port : 27017
31
- timeout : 10
2
+ - include : filesystem.yml
3
+ - include : install-mongod.yml
Original file line number Diff line number Diff line change 5
5
6
6
# Where and how to store data.
7
7
storage:
8
- dbPath: /var/lib/ mongodb
8
+ dbPath: /persistent_storage/ mongodb/data
9
9
journal:
10
10
enabled: true
11
11
# engine:
@@ -16,7 +16,7 @@ storage:
16
16
systemLog:
17
17
destination: file
18
18
logAppend: true
19
- path: /var/log/ mongodb/mongod.log
19
+ path: /persistent_storage/ mongodb/log /mongod.log
20
20
21
21
# network interfaces
22
22
net:
Original file line number Diff line number Diff line change
1
+ - name : python pip and boto
2
+ apt :
3
+ name={{ item }}
4
+ update_cache=yes
5
+ with_items :
6
+ - python-boto
7
+ - python-pip
8
+
9
+ - name : ensure pip is properly installed
10
+ easy_install : name=pip
11
+
12
+ - name : update pip to latest version
13
+ pip :
14
+ name=pip
15
+ state=latest
16
+
17
+ - name : update boto to latest version
18
+ pip :
19
+ name=boto
20
+ state=latest
Original file line number Diff line number Diff line change
1
+ ---
2
+ - include : install-boto.yml
3
+ - include : storage.yml
Original file line number Diff line number Diff line change
1
+ ---
2
+ - name : check if mount already exist
3
+ shell : df -h | grep xvdf1
4
+ register : mount_exist
5
+ ignore_errors : True
6
+
7
+ - name : Display all variables/facts known for a host
8
+ debug : var=hostvars[inventory_hostname] verbosity=1
9
+
10
+ - name : ensure that external EBS volume exists and is attached to the instance
11
+ ec2_vol :
12
+ instance : " {{ hostvars[inventory_hostname].id }}"
13
+ volume_size : 50
14
+ volume_type : gp2
15
+ device_name : /dev/xvdf
16
+ state : present
17
+ region : " {{ aws.region }}"
18
+ encrypted : yes
19
+ aws_access_key : " {{ aws.access_key }}"
20
+ aws_secret_key : " {{ aws.secret_key }}"
21
+
22
+ - name : hack fdisk with echo commands
23
+ shell : (echo n; echo; echo; echo; echo; echo w) | fdisk /dev/xvdf
24
+ when : mount_exist.stdout.find("xvdf1") < 1
25
+
26
+ - name : create a ext4 filesystem on /dev/xvdf1
27
+ filesystem :
28
+ fstype : ext4
29
+ dev : /dev/xvdf1
30
+ when : mount_exist.stdout.find("xvdf1") < 1
31
+
32
+ - name : mount our new disk
33
+ mount :
34
+ name : /persistent_storage
35
+ src : /dev/xvdf1
36
+ fstype : ext4
37
+ opts : noatime
38
+ state : mounted
39
+ when : mount_exist.stdout.find("xvdf1") < 1
Original file line number Diff line number Diff line change
1
+ # For security reasons we use environment variables, so we avoid having secrets in git.
2
+ # We reuse the environment variables set for using terraform
3
+
4
+ aws :
5
+ region : " {{ lookup('env','TF_VAR_region') }}"
6
+ access_key : " {{ lookup('env','TF_VAR_access_key') }}"
7
+ secret_key : " {{ lookup('env','TF_VAR_secret_key') }}"
Original file line number Diff line number Diff line change @@ -42,6 +42,9 @@ output:
42
42
@echo " *** VPC ***"
43
43
@terraform output --module=vpc
44
44
45
+ ping :
46
+ ansible -i bin/terraform.py/terraform.py -m ping all
47
+
45
48
clean :
46
49
terraform destroy
47
50
rm -rf $(CURDIR ) /.terraform
Original file line number Diff line number Diff line change @@ -49,7 +49,8 @@ module "mongodbnodes" {
49
49
zones = " ${ var . zones } "
50
50
key_name = " ${ aws_key_pair . terraform-deployer . id } "
51
51
52
- vpc_id = " ${ module . vpc . vpc_id } "
53
- default_sg_id = " ${ module . vpc . default_sg_id } "
54
- subnet_id_zones = " ${ module . vpc . subnet_id_zones } "
52
+ vpc_id = " ${ module . vpc . vpc_id } "
53
+ vpc_private_cidr = " ${ module . vpc . vpc_private_cidr } "
54
+ default_sg_id = " ${ module . vpc . default_sg_id } "
55
+ subnet_id_zones = " ${ module . vpc . subnet_id_zones } "
55
56
}
Original file line number Diff line number Diff line change @@ -7,10 +7,8 @@ resource "aws_security_group" "mongodb" {
7
7
from_port = 27017
8
8
to_port = 27017
9
9
protocol = " tcp"
10
- self = true
11
- cidr_blocks = [" 0.0.0.0/0" ]
10
+ cidr_blocks = [" ${ var . vpc_private_cidr } " ]
12
11
}
13
-
14
12
}
15
13
16
14
resource "aws_instance" "mongodbnodes" {
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ variable "key_name" {}
4
4
5
5
variable "vpc_id" {}
6
6
variable "default_sg_id" {}
7
+ variable "vpc_private_cidr" {}
7
8
variable "subnet_id_zones" {
8
9
type = " list"
9
10
}
Original file line number Diff line number Diff line change @@ -2,6 +2,10 @@ output "vpc_id" {
2
2
value = " ${ aws_vpc . main . id } "
3
3
}
4
4
5
+ output "vpc_private_cidr" {
6
+ value = " ${ aws_vpc . main . cidr_block } "
7
+ }
8
+
5
9
output "default_sg_id" {
6
10
value = " ${ aws_security_group . default . id } "
7
11
}
Original file line number Diff line number Diff line change @@ -13,9 +13,9 @@ variable "zones" {
13
13
variable "cidr_blocks" {
14
14
type = " list"
15
15
default = [
16
- " 10.0.0 .0/22 " ,
17
- " 10.0.8 .0/22 " ,
18
- " 10.0.16 .0/22 "
16
+ " 10.0.1 .0/23 " ,
17
+ " 10.0.10 .0/23 " ,
18
+ " 10.0.12 .0/23 "
19
19
]
20
20
}
21
21
Original file line number Diff line number Diff line change @@ -44,13 +44,20 @@ resource "aws_security_group" "default" {
44
44
description = " Default SSH and HTTP only from whitelisted cidr blocks"
45
45
vpc_id = " ${ aws_vpc . main . id } "
46
46
47
+ # Allow all traffic from instances attached to same sceurity group
48
+ ingress {
49
+ from_port = 0
50
+ to_port = 0
51
+ protocol = - 1
52
+ self = true
53
+ }
54
+
47
55
# SSH from the whitelisted CIDR blocks
48
56
ingress {
49
57
from_port = 22
50
58
to_port = 22
51
59
protocol = " tcp"
52
60
cidr_blocks = [" ${ split (" ," , var. whitelisted_cidrs )} " ]
53
- self = true
54
61
}
55
62
56
63
# Outbound internet access
You can’t perform that action at this time.
0 commit comments