-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup-jpetstore-demo.yml
226 lines (195 loc) · 7.89 KB
/
setup-jpetstore-demo.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
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
---
# create databases for JPetStore Environments
- hosts: db_server
become: yes
gather_facts: yes
pre_tasks:
- name: Include JPetStore related vars
include_vars:
file: vars/jpetstore_demo_variables.yml
- name: Include Urbancode Deploy related vars
include_vars:
dir: ../deploy-urbancode-deploy/group_vars
extensions:
- 'yaml'
- 'yml'
roles:
- role: geerlingguy.mysql
post_tasks:
- name: create jpetstore databaes
mysql_db:
name: "{{ jpetstore_db.name }}_{{ item.key}}"
encoding: utf8
collation: utf8_bin
state: present
loop: "{{ lookup('dict', demo_target_environment_vars) }}"
- name: create jpetstore user
mysql_user:
name: "{{ jpetstore_db.user }}"
password: "{{ jpetstore_db.password }}"
host: "localhost"
- name: add grant to jpetstore User
mysql_user:
name: "{{ jpetstore_db.user }}"
append_privs: yes
priv: "{{ jpetstore_db.name }}_{{ item.key}}.*:ALL,GRANT"
host: "%"
state: present
loop: "{{ lookup('dict', demo_target_environment_vars) }}"
- hosts: ucd_server
# gather_facts: yes
become: yes
tasks:
- name: Include JPetStore related vars
include_vars:
file: vars/jpetstore_demo_variables.yml
- name: create a download directory if not exists
file:
path: "{{ download_dir }}/{{ demo_name }}"
state: directory
recurse: yes
# Component artifacts: /home/JPetStore/shared/.... -> available from zip file
- name: download JPetStore-Artifacts pack
copy:
src: "{{ demo_source_directory }}/{{ demo_name }}/{{ demo_artifact_binaries }}"
dest: "{{ download_dir }}/{{ demo_name }}"
- name: unzip JPetStore-Artifacts pack
unarchive:
src: "{{ download_dir }}/{{ demo_name }}/{{ demo_artifact_binaries }}"
dest: "{{ demo_target_directory }}"
creates: "{{ demo_target_directory }}/{{ demo_name }}"
remote_src: yes
- name: set owner of JPetStore artifacts directory to running user
file:
path: "{{ demo_target_directory }}/{{ demo_name }}"
state: directory
recurse: yes
owner: "{{ ansible_ssh_user }}"
group: "{{ ansible_ssh_user }}"
- name: create webserver directory if not exists
file:
path: "{{ at_target_directory }}"
state: directory
recurse: yes
# download apache tomcat for the environments sit and uat
- name: download apache tomcat
get_url:
url: "{{ at_download_url }}"
dest: "{{ download_dir }}"
# - name: download JPetStore-Artifacts pack
# copy:
# src: "{{ at_source_directory }}/{{ at_file_name }}.{{ at_file_extension }}"
# dest: "{{ download_dir }}"
# unzip archive and copy it to destination directories
- name: unzip apache tomcat archive
unarchive:
src: "{{ download_dir }}/{{ at_file_name }}.{{ at_file_extension }}"
dest: "{{ download_dir }}"
creates: "{{ download_dir }}/{{ at_file_name }}"
remote_src: yes
- name: copy to target directory
copy:
src: "{{ download_dir }}/{{ at_file_name }}/"
dest: "{{ at_target_directory }}/{{ item.key}}-{{ at_file_name }}"
remote_src: yes
loop: "{{ lookup('dict', demo_target_environment_vars) }}"
- name: change non ssl ports in server.xml
replace:
path: "{{ at_target_directory }}/{{ item.key }}-{{ at_file_name }}/conf/server.xml"
regexp: "{{at_standard_ports.non_ssl_port }}"
replace: "{{ item.value.non_ssl_port }}"
loop: "{{ lookup('dict', demo_target_environment_vars) }}"
- name: change ssl ports in server.xml
replace:
path: "{{ at_target_directory }}/{{ item.key }}-{{ at_file_name }}/conf/server.xml"
regexp: "{{at_standard_ports.ssl_port }}"
replace: "{{ item.value.ssl_port }}"
loop: "{{ lookup('dict', demo_target_environment_vars) }}"
- name: copy tomcatusers
copy:
src: "{{ demo_source_directory }}/{{ demo_name }}/{{ at_tomcat_users_file }}"
dest: "{{ at_target_directory }}/{{ item.key}}-{{ at_file_name }}/conf"
loop: "{{ lookup('dict', demo_target_environment_vars) }}"
# create resource tree
#TODO: check first if exists... then create
- name: create top level resource
uri:
url: "https://{{ ucd_server_hostname }}:{{ install_server_web_https_port }}/cli/resource/create"
user: "{{ ucds_admin_user }}"
password: "{{ ucds_initial_admin_pwd }}"
method: PUT
body: ' { "name" : "{{ demo_name }}-Demo-Lab" }'
force_basic_auth: yes
body_format: json
validate_certs: no
# status_code: 204
- name: create environment level resource
uri:
url: "https://{{ ucd_server_hostname }}:{{ install_server_web_https_port }}/cli/resource/create"
user: "{{ ucds_admin_user }}"
password: "{{ ucds_initial_admin_pwd }}"
method: PUT
body: ' { "name" : "{{ item.key | upper}}" ,"parent" : "\/{{ demo_name }}-Demo-Lab" }'
force_basic_auth: yes
body_format: json
validate_certs: no
loop: "{{ lookup('dict', demo_target_environment_vars) }}"
- name: add agent to environment
uri:
url: "https://{{ ucd_server_hostname }}:{{ install_server_web_https_port }}/cli/resource/create"
user: "{{ ucds_admin_user }}"
password: "{{ ucds_initial_admin_pwd }}"
method: PUT
body: ' { "agent" : "{{ ucd_agent_name }}" ,"parent" : "\/{{ demo_name }}-Demo-Lab\/{{ item.key | upper}}" }'
force_basic_auth: yes
body_format: json
validate_certs: no
loop: "{{ lookup('dict', demo_target_environment_vars) }}"
#TODO: check if app exists if yes use update artifact setting if no just import with create
#BUG: Fails with 7.1.1 UCDS
# import application
- name: import JPetStore demo application
shell: 'curl -v -k -u "{{ ucds_admin_user }}:{{ ucds_initial_admin_pwd }}" -X POST -H "Content-Type: multipart/form-data" -F "file=@{{ demo_name }}.json" "https://{{ ucd_server_hostname }}:{{ install_server_web_https_port }}/rest/deploy/application/import?upgradeType=USE_EXISTING_IF_EXISTS&compTempUpgradeType=USE_EXISTING_IF_EXISTS&processUpgradeType=USE_EXISTING_IF_EXISTS&resourceTemplateUpgradeType=USE_EXISTING_IF_EXISTS&appTempUpgradeType=USE_EXISTING_IF_EXISTS"'
args:
chdir: "{{ demo_target_directory }}/{{ demo_name }}"
# import component versions
- name: import JPetStore component versions
uri:
url: "https://{{ ucd_server_hostname }}:{{ install_server_web_https_port }}/cli/component/integrate"
user: "{{ ucds_admin_user }}"
password: "{{ ucds_initial_admin_pwd }}"
method: PUT
body: ' { "component" : "{{ item }}" }'
force_basic_auth: yes
body_format: json
validate_certs: no
loop: "{{ demo_components }}"
- name: add components to agents
uri:
url: "https://{{ ucd_server_hostname }}:{{ install_server_web_https_port }}/cli/resource/create"
user: "{{ ucds_admin_user }}"
password: "{{ ucds_initial_admin_pwd }}"
method: PUT
body: ' { "component" : "{{ item[1] }}" ,"parent" : "\/{{ demo_name }}-Demo-Lab\/{{ item.0.key | upper}}\/{{ ucd_agent_name }}" }'
force_basic_auth: yes
body_format: json
validate_certs: no
with_nested:
- "{{ lookup('dict', demo_target_environment_vars) }}"
- "{{ demo_components }}"
- name: set JPetStore Firewalld settings
firewalld:
port: "{{ item.value.non_ssl_port }}/tcp"
permanent: yes
immediate: yes
state: enabled
loop: "{{ lookup('dict', demo_target_environment_vars) }}"
when: ansible_facts['os_family'] == "RedHat"
- name: set JPetStore UFW settings
firewalld:
port: "{{ item.value.non_ssl_port }}"
proto: tcp
rule: allow
state: enabled
loop: "{{ lookup('dict', demo_target_environment_vars) }}"
when: ansible_facts['os_family'] == "Ubuntu"