-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker_nodejs.yml
More file actions
93 lines (82 loc) · 2.61 KB
/
docker_nodejs.yml
File metadata and controls
93 lines (82 loc) · 2.61 KB
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
- name: Install docker
hosts: _ansible_nodejs
become: true
tasks:
- name: upgrade all packages
ansible.builtin.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
ansible.builtin.yum:
name:
- docker
- docker-client
- docker-client-latest
- docker-common
- docker-latest
- docker-latest-logrotate
- docker-logrotate
- docker-engine
state: removed
# yum-utils is a collection of tools and programs for managing yum repositories, installing debug packages, source packages, extended information from repositories and administration.
- name: Install yum utils
ansible.builtin.yum:
name: "yum-utils"
state: latest
# set up the repository (`yum_repository` modul can be used.)
- name: Add Docker repo
ansible.builtin.get_url:
url: https://download.docker.com/linux/centos/docker-ce.repo
dest: /etc/yum.repos.d/docker-ce.repo
- name: Install Docker
ansible.builtin.package:
name: docker-ce
state: latest
- name: Add user ec2-user to docker group
ansible.builtin.user:
name: ec2-user
groups: docker
append: yes
- name: Start Docker service
ansible.builtin.service:
name: docker
state: started
enabled: yes
- name: copy files to the nodejs node
ansible.builtin.copy:
src: /home/ec2-user/ansible-project/nodejs/
dest: /home/ec2-user/nodejs
# Remove the container if it exists
- name: remove cw_nodejs container
community.docker.docker_container:
name: cw_nodejs
state: absent
force_kill: true
# Remove the image if it exists
- name: remove clarusway/nodejs image
community.docker.docker_image:
name: clarusway/nodejs
state: absent
- name: build container image
community.docker.docker_image:
name: clarusway/nodejs
build:
path: /home/ec2-user/nodejs
source: build
state: present
register: image_info
- name: print the image info
ansible.builtin.debug:
var: image_info
- name: Launch nodejs docker container
community.docker.docker_container:
name: cw_nodejs
image: clarusway/nodejs
state: started
ports:
- "5000:5000"
register: container_info
- name: print the container info
ansible.builtin.debug:
var: container_info