-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdocker_nodejs.yml
107 lines (92 loc) · 2.61 KB
/
docker_nodejs.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
- name: Install docker
gather_facts: No
any_errors_fatal: true
hosts: ansible_nodejs
become: true
tasks:
- name: upgrade all packages
yum:
name: "*"
state: latest
# we may need to uninstall any existing docker files from the centos repo first.
- 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
- 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 user 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: create build directory
file:
path: /home/ec2-user/nodejs
state: directory
owner: root
group: root
mode: "0755"
# at this point do not forget change DB_HOST env variable for postgresql node
- name: copy files to the nodejs node
copy:
src: /home/ec2-user/ansible-servers/todo-app/server/
dest: /home/ec2-user/nodejs
- name: copy the Dockerfile
copy:
src: /home/ec2-user/ansible-servers/nodejs/Dockerfile
dest: /home/ec2-user/nodejs
- name: remove enes_nodejs container if exists
shell: "docker ps -q --filter 'name=enes_nodejs' && docker stop enes_nodejs && docker rm -fv enes_nodejs && docker image rm devenes/nodejs || echo 'Not Found'"
- name: build container image
docker_image:
name: devenes/nodejs
build:
path: /home/ec2-user/nodejs
source: build
state: present
- name: Launch nodejs docker container
docker_container:
name: enes_nodejs
image: devenes/nodejs
state: started
ports:
- "5000:5000"
register: container_info
- name: Print the container_info
debug:
msg: "{{ container_info }}"