-
Notifications
You must be signed in to change notification settings - Fork 253
/
main.yml
249 lines (225 loc) · 10.2 KB
/
main.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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
---
- name: Load variables
include_vars: "{{ item }}"
with_first_found:
- files:
- "{{ ansible_os_family|lower }}-{{ ansible_distribution|lower }}-{{ ansible_distribution_major_version }}.yml"
- "{{ ansible_os_family|lower }}-{{ ansible_distribution|lower }}-{{ ansible_distribution_version }}.yml"
- "{{ ansible_os_family|lower }}-{{ ansible_distribution|lower }}.yml"
- "{{ ansible_os_family|lower }}-{{ ansible_distribution_major_version }}.yml"
- "{{ ansible_os_family|lower }}.yml"
- defaults.yml
paths:
- ../ambari-config/vars
- name: Set the GPL Licensed setting in Ambari
lineinfile:
path: /etc/ambari-server/conf/ambari.properties
backup: no
state: present
regexp: "^gpl.license.accepted.*"
line: "gpl.license.accepted={{ (accept_gpl|default(omit)|bool == true) | ternary('true', 'false') }}"
notify: Restart ambari-server
- name: Attempt to change the default Ambari admin password
uri:
url: http://{{ ansible_fqdn }}:8080/api/v1/users/admin
method: PUT
force_basic_auth: yes
user: "{{ ambari_admin_user }}"
password: "{{ ambari_admin_default_password }}"
headers: '{"X-Requested-By":"ambari"}'
body: " {\"Users\":{ \"password\":\"{{ ambari_admin_password }}\", \"old_password\":\"{{ ambari_admin_default_password }}\"}}"
body_format: raw
status_code: 200,201,202,403
return_content: no
when: ambari_admin_user == 'admin' and ambari_admin_password != ambari_admin_default_password
- block:
- name: Set the HDP Search mpack filename
set_fact:
mpack_filename: "solr-service-mpack-{{ hdpsearch_version }}.tar.gz"
- name: "Install the HDP Search Management Pack"
shell: "echo yes | ambari-server install-mpack --mpack={{ repo_base_url }}/HDP-SOLR/hdp-solr-ambari-mp/{{ mpack_filename }}"
notify: Restart ambari-server
args:
creates: "/var/lib/ambari-server/resources/mpacks/solr-ambari-mpack-{{ hdpsearch_version }}"
when: install_hdpsearch is defined and install_hdpsearch
- block:
- block:
- name: Attempt to read the HDF repo build.id file
uri:
url: "{{ hdf_main_repo_url }}/build.id"
method: GET
return_content: yes
register: hdf_repo_build_id
- name: Set the HDF build number
set_fact:
hdf_build_number_auto: "{{ (hdf_repo_build_id.content|from_yaml).BUILD_NUMBER }}"
when: hdf_build_number is not defined or hdf_build_number == 'auto'
- name: Set the HDF mpack filename
set_fact:
mpack_filename: "hdf-ambari-mpack-{{ hdf_version }}-{{ hdf_build_number_auto|default(hdf_build_number) }}.tar.gz"
- name: "Install the HDF Management Pack"
shell: "echo yes | ambari-server install-mpack --mpack={{ hdf_main_repo_url }}/tars/hdf_ambari_mp/{{ mpack_filename }}"
notify: Restart ambari-server
args:
creates: "/var/lib/ambari-server/resources/mpacks/{{ mpack_filename | regex_replace('.tar.gz$','') }}"
when: hdf_major_version|int >= 3
- name: "Install the HDF Management Pack (with --purge)"
shell: "echo yes | ambari-server install-mpack --mpack={{ hdf_main_repo_url }}/tars/hdf_ambari_mp/{{ mpack_filename }} --purge"
notify: Restart ambari-server
args:
creates: "/var/lib/ambari-server/resources/mpacks/{{ mpack_filename | regex_replace('.tar.gz$','') }}"
when: hdf_major_version|int < 3
- meta: flush_handlers
- name: "Modify the HDF base_url repository for HDF {{ hdf_minor_version }}"
uri:
url: http://{{ ansible_fqdn }}:8080/api/v1/stacks/HDF/versions/{{ hdf_minor_version }}/{{ main_os_target }}/repositories/HDF-{{ hdf_minor_version }}
method: PUT
force_basic_auth: yes
user: "{{ ambari_admin_user }}"
password: "{{ ambari_admin_password }}"
headers: '{"X-Requested-By":"ambari"}'
body: " {\"Repositories\" : { \"repo_name\": \"HDF\", \"base_url\" : \"{{ hdf_main_repo_url }}\", \"verify_base_url\": true } }"
body_format: raw
status_code: 200,201,202
return_content: no
when: ambari_version is version_compare('2.6', '<')
- name: Upload the HDF Version Definition file for HDF-only clusters (Ambari 2.6+)
template:
src: "{{ item }}"
dest: "/tmp/cluster_vdf.xml"
mode: 0640
force: yes
with_first_found:
- files:
- "vdf-HDF-{{ hdf_version }}.xml.j2"
- "vdf-HDF-{{ hdf_minor_version }}-latest.xml.j2"
- "vdf-HDF-{{ hdf_major_version }}-latest.xml.j2"
paths:
- ../templates
when: ambari_version is version_compare('2.6', '>=') and not install_hdp|default(false)
when: install_hdf is defined and install_hdf
- block:
- block:
- name: "Modify the HDP base_url repository for HDP {{ hdp_minor_version }}"
uri:
url: http://{{ ansible_fqdn }}:8080/api/v1/stacks/HDP/versions/{{ hdp_minor_version }}/{{ main_os_target }}/repositories/HDP-{{ hdp_minor_version }}
method: PUT
force_basic_auth: yes
user: "{{ ambari_admin_user }}"
password: "{{ ambari_admin_password }}"
headers: '{"X-Requested-By":"ambari"}'
body: " {\"Repositories\" : { \"repo_name\": \"HDP\", \"base_url\" : \"{{ hdp_main_repo_url }}\", \"verify_base_url\": true } }"
body_format: raw
status_code: 200,201,202
return_content: no
- name: "Modify the HDP-UTILS base_url repository for HDP {{ hdp_minor_version }}"
uri:
url: http://{{ ansible_fqdn }}:8080/api/v1/stacks/HDP/versions/{{ hdp_minor_version }}/{{ utils_os_target }}
method: PUT
force_basic_auth: yes
user: "{{ ambari_admin_user }}"
password: "{{ ambari_admin_password }}"
headers: '{"X-Requested-By":"ambari"}'
body: " {\"Repositories\" : { \"repo_name\": \"HDP\", \"base_url\" : \"{{ utils_repo_url }}\", \"verify_base_url\": true } }"
body_format: raw
status_code: 200,201,202
return_content: no
when: ambari_version is version_compare('2.6', '<')
- block:
- block:
- name: Attempt to read the HDP repo build.id file (Ambari >= 2.6)
uri:
url: "{{ hdp_main_repo_url }}/build.id"
method: GET
return_content: yes
register: hdp_repo_build_id
- name: Set the HDP build number (Ambari >= 2.6)
set_fact:
hdp_build_number_auto: "{{ (hdp_repo_build_id.content|from_yaml).BUILD_NUMBER }}"
when: hdp_build_number is not defined or hdp_build_number == 'auto'
- name: Upload the HDP Version Definition file (Ambari >= 2.6)
template:
src: "{{ item }}"
dest: "/tmp/cluster_vdf.xml"
mode: 0640
force: yes
with_first_found:
- files:
- "vdf-HDP-{{ hdp_version }}.xml.j2"
- "vdf-HDP-{{ hdp_minor_version }}-latest.xml.j2"
- "vdf-HDP-{{ hdp_major_version }}-latest.xml.j2"
paths:
- ../templates
when: ambari_version is version_compare('2.6', '>=')
- name: Enable User Home Directory Creation
lineinfile:
path: /etc/ambari-server/conf/ambari.properties
state: present
line: "{{ item }}"
notify: Restart ambari-server
with_items:
- "ambari.post.user.creation.hook.enabled=true"
- "ambari.post.user.creation.hook=/var/lib/ambari-server/resources/scripts/post-user-creation-hook.sh"
when: install_hdp is defined and install_hdp
- block:
- name: Attempt to get an existing VDF for the required version (Ambari >= 2.6)
uri:
url: "http://{{ ansible_fqdn }}:8080/api/v1/version_definitions?VersionDefinition/release/version={{ (install_hdp|default(false) == true) | ternary(hdp_version,hdf_version) }}"
method: GET
force_basic_auth: yes
user: "{{ ambari_admin_user }}"
password: "{{ ambari_admin_password }}"
headers: '{"X-Requested-By":"ambari"}'
status_code: 200,201,202
return_content: yes
register: existing_vdf
- name: Register the VDF with Ambari (Ambari >= 2.6)
uri:
url: http://{{ ansible_fqdn }}:8080/api/v1/version_definitions
method: POST
force_basic_auth: yes
user: "{{ ambari_admin_user }}"
password: "{{ ambari_admin_password }}"
headers: '{"X-Requested-By":"ambari"}'
body: " {\"VersionDefinition\":{ \"version_url\":\"file:/tmp/cluster_vdf.xml\"}}"
body_format: raw
status_code: 200,201,202
return_content: no
when: (existing_vdf.content|from_yaml)['items'] | length == 0
when: ambari_version is version_compare('2.6', '>=')
- block:
- name: Generate repo_version API request body from template
template:
src: "{{ repo_version_template | default('repo_version_template.json.j2') }}"
dest: /tmp/repo_version_update_body.json
become: False
delegate_to: localhost
- name: Update repo_version model to set ambari_managed_repositories=false
uri:
url: "http://{{ ansible_fqdn }}:8080/api/v1/stacks/HDP/versions/{{ hdp_minor_version }}/repository_versions/1"
method: PUT
force_basic_auth: yes
user: "{{ ambari_admin_user }}"
password: "{{ ambari_admin_password }}"
headers:
"X-Requested-By": "ambari"
"Content-type": "Application/json"
body: "{{ lookup('file', '/tmp/repo_version_update_body.json')|to_json }}"
status_code: 200
when: not (ambari_managed_repositories|default(True))
- meta: flush_handlers
- name: Make sure all of the Ambari Agents have registered
uri:
url: http://{{ ansible_fqdn }}:8080/api/v1/hosts/{{ hostvars[item]['ansible_fqdn']|lower }}
method: GET
force_basic_auth: yes
user: "{{ ambari_admin_user }}"
password: "{{ ambari_admin_password }}"
headers: '{"X-Requested-By":"ambari"}'
status_code: 200,201,202,404
return_content: no
with_items: "{{ groups['hadoop-cluster'] }}"
register: result
until: "result.status != 404"
retries: 100
delay: 5