-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgfh_deploy_tool.yaml
116 lines (97 loc) · 4.42 KB
/
gfh_deploy_tool.yaml
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
108
109
110
111
112
113
114
115
---
- hosts: app01
#remote_user: user
#gather_facts: true
vars:
- app_user: 'gfhadmin'
- app_name: "{{ app }}"
- app_project: "{{ project }}"
- app_env: "{{ env }}"
- app_dir: "/app/www/{{ app_env }}"
- app_script: "{{ app_name }}.sh"
- app_jar: "{{ app_name }}.jar"
- app_conf: "{{ app_name }}.properties"
- app_port: "{{ jarport }}"
- backup_dir: '/app/backup'
- backup_name: "{{ backup }}"
- ftp_dir: "/{{ app_env }}"
- Upload_dir: "/tmp"
- ansible_server: "172.1.1.2"
- ftp_server: "172.1.1.1"
- ftp_username: "xxx"
- ftp_password: "xxx"
tasks:
- name: "Deploy: Download MD5sum From Ftp {{ ftp_server }}{{ ftp_dir }}/{{ app_project }}/{{ app_jar }}.txt"
get_url:
url: "ftp://{{ ftp_username }}:{{ ftp_password }}@{{ ftp_server }}{{ ftp_dir }}/{{ app_project }}/{{ app_jar }}.txt"
backup: yes
dest: "{{ Upload_dir }}"
mode: 0640
group: "{{ app_user }}"
owner: "{{ app_user }}"
timeout: 60
delegate_to: "{{ ansible_server }}"
- name: "Deploy: Get The Checksum value of {{ app_jar }}"
shell: "cat {{ Upload_dir }}/{{ app_jar }}.txt"
register: checksum_results
delegate_to: "{{ ansible_server }}"
- name: "Deploy: Diplay checksum_results of {{ app_jar }}"
debug: var=checksum_results.stdout
delegate_to: "{{ ansible_server }}"
- name: "Deploy: Download Jar From Ftp {{ ftp_server }}{{ ftp_dir }}/{{ app_project }}/{{ app_jar }} "
get_url:
url: "ftp://{{ ftp_username }}:{{ ftp_password }}@{{ ftp_server }}{{ ftp_dir }}/{{ app_project }}/{{ app_jar }}"
backup: yes
dest: "{{ Upload_dir }}"
mode: 0640
group: "{{ app_user }}"
owner: "{{ app_user }}"
checksum: md5:{{ checksum_results.stdout }}
timeout: 60
delegate_to: "{{ ansible_server }}"
- name: "Deploy: Download script and conf From Ftp {{ ftp_server }}{{ ftp_dir }}/{{ app_project }}/{{ app_conf }} "
get_url:
url: "ftp://{{ ftp_username }}:{{ ftp_password }}@{{ ftp_server }}{{ ftp_dir }}/{{ app_project }}/{{ item }}"
backup: yes
dest: "{{ Upload_dir }}"
mode: 0640
group: "{{ app_user }}"
owner: "{{ app_user }}"
timeout: 60
with_items:
- "{{ app_script }}"
- "{{ app_conf }}"
delegate_to: "{{ ansible_server }}"
- name: "Deploy Create Backup Dir : {{ backup_dir }}/{{ app_project }}/{{ backup_name }}"
file: path={{ backup_dir }}/{{ app_project }}/{{ backup_name }} state=directory group={{ app_user }} owner={{ app_user }} mode=750
- name: "Deploy: Create Project dir : {{ app_dir }}/{{ app_project }} "
file: path={{ app_dir }}/{{ app_project }} state=directory group={{ app_user }} owner={{ app_user }} mode=0750
- name: "Deploy Backup : {{ app_dir }}/{{ app_project }}/ {{ app_jar }} {{ app_conf }} {{ app_script }}"
shell: cp -rp {{ app_dir }}/{{ app_project }}/{{ item }} {{ backup_dir }}/{{ app_project }}/{{ backup_name }}/
with_items:
- "{{ app_jar }}"
- "{{ app_conf }}"
- "{{ app_script }}"
- name: "Deploy Stop : APP {{ app_jar }}"
shell: "ps aux | grep {{ app_jar }} | grep -v grep| awk '{print $2}' |xargs kill -9"
ignore_errors: yes
- name: "Deploy Upload : {{ app_jar }} {{ app_conf }} {{ app_script }} to {{ app_dir }}/{{ app_project }}/ "
copy: src={{ Upload_dir }}/{{ item }} dest={{ app_dir }}/{{ app_project }}/ group={{ app_user }} owner={{ app_user }} mode=640
with_items:
- "{{ app_jar }}"
- "{{ app_conf }}"
- "{{ app_script }}"
- name: "Deploy: Set {{ app_dir }}/{{ app_project }}/{{ app_script }} owner and mode"
file: path={{ app_dir }}/{{ app_project }}/{{ app_script }} group={{ app_user }} owner={{ app_user }} mode=0750
- name: "Deploy Restart : Run Script {{ app_script }}"
shell: "sh {{ app_dir }}/{{ app_project }}/{{ app_script }} restart"
- name: "Deploy Health Check : Wait for instance to respond to {{ app_port }} Port"
wait_for:
port: "{{ app_port }}"
state: started
timeout: 120
- name: "Deploy Health Check : Find The {{ app_jar }} Process "
shell: "ps aux| grep {{ app_jar }} |grep -v grep"
register: process
- name: "Deploy Health Check : Show The {{ app_jar }} Process "
debug: var=process.stdout verbosity=0