-
Notifications
You must be signed in to change notification settings - Fork 8
/
restexample-windows.yml
63 lines (53 loc) · 2.75 KB
/
restexample-windows.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
---
- hosts: "{{host}}"
vars:
spring_boot_app_path: "C:\\spring-boot\\{{spring_boot_app_name}}"
path_to_java_exe: "C:\\ProgramData\\Oracle\\Java\\javapath\\java.exe"
tasks:
###### Preparation steps
- name: Create directory C:\spring-boot\spring_boot_app_name, if not there
win_file: path={{spring_boot_app_path}} state=directory
- name: Install nssm (non-sucking service manager) via chocolatey
win_chocolatey:
name: nssm
###### Stop services, if they´re already in place
- name: Stop Spring Boot service, if there - so we can extract JRE & other necessary files without Windows file handle problems
win_service:
name: "{{spring_boot_app_name}}"
state: stopped
ignore_errors: yes
###### Extraction and copying of all necessary files (unzip or install JRE, deploy Spring Boot jar)
- name: Install Java Runtime Environment (JRE) 8 via chocolatey
win_chocolatey:
name: jre8
- name: Copy Spring Boot app´s jar-File to directory C:\spring-boot\spring_boot_app_name
win_copy:
src: "{{spring_boot_app_jar}}"
dest: "{{spring_boot_app_path}}\\{{spring_boot_app_name}}.jar"
####### Service installation
# (stopping and configuration of Application directory is only done for demontration purposes - for apps that need certain .dlls on the path for example)
- name: Install Spring Boot app as Windows service (via nssm), if not already there - but remain stopped to configure Application directory
win_nssm:
name: "{{spring_boot_app_name}}"
application: "{{path_to_java_exe}}"
app_parameters_free_form: "-jar {{spring_boot_app_path}}\\{{spring_boot_app_name}}.jar"
state: stopped
####### Configure Application path & Fire up the service
# If you need to have certain .exe or .dll files on the path where your Spring Boot .jar is located, you can configure the nssm Application Directory to that path
# this is currently not supported by the ansible win_nssm module http://docs.ansible.com/ansible/win_nssm_module.html, so we have to use raw component
# After that we have to (re-) start our nssm service to bring the configuration change to life
- name: Set the Application path for the Spring Boot app to the folder where the needed native libraries reside
raw: nssm set {{spring_boot_app_name}} AppDirectory {{spring_boot_app_path}}
- name: Fire up Spring Boot app Windows service
win_service:
name: "{{spring_boot_app_name}}"
state: restarted
###### Smoke test, if app has booted up correctly
- name: Wait until our Spring Boot app is up & running
win_uri:
url: "http://localhost:8080/swagger-ui.html"
method: GET
register: result
until: result.status_code is defined and result.status_code == 200
retries: 5
delay: 5