-
Notifications
You must be signed in to change notification settings - Fork 5
/
deploy-aws-mongo.yml
80 lines (66 loc) · 2.35 KB
/
deploy-aws-mongo.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
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
78
79
80
# Example to create an AWS instance and install MongoDB
#
# The region, key_name, image and security group (group) must match your configuration
#
# Before running the playbook, ensure that:
# - The key 'demo-key' has been added to ssh-agent
# - export ANSIBLE_HOST_KEY_CHECKING=False
# - The environment variables AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY match your credentials
#
---
- hosts: localhost
connection: local
gather_facts: no
tasks:
- name: EC2 provisioning of MongoDB instance
ec2:
region: eu-west-1
key_name: demo-key
instance_type: t2.micro
image: ami-234ecc54
wait: yes
instance_tags:
Name: mongo-server
exact_count: 1
count_tag:
Name: mongo-server
group:
- SSH-ACCESS
volumes:
- device_name: /dev/xvdc
# /dev/xvdc of 5 GB
volume_size: 5
register: ec2
- name: Wait for SSH to come up
wait_for: host={{ item.public_ip }} port=22 delay=10 timeout=320 state=started
with_items: ec2.instances
- name: Add the host to the group to be provisioned
add_host: name={{ item.public_ip }} groupname=to_be_provisioned
with_items: ec2.instances
- hosts: to_be_provisioned
user: ubuntu
sudo: yes
roles:
- {
role: mongodb_server,
small_files: true
}
tasks:
- name: Install the pre-requisites
apt: name={{ item }} update_cache=yes
with_items:
- lvm2
- name: Create a vg named vgdata with /dev/xvdc
lvg: vg=vgdata pvs=/dev/xvdc
- name: Create a lv named lvdata01 in vgdata
lvol: vg=vgdata lv=lvdata01 size=80%VG
- name: Create an ext4 filesystem in /dev/mapper/vgdata-lvdata01
filesystem: fstype=ext4 dev=/dev/mapper/vgdata-lvdata01
- name: Make sure mongod is stopped
service: name=mongod state=stopped
- name: Mount the directory
mount: name=/var/lib/mongodb src=/dev/mapper/vgdata-lvdata01 fstype=ext4 state=mounted
- name: Re-establish permissions for the directory
file: path=/var/lib/mongodb owner=mongodb group=nogroup state=directory recurse=yes
- name: Make sure mongod is started
service: name=mongod state=started