-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.yml
More file actions
53 lines (47 loc) · 1.52 KB
/
deploy.yml
File metadata and controls
53 lines (47 loc) · 1.52 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
---
- name: Deploy Calculator App with Docker
hosts: local
become: no
vars:
docker_hub_username: "seifeldinzook"
docker_image_name: "calculator-app"
docker_image_tag: "latest"
container_name: "calculator-container"
host_port: 8080
container_port: 80
tasks:
- name: Check if Docker is installed
command: docker --version
register: docker_check
changed_when: false
failed_when: false
- name: Display Docker check status
debug:
msg: "Docker is installed: {{ docker_check.stdout }}"
when: docker_check.rc == 0
- name: Fail if Docker is not installed
fail:
msg: "Docker is not installed. Please install Docker first."
when: docker_check.rc != 0
- name: Stop and remove existing container if it exists
docker_container:
name: "{{ container_name }}"
state: absent
ignore_errors: yes
when: docker_check.rc == 0
- name: Pull the latest Docker image
docker_image:
name: "{{ docker_hub_username }}/{{ docker_image_name }}:{{ docker_image_tag }}"
source: pull
force_source: yes
when: docker_check.rc == 0
- name: Run the Docker container
docker_container:
name: "{{ container_name }}"
image: "{{ docker_hub_username }}/{{ docker_image_name }}:{{ docker_image_tag }}"
state: started
restart_policy: unless-stopped
ports:
- "{{ host_port }}:{{ container_port }}"
detach: yes
when: docker_check.rc == 0