-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_tomcat.yml
80 lines (66 loc) · 2.13 KB
/
run_tomcat.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
---
- name: Run Tomcat Sample Application on Docker Container
hosts: tomcat-server
vars:
tomcatpath: /opt/tomcat-docker
become: yes
tasks:
- name: Install Python3 Package requests
command: pip3 install requests
- name: Install Python3 Package docker-py
command: pip3 install docker-py
- name: Run Python Test
command: pytest-3
register: container_exists
ignore_errors: yes
- block:
- name: Remove Build Directory If Exists
file:
path: "{{tomcatpath}}"
state: absent
ignore_errors: yes
- name: Create Build Directory
file:
path: "{{tomcatpath}}"
state: directory
mode: 755
- name: Download Tomcat 9.0.45
get_url:
url: http://archive.apache.org/dist/tomcat/tomcat-9/v9.0.45/bin/apache-tomcat-9.0.45.tar.gz
dest: "{{tomcatpath}}/apache-tomcat-9.0.45.tar.gz"
mode: 755
force: yes
- name: Download Tomcat Sample Application
get_url:
url: https://tomcat.apache.org/tomcat-9.0-doc/appdev/sample/sample.war
dest: "{{tomcatpath}}/sample.war"
mode: 755
force: yes
- name: Copy start_tomcat.sh script to Build Directory
copy:
src: start_tomcat.sh
dest: "{{tomcatpath}}/start_tomcat.sh"
mode: 755
- name: Copy Dockerfile to Build Directory
copy:
src: Dockerfile
dest: "{{tomcatpath}}/Dockerfile"
mode: 755
- name: Build Docker Image
command: "docker build -f Dockerfile -t apache-tomcat-sample:latest ."
args:
chdir: "{{tomcatpath}}"
- name: Check Tomcat Container Exists
command: docker ps -aqf "name=apache-tomcat-sample-container"
register: container
- block:
- name: Remove Tomcat Docker Container
command: "docker rm -f {{container.stdout}}"
when: container.stdout != ""
- name: Run Docker Container
command: docker run -d -p 8080:8080 --name apache-tomcat-sample-container apache-tomcat-sample:latest
- name: Remove Build Directory
file:
path: "{{tomcatpath}}"
state: absent
when: container_exists.rc != 0