-
Notifications
You must be signed in to change notification settings - Fork 1
/
playbook.yml
executable file
·147 lines (129 loc) · 4.12 KB
/
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
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
- name: Install Docker and config # PLAY1
hosts: _development
become: true
vars_files:
- "playbook-vars.yml"
tasks:
- name: Update all packages
yum:
name: '*'
state: latest
- name: Remove Docker if installed from CentOS repo
yum:
name: "{{ item }}"
state: removed
with_items:
- docker
- docker-client
- docker-client-latest
- docker-common
- docker-latest
- docker-latest-logrotate
- docker-logrotate
- docker-engine
- name: Install yum utils
yum:
name: "{{ item }}"
state: latest
with_items:
- yum-utils
- device-mapper-persistent-data
- lvm2
- unzip
- name: Add Docker repo
get_url:
url: https://download.docker.com/linux/centos/docker-ce.repo
dest: /etc/yum.repos.d/docker-ce.repo
- name: Install Docker
package:
name: docker-ce
state: latest
- name: Install pip
package:
name: python3-pip
state: present
update_cache: true
- name: Install Docker SDK
pip:
name: docker
- name: Add ec2-user to docker group
user:
name: ec2-user
groups: docker
append: yes
- name: Start Docker service
service:
name: docker
state: started
enabled: yes
- name: Download AWS CLI
get_url:
url: https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip
dest: /home/ec2-user/awscliv2.zip
- name: Unzip zip file
unarchive:
src: /home/ec2-user/awscliv2.zip
dest: /home/ec2-user
remote_src: True
- name: Install the AWS CLI
shell: ./aws/install
- name: Login to AWS ECR
shell: |
export PATH=/usr/local/bin:$PATH
source ~/.bash_profile
aws ecr get-login-password --region {{ aws_region }} | docker login --username AWS --password-stdin {{ ecr_registry }}
- name: PostgreSQL database config # PLAY2
hosts: _postgresql
become: true
vars_files:
- "playbook-vars.yml"
vars:
container_name: postgresql
tasks:
- name: Remove container and image if exist
shell: "docker ps -q --filter 'name={{ container_name }}' && docker stop {{ container_name }} && docker rm -fv {{ container_name }} && docker image rm -f {{ ecr_registry }}/{{ repo_name }}:{{ container_name }} || echo 'Not Found'"
- name: Launch PostgreSQL Docker container
docker_container:
name: "{{ container_name }}"
image: "{{ ecr_registry }}/{{ repo_name }}:{{ container_name }}"
state: started
ports:
- "5432:5432"
env:
POSTGRES_PASSWORD: "{{ postgres_password }}"
volumes:
- /db-data:/var/lib/postgresql/data
- name: Nodejs server configuration # PLAY3
hosts: _nodejs
become: true
vars_files:
- "playbook-vars.yml"
vars:
container_name: nodejs
tasks:
- name: Remove container and image if exist
shell: "docker ps -q --filter 'name={{ container_name }}' && docker stop {{ container_name }} && docker rm -fv {{ container_name }} && docker image rm -f {{ ecr_registry }}/{{ repo_name }}:{{ container_name }} || echo 'Not Found'"
- name: Launch Nodejs docker container
docker_container:
name: "{{ container_name }}"
image: "{{ ecr_registry }}/{{ repo_name }}:{{ container_name }}"
state: started
ports:
- "5000:5000"
- name: React UI Server configuration # PLAY4
hosts: _react
become: true
vars_files:
- "playbook-vars.yml"
vars:
container_name: react
tasks:
- name: Remove container and image if exist
shell: "docker ps -q --filter 'name={{ container_name }}' && docker stop {{ container_name }} && docker rm -fv {{ container_name }} && docker image rm -f {{ ecr_registry }}/{{ repo_name }}:{{ container_name }} || echo 'Not Found'"
- name: Launch React docker container
docker_container:
name: "{{ container_name }}"
image: "{{ ecr_registry }}/{{ repo_name }}:{{ container_name }}"
state: started
ports:
- "3000:3000"