-
Notifications
You must be signed in to change notification settings - Fork 0
/
WIN2022_provisioning.yml
2390 lines (1945 loc) · 108 KB
/
WIN2022_provisioning.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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
---
# Performing automated Windows Server 2022 installation on on HPE Compute Ops Managmeent server(s) using an auto-generated ISO file with customized unattend file.
#
# Command that can be used to run this playbook:
#
# $ ansible-playbook -i hosts_WIN WIN2022_provisioning.yml --ask-vault-password --ask-become-pass
#
# Note: Make sure to provide the list of servers to be provisioned with their details in the inventory file 'hosts_WIN'
#
#----------------------------------------------------------------------------------------------------------------------------------------------------------------------
#-------------------------------------- Bare Metal Provisioning -------------------------------------------------------------------------------------------------------
- name: Automated Windows Server 2022 installation on HPE Compute Ops Managmeent server(s) using an auto-generated ISO file with customized unattend file
hosts: WIN2022
gather_facts: no
vars_files:
- vars/GLP_COM_API_credentials_encrypted.yml
vars:
inventory_fqdn: "{{ inventory_hostname | lower }}.{{ domain }}"
ansible_host_key_checking: false
validate_certs: false
user: "{{ lookup('env', 'USER') }}"
ssh_known_hosts_file: "{{ lookup('env','HOME') + '/.ssh/known_hosts' }}"
ansible_ssh_public_key: "{{ lookup('file', '~/.ssh/id_rsa.pub') }}"
ansible_forks: 5
tasks:
#--------------------------------------Capture start time--------------------------------------------------------------------------------------------------------------
- name: Gather subset facts on localhost
setup:
gather_subset: [all]
delegate_to: localhost
- name: Capture the start time (will be used later to filter COM activities and get the runtime of the playbook)
set_fact:
start_time: "{{ ansible_date_time.iso8601 }}"
# yesterday_date: "{{ '%Y-%m-%dT%H:%M:%SZ' | strftime(ansible_date_time.epoch | int - (24 * 3600)) }}"
- debug: var=start_time
#--------------------------------------Authentication with COM---------------------------------------------------------------------------------------------------------
- name: Create HPE Compute Ops Management session
import_tasks: files/Create_COM_session.yml
#--------------------------------------Capture COM resource API versions ----------------------- ----------------------------------------------------------------------
- name: Capture Resource API versions
import_tasks: files/Get_resource_API_versions.yml
#--------------------------------------Capture Job Templates Resource Uri-----------------------------------------------------------------------------------------------
- name: Capture Job Templates ResourceUri
import_tasks: files/Get_job_templates_resourceuri.yml
#--------------------------------------Capture server information -----------------------------------------------------------------------------------------------------
- name: Capture server '{{ serial_number }}' information
uri:
url: "{{ ConnectivityEndpoint }}/compute-ops-mgmt/{{ servers_API_version }}/servers?filter=hardware/serialNumber%20eq%20'{{ serial_number }}'"
method: GET
headers:
Authorization: "Bearer {{ access_token }}"
register: server
delegate_to: localhost
# - debug: var=server
- name: Exit if server '{{ serial_number }}' does not exist
fail:
msg: "Server '{{ serial_number }}' does not exist!"
when: server.json.count == 0
- name: Capture server '{{ serial_number }}' generation, id, uri, connection status and iLO IP
set_fact:
server_generation: "{{ server | json_query('json.items[0].serverGeneration') }}"
server_id: "{{ server | json_query('json.items[0].id') }}"
server_resourceUri: "{{ server | json_query('json.items[0].resourceUri') }}"
server_connected_status: "{{ server | json_query('json.items[0].state.connected') }}"
server_ilo_ip: "{{ server | json_query('json.items[0].hardware.bmc.ip') }}"
- debug:
msg:
- "Generation: {{ server_generation }}"
- "ID: {{ server_id }}"
- "URI: {{ server_resourceUri }}"
- "Connection status: {{ server_connected_status }}"
- "iLO IP: {{ server_ilo_ip }}"
- name: Exit if server '{{ serial_number }}' is not connected to COM
fail:
msg:
- "Server '{{ serial_number }}' is not connected to COM!"
- "Make sure to connect the server's iLO to COM ! Go to iLO UI / Management / Compute Ops Management"
when: server_connected_status == false
- name: Wait until the server '{{ serial_number }}' raw inventory information is available (necessary when the server has recently been added to COM) then capture the data
uri:
url: "{{ ConnectivityEndpoint }}/compute-ops-mgmt/{{ servers_API_version }}/servers/{{ server_id }}/raw-inventory"
method: GET
headers:
Authorization: "Bearer {{ access_token }}"
register: server_raw_inventory
failed_when: server_raw_inventory.status != 200 and server_raw_inventory.status != 404
until: server_raw_inventory.status == 200
retries: 30
delay: 60
delegate_to: localhost
- name: Wait until the complete discovery of server '{{ serial_number }}' is complete (necessary when the server has recently been added to COM).
uri:
url: "{{ ConnectivityEndpoint }}/ui-doorway/compute/v2/servers/{{ server_id }}"
method: GET
return_content: yes
status_code: 200
headers:
Authorization: "Bearer {{ access_token }}"
register: server_inventory_from_ui_doorway
until: server_inventory_from_ui_doorway.json.state_ != "Retrieving server information in progress"
retries: 30
delay: 60
delegate_to: localhost
#--------------------------------------Check BIOS/Workload profile settings -------------------------------------------------------------------------------------------
# BIOS/Workload profiles are predefined by HPE, so there's no need to create/update them, just check that they exist.
- name: Check if workload profile '{{ workload_profile_name }}' exists
uri:
url: "{{ ConnectivityEndpoint }}/compute-ops-mgmt/{{ server_settings_API_version }}/server-settings?filter={{ filter | urlencode }}"
method: GET
headers:
Authorization: "Bearer {{ access_token }}"
vars:
filter: "category eq 'BIOS' and name eq '{{ workload_profile_name }}'"
register: bios_server_setting
delegate_to: localhost
# - debug: var=bios_server_setting
- name: Exit if workload profile '{{ workload_profile_name }}' does not exist
fail:
msg: "Workload profile '{{ workload_profile_name }}' does not exist!"
when: bios_server_setting.json.count == 0
- name: Set a variable for the resourceUri of workload profile '{{ workload_profile_name }}'
set_fact:
bios_server_setting_resourceuri: "{{ bios_server_setting | json_query('json.items[0].resourceUri') }}"
# - debug: var=bios_server_setting_resourceuri
#--------------------------------------Create internal storage settings -----------------------------------------------------------------------------------------------
- name: Wait until PCI devices information is available then capture the server '{{ serial_number }}' raw inventory information
uri:
url: "{{ ConnectivityEndpoint }}/compute-ops-mgmt/{{ servers_API_version }}/servers/{{ server_id }}/raw-inventory"
method: GET
headers:
Authorization: "Bearer {{ access_token }}"
register: server_raw_inventory
# until: (server_raw_inventory.json.pciDevices | length>0)
until: server_raw_inventory.json.pciDevices is defined and server_raw_inventory.json.pciDevices is not none
retries: 30
delay: 60
delegate_to: localhost
# Run a server inventory job to collect the local storage information
- name: Run a server inventory job to collect the local storage information
uri:
url: "{{ ConnectivityEndpoint }}/compute-ops-mgmt/{{ jobs_API_version }}/jobs"
method: POST
status_code: 200
headers:
Authorization: "Bearer {{ access_token }}"
Content-Type: "application/json"
body_format: json
body:
resourceUri: "{{ server_resourceUri }}"
jobTemplateUri: "{{ GetFullServerInventory_job_template_resourceUri }}"
data:
is_reports_call: true
filters:
- localStorageV2
register: inventory_job_result
delegate_to: localhost
# - debug: var=inventory_job_result
- name: Set a variable for the job resource URI
set_fact:
job_resourceUri: "{{ inventory_job_result.json.resourceUri }}"
# - debug: var=job_resourceUri
- name: Wait for the server inventory job to complete
uri:
url: "{{ ConnectivityEndpoint }}{{ job_resourceUri }}"
method: GET
return_content: yes
headers:
Authorization: "Bearer {{ access_token }}"
retries: 60
delay: 5
until: >
(server_inventory_job_status.json.state == "COMPLETE" or
server_inventory_job_status.json.state == "ERROR")
register: server_inventory_job_status
delegate_to: localhost
# - debug: var=server_inventory_job_status
- name: Display the server inventory job result
debug:
msg:
- "State: {{ server_inventory_job_status.json.state }}"
- "ResultCode: {{ server_inventory_job_status.json.resultCode }}"
- "Status: {{ server_inventory_job_status.json.status }}"
- name: Exit when server inventory job is failing
fail:
msg: "Error ! Server inventory job to collect the local storage information has failed !"
when: server_inventory_job_status.json.state == "ERROR"
- name: Capture the server '{{ serial_number }}' raw inventory information
uri:
url: "{{ ConnectivityEndpoint }}/compute-ops-mgmt/{{ servers_API_version }}/servers/{{ server_id }}/raw-inventory"
method: GET
headers:
Authorization: "Bearer {{ access_token }}"
register: server_raw_inventory
delegate_to: localhost
# - debug: var=server_raw_inventory
# Is the server equipped with an NVMe NS204i boot controller?
- name: Capture the presence of a NS204i NVMe boot controller in server '{{ serial_number }}'
set_fact:
NS204i_data: "{{ matched_item }}"
vars:
matched_item: "{{ item }}"
loop: "{{ server_raw_inventory.json.storageInventory.LocalStorageV2 }}"
loop_control:
label: never
when: item.Name is search('NS204i')
# - debug: var=NS204i_data
- debug:
msg: "NS204i found in server '{{ serial_number }}'! NVMe RAID1 volume will be used as the target volume for the installation of Windows!"
when: NS204i_data is defined
- debug:
msg: "No NS204i found in server '{{ serial_number }}'! Let's check if a storage controller with drives is available..."
when: NS204i_data is undefined
# - debug: var=server_raw_inventory.json.storageInventory
- name: Capture size of the NS204i RAID1 volume if any
set_fact:
boot_drive_bytes_size: "{{ matched_item }}"
vars:
matched_item: "{{ item.Volumes[0].CapacityBytes }}"
loop: "{{ server_raw_inventory.json.storageInventory.LocalStorageV2 }}"
loop_control:
label: never
when: NS204i_data is defined and item.Name is search('NS204i')
- debug:
msg: "Size of NS204i volume: {{ ((boot_drive_bytes_size | int) / (1024 ** 3)) | round(1) }} GB"
when: NS204i_data is defined
# No NS204i but is the server equipped with an HPE MR or SR controller and with drives available?
- name: Capture storage RAID controller information when an HPE MR or SR controller is used with available drives
set_fact:
SR_MR_storage_controller_data: "{{ matched_item }}"
vars:
matched_item: "{{ item }}"
loop: "{{ server_raw_inventory.json.storageInventory.LocalStorageV2 }}"
loop_control:
label: never
when: NS204i_data is undefined and item.Drives | length > 0 and (item.Name is search('HPE MR') or item.Name is search('HPE SR'))
# - debug: var=SR_MR_storage_controller_data
- name: Set a variable for the name of the storage RAID controller found
set_fact:
storage_controller_name: "{{ SR_MR_storage_controller_data.Name }}"
when: NS204i_data is undefined and SR_MR_storage_controller_data is defined
- debug:
msg: "Storage RAID controller found: '{{ storage_controller_name }}' with '{{ SR_MR_storage_controller_data.Drives | length }}' drives"
when: NS204i_data is undefined and SR_MR_storage_controller_data is defined
# Retrieve storage controller data when no NS204i and no SR/MR controller with disk available found
- name: Set controller type if disk found and when no NS204i and no SR/MR controller with disk available found
set_fact:
no_NS204i_no_SR_MR_but_local_disk: "{{ matched_item }}"
vars:
matched_item: "{{ item }}"
loop: "{{ server_raw_inventory.json.storageInventory.LocalStorageV2 }}"
loop_control:
label: never
when: NS204i_data is undefined and SR_MR_storage_controller_data is undefined and item.Drives | length > 0
# - debug: var=no_NS204i_no_SR_MR_but_local_disk
- name: Exit when no NS204i and no SR/MR controller and no other controller with disks are found
fail:
msg: "Error ! No controller found with disk available !"
when: NS204i_data is undefined and SR_MR_storage_controller_data is undefined and no_NS204i_no_SR_MR_but_local_disk is undefined
- name: Set a variable for the name of the storage controller found
set_fact:
storage_controller_name: "{{ no_NS204i_no_SR_MR_but_local_disk.Name }}"
when: NS204i_data is undefined and SR_MR_storage_controller_data is undefined
- debug:
msg: "Storage controller found: '{{ storage_controller_name }}' with '{{ no_NS204i_no_SR_MR_but_local_disk.Drives | length }}' drives"
when: NS204i_data is undefined and SR_MR_storage_controller_data is undefined
# Set controller type name for kickstart creation
- name: Set controller type when no NS204i and no SR/MR controller with disk available found
set_fact:
Controller_type: "Local"
when: NS204i_data is undefined and SR_MR_storage_controller_data is undefined and no_NS204i_no_SR_MR_but_local_disk is defined
- name: Set a controller type variable for kickstart creation when an NS204i is present
set_fact:
Controller_type: "NS204i"
when: NS204i_data is defined
- name: Set a controller type variable for kickstart creation when there is no NS204i but an SR/MR controller is present.
set_fact:
Controller_type: "{{ storage_controller_name }}"
when: NS204i_data is undefined and SR_MR_storage_controller_data is defined
- debug:
msg: "Controller type found that will be used by autounattend.xml: {{ Controller_type }}"
# Server settings for internal storage RAID configuration (creation or modification)
- name: Check if server settings '{{ raid_type }}' already exist
uri:
url: "{{ ConnectivityEndpoint }}/compute-ops-mgmt/{{ server_settings_API_version }}/server-settings?filter={{ filter | urlencode }}"
method: GET
headers:
Authorization: "Bearer {{ access_token }}"
vars:
filter: "name eq '{{ raid_type }}'"
register: internal_storage_server_setting
when: NS204i_data is undefined and SR_MR_storage_controller_data is defined
delegate_to: localhost
# - debug: var=internal_storage_server_setting
# Need to create an internal storage RAID configuration if there is no NS204i but there is a storage controller
- name: Create internal storage configuration using '{{ raid_type }}' with a volume size of '{{ volume_size_in_GB }}' GB for the OS boot volume when it does not exist
uri:
url: "{{ ConnectivityEndpoint }}/compute-ops-mgmt/{{ server_settings_API_version }}/server-settings"
method: POST
status_code: 201
headers:
Authorization: "Bearer {{ access_token }}"
Content-Type: "application/json"
body_format: json
body:
name: "{{ raid_type }}"
description: "Local storage settings using {{ raid_type }} for OS"
platformFamily: "Any"
category: "STORAGE"
settings:
DEFAULT:
raidType: "{{ raid_type }}"
volumeSizeInGB: "{{ volume_size_in_GB }}"
register: internal_storage_server_setting_result
delegate_to: localhost
when: NS204i_data is undefined and SR_MR_storage_controller_data is defined and internal_storage_server_setting.json.count == 0
- name: Result of the '{{ raid_type }}' creation task
debug: var=internal_storage_server_setting_result
when: NS204i_data is undefined and SR_MR_storage_controller_data is defined and internal_storage_server_setting.json.count == 0
- name: Set a variable for the resourceUri of the internal storage configuration '{{ raid_type }}' just created
set_fact:
internal_storage_server_setting_resourceuri: "{{ internal_storage_server_setting_result.json.resourceUri }}"
when: NS204i_data is undefined and SR_MR_storage_controller_data is defined and internal_storage_server_setting.json.count == 0
- name: Update internal storage configuration using '{{ raid_type }}' with a volume size of '{{ volume_size_in_GB }}' GB for the OS boot volume
uri:
url: "{{ ConnectivityEndpoint }}/compute-ops-mgmt/{{ server_settings_API_version }}/server-settings/{{ internal_storage_server_setting_id }}"
method: PATCH
status_code: 200
headers:
Authorization: "Bearer {{ access_token }}"
Content-Type: "application/merge-patch+json"
body_format: json
body:
name: "{{ raid_type }}"
description: "Local storage settings using {{ raid_type }} for OS"
platformFamily: "Any"
category: "STORAGE"
settings:
DEFAULT:
raidType: "{{ raid_type }}"
volumeSizeInGB: "{{ volume_size_in_GB }}"
vars:
internal_storage_server_setting_id: "{{ internal_storage_server_setting | json_query('json.items[0].id') }}"
register: internal_storage_server_setting_result
delegate_to: localhost
when: NS204i_data is undefined and SR_MR_storage_controller_data is defined and internal_storage_server_setting.json.count == 1
- name: Result of the '{{ raid_type }}' update task
debug: var=internal_storage_server_setting_result.msg
when: NS204i_data is undefined and SR_MR_storage_controller_data is defined and internal_storage_server_setting.json.count == 1
- name: Set a variable for the resourceUri of the internal storage configuration '{{ raid_type }}' just updated
set_fact:
internal_storage_server_setting_resourceuri: "{{ internal_storage_server_setting | json_query('json.items[0].resourceUri') }}"
when: NS204i_data is undefined and SR_MR_storage_controller_data is defined and internal_storage_server_setting.json.count == 1
- debug: var=internal_storage_server_setting_resourceuri
when: NS204i_data is undefined and SR_MR_storage_controller_data is defined
#--------------------------------------Create temporary server group with server settings -----------------------------------------------------------------------------
# Create a temporary group name from hostname + _server_group
- name: Create server group name '{{ inventory_hostname }}_server_group' variable
set_fact:
temporary_server_group_name: "{{ inventory_hostname }}_server_group"
# Group is created or modified based on whether this particular resource is present or not
- name: Check if group '{{ temporary_server_group_name }}' already exists
uri:
url: "{{ ConnectivityEndpoint }}/compute-ops-mgmt/{{ groups_API_version }}/groups?filter={{ filter | urlencode }}"
method: GET
headers:
Authorization: "Bearer {{ access_token }}"
vars:
filter: "name eq '{{ temporary_server_group_name }}'"
register: temporary_server_group
delegate_to: localhost
# - debug: var=temporary_server_group
# Server group creation or modification when NS204i is found or when no_NS204i_no_SR_MR_but_local_disk => no local storage configuration definition
- name: Create temporary group '{{ temporary_server_group_name }}' with no local storage configuration definition (if it does not exist)
uri:
url: "{{ ConnectivityEndpoint }}/compute-ops-mgmt/{{ groups_API_version }}/groups"
method: POST
status_code: 201
headers:
Authorization: "Bearer {{ access_token }}"
Content-Type: "application/json"
body_format: json
body:
name: "{{ temporary_server_group_name }}"
description: "Temporary server group for Windows Server installation on server '{{ inventory_hostname }}'"
serverSettingsUris:
- "{{ bios_server_setting_resourceuri }}"
serverPolicies:
onServerAdd:
firmwareUpdate: false
biosApplySettings: true
storageConfiguration: false
storageVolumeDeletion: false
storageVolumeName: ""
osInstall: false
onSettingsApply:
firmwareDowngrade: false
# autoAddServerTags:
register: server_group_result
when: (NS204i_data is defined or no_NS204i_no_SR_MR_but_local_disk is defined) and temporary_server_group.json.count == 0
delegate_to: localhost
- name: Display response of the temporary group '{{ temporary_server_group_name }}' creation request
debug: var=server_group_result.msg
when: (NS204i_data is defined or no_NS204i_no_SR_MR_but_local_disk is defined) and temporary_server_group.json.count == 0
- name: Set variables for the id and the resourceUri of temporary group '{{ temporary_server_group_name }}' just created
set_fact:
temporary_group_id: "{{ server_group_result.json.id }}"
temporary_group_resourceuri: "{{ server_group_result.json.resourceUri }}"
when: (NS204i_data is defined or no_NS204i_no_SR_MR_but_local_disk is defined) and temporary_server_group.json.count == 0
- name: Update temporary group '{{ temporary_server_group_name }}' with no local storage configuration definition (if it does exist)
uri:
url: "{{ ConnectivityEndpoint }}/compute-ops-mgmt/{{ groups_API_version }}/groups/{{ group_id }}"
method: PATCH
status_code: 200
headers:
Authorization: "Bearer {{ access_token }}"
Content-Type: "application/merge-patch+json"
body_format: json
body:
name: "{{ temporary_server_group_name }}"
description: "Temporary server group for Windows Server installation on server '{{ inventory_hostname }}'"
serverSettingsUris:
- "{{ bios_server_setting_resourceuri }}"
serverPolicies:
onServerAdd:
firmwareUpdate: false
biosApplySettings: true
storageConfiguration: false
storageVolumeDeletion: false
storageVolumeName: ""
osInstall: false
onSettingsApply:
firmwareDowngrade: false
# autoAddServerTags:
vars:
group_id: "{{ temporary_server_group | json_query('json.items[0].id') }}"
register: server_group_result
when: (NS204i_data is defined or no_NS204i_no_SR_MR_but_local_disk is defined) and temporary_server_group.json.count == 1
delegate_to: localhost
- name: Display response of the temporary group '{{ temporary_server_group_name }}' update request
debug: var=server_group_result.msg
when: (NS204i_data is defined or no_NS204i_no_SR_MR_but_local_disk is defined) and temporary_server_group.json.count == 1
- name: Set variables for the id and the resourceUri of temporary group '{{ temporary_server_group_name }}' just updated
set_fact:
temporary_group_id: "{{ temporary_server_group | json_query('json.items[0].id') }}"
temporary_group_resourceuri: "{{ temporary_server_group | json_query('json.items[0].resourceUri') }}"
when: (NS204i_data is defined or no_NS204i_no_SR_MR_but_local_disk is defined) and temporary_server_group.json.count == 1
# Server group creation or modification when NS204i is not found but storage controller is found => with local storage RAID configuration definition
- name: Create temporary group '{{ temporary_server_group_name }}' with local storage configuration definition (if it does not exist)
uri:
url: "{{ ConnectivityEndpoint }}/compute-ops-mgmt/{{ groups_API_version }}/groups"
method: POST
status_code: 201
headers:
Authorization: "Bearer {{ access_token }}"
Content-Type: "application/json"
body_format: json
body:
name: "{{ temporary_server_group_name }}"
description: "Temporary server group for Windows Server installation on server '{{ inventory_hostname }}'"
serverSettingsUris:
- "{{ bios_server_setting_resourceuri }}"
- "{{ internal_storage_server_setting_resourceuri }}"
serverPolicies:
onServerAdd:
firmwareUpdate: false
biosApplySettings: true
storageConfiguration: true
storageVolumeDeletion: true
storageVolumeName: "OS_boot_volume"
osInstall: false
onSettingsApply:
firmwareDowngrade: false
# autoAddServerTags:
register: server_group_result
when: NS204i_data is undefined and SR_MR_storage_controller_data is defined and temporary_server_group.json.count == 0
delegate_to: localhost
- name: Display response of the temporary group '{{ temporary_server_group_name }}' creation request
debug: var=server_group_result.msg
when: NS204i_data is undefined and SR_MR_storage_controller_data is defined and temporary_server_group.json.count == 0
- name: Set variables for the id and the resourceUri of temporary group '{{ temporary_server_group_name }}' just created
set_fact:
temporary_group_id: "{{ server_group_result.json.id }}"
temporary_group_resourceuri: "{{ server_group_result.json.resourceUri }}"
when: NS204i_data is undefined and SR_MR_storage_controller_data is defined and temporary_server_group.json.count == 0
- name: Update temporary group '{{ temporary_server_group_name }}' with local storage configuration definition (if it does exist)
uri:
url: "{{ ConnectivityEndpoint }}/compute-ops-mgmt/{{ groups_API_version }}/groups/{{ group_id }}"
method: PATCH
status_code: 200
headers:
Authorization: "Bearer {{ access_token }}"
Content-Type: "application/merge-patch+json"
body_format: json
body:
name: "{{ temporary_server_group_name }}"
description: "Temporary server group for Windows Server installation on server '{{ inventory_hostname }}'"
serverSettingsUris:
- "{{ bios_server_setting_resourceuri }}"
- "{{ internal_storage_server_setting_resourceuri }}"
serverPolicies:
onServerAdd:
firmwareUpdate: false
biosApplySettings: true
storageConfiguration: true
storageVolumeDeletion: true
storageVolumeName: "OS_boot_volume"
osInstall: false
onSettingsApply:
firmwareDowngrade: false
# autoAddServerTags:
vars:
group_id: "{{ temporary_server_group | json_query('json.items[0].id') }}"
register: server_group_result
when: NS204i_data is undefined and SR_MR_storage_controller_data is defined and temporary_server_group.json.count == 1
delegate_to: localhost
- name: Display response of the temporary group '{{ temporary_server_group_name }}' update request
debug: var=server_group_result.msg
when: NS204i_data is undefined and SR_MR_storage_controller_data is defined and temporary_server_group.json.count == 1
- name: Set variables for the id and the resourceUri of temporary group '{{ temporary_server_group_name }}' just updated
set_fact:
temporary_group_id: "{{ temporary_server_group | json_query('json.items[0].id') }}"
temporary_group_resourceuri: "{{ temporary_server_group | json_query('json.items[0].resourceUri') }}"
when: NS204i_data is undefined and SR_MR_storage_controller_data is defined and temporary_server_group.json.count == 1
- debug: var=temporary_group_id
- debug: var=temporary_group_resourceuri
#--------------------------------------Add server to temporary server group for server configuration ------------------------------------------------------------------
- name: Check if server '{{ serial_number }}' is already member of a server group
uri:
url: "{{ ConnectivityEndpoint }}/ui-doorway/compute/v2/servers/{{ server_id }}"
method: GET
status_code: 200
headers:
Authorization: "Bearer {{ access_token }}"
register: server_info_from_ui_doorway
delegate_to: localhost
# - debug: var=server_info_from_ui_doorway
- debug: var=server_info_from_ui_doorway.json.group_
when: server_info_from_ui_doorway.json.group_ is defined
- name: Capture the id of the server group of which the server '{{ serial_number }}' is a member (if applicable)
set_fact:
server_group_id_found: "{{ server_info_from_ui_doorway.json.group_.id }}"
server_group_name_found: "{{ server_info_from_ui_doorway.json.group_.name }}"
when: server_info_from_ui_doorway.json.group_ is not none and server_info_from_ui_doorway.json.group_ is defined
- debug: var=server_group_name_found
when: server_info_from_ui_doorway.json.group_ is not none and server_info_from_ui_doorway.json.group_ is defined
- name: Remove server '{{ serial_number }}' from the server group of which it is currently a member
uri:
url: "{{ ConnectivityEndpoint }}/compute-ops-mgmt/{{ groups_API_version }}/groups/{{ server_group_id_found }}/devices/{{ server_id }}"
method: DELETE
status_code: 204
headers:
Authorization: "Bearer {{ access_token }}"
when: server_info_from_ui_doorway.json.group_ is not none and server_info_from_ui_doorway.json.group_ is defined
register: group_unassignment_result
delegate_to: localhost
- name: Wait for deletion to complete
pause:
seconds: 15
when: server_info_from_ui_doorway.json.group_ is not none and server_info_from_ui_doorway.json.group_ is defined
# Add server to the temporary server group
- name: Assign server '{{ serial_number }}' to temporary group '{{ temporary_server_group_name }}'
uri:
url: "{{ ConnectivityEndpoint }}/compute-ops-mgmt/{{ groups_API_version }}/groups/{{ temporary_group_id }}/devices"
method: POST
headers:
Authorization: "Bearer {{ access_token }}"
Content-Type: "application/json"
body_format: json
body:
devices:
# Only servers that are not part of a group can be assigned to a group.
- serverId: "{{ server_id }}"
register: group_assignment_result
delegate_to: localhost
- name: Display response of the group assignment task
debug: var=group_assignment_result.msg
#--------------------------------------Monitor the server configuration status ----------------------------------------------------------------------------------------
# Wait for the server configuration to complete
- name: Display the url that will be used to monitor the server configuration activity task
debug:
msg: "{{ ConnectivityEndpoint }}/compute-ops-mgmt/{{ activities_API_version }}/activities?filter=associatedServerId eq '{{ server_id }}' and createdAt gt {{ start_time }}"
- name: Wait for the configuration of server '{{ serial_number }}' to complete
uri:
url: "{{ ConnectivityEndpoint }}/compute-ops-mgmt/{{ activities_API_version }}/activities?filter={{ filter | urlencode }}"
method: GET
headers:
Authorization: "Bearer {{ access_token }}"
vars:
filter: "associatedServerId eq '{{ server_id }}' and createdAt gt {{ start_time }}"
query: "json.items[? name=='Server automatic configuration' && (contains(message,'Automatic configuration of server is complete') || contains(message,'failed'))]"
register: server_activities
until: server_activities | json_query(query)
retries: 30
delay: 60
delegate_to: localhost
- name: Exit if configuration of server '{{ serial_number }}' failed to complete
fail:
msg: "The configuration of server '{{ serial_number }}' failed to complete! Refer to the individual server activity entries in GLCP UI for details."
vars:
query: "json.items[? name=='Server automatic configuration' && contains(message,'failed')]"
when: server_activities | json_query(query)
# Run a server inventory job to collect the local storage information
- name: Run a server inventory job to collect the local storage information
uri:
url: "{{ ConnectivityEndpoint }}/compute-ops-mgmt/{{ jobs_API_version }}/jobs"
method: POST
status_code: 200
headers:
Authorization: "Bearer {{ access_token }}"
Content-Type: "application/json"
body_format: json
body:
resourceUri: "{{ server_resourceUri }}"
jobTemplateUri: "{{ GetFullServerInventory_job_template_resourceUri }}"
data:
is_reports_call: true
filters:
- localStorageV2
register: inventory_job_result
delegate_to: localhost
# - debug: var=inventory_job_result
- name: Set a variable for the job resource URI
set_fact:
job_resourceUri: "{{ inventory_job_result.json.resourceUri }}"
# - debug: var=job_resourceUri
- name: Wait for the server inventory job to complete
uri:
url: "{{ ConnectivityEndpoint }}{{ job_resourceUri }}"
method: GET
return_content: yes
headers:
Authorization: "Bearer {{ access_token }}"
retries: 60
delay: 5
until: >
(server_inventory_job_status.json.state == "COMPLETE" or
server_inventory_job_status.json.state == "ERROR")
register: server_inventory_job_status
delegate_to: localhost
# - debug: var=server_inventory_job_status
- name: Display the server inventory job result
debug:
msg:
- "State: {{ server_inventory_job_status.json.state }}"
- "ResultCode: {{ server_inventory_job_status.json.resultCode }}"
- "Status: {{ server_inventory_job_status.json.status }}"
- name: Exit when server inventory job is failing
fail:
msg: "Error ! Server inventory job to collect the local storage information has failed !"
when: server_inventory_job_status.json.state == "ERROR"
# Capture the size of the volume created once the server configuration is complete only when NS204i is not found with Storage RAID controller
- name: Capture server '{{ serial_number }}' raw inventory information
uri:
url: "{{ ConnectivityEndpoint }}/compute-ops-mgmt/{{ servers_API_version }}/servers/{{ server_id }}/raw-inventory"
method: GET
headers:
Authorization: "Bearer {{ access_token }}"
register: server_raw_inventory
delegate_to: localhost
when: NS204i_data is undefined and SR_MR_storage_controller_data is defined
# - debug: var=server_raw_inventory
- name: Capture storage RAID controller information when an HPE MR or SR controller is used with available drives
set_fact:
SR_MR_storage_controller_data: "{{ matched_item }}"
vars:
matched_item: "{{ item }}"
loop: "{{ server_raw_inventory.json.storageInventory.LocalStorageV2 }}"
loop_control:
label: never
when: NS204i_data is undefined and SR_MR_storage_controller_data is defined and item.Name == storage_controller_name
- name: Capture the size of the OS volume configured on the {{ storage_controller_name }}
set_fact:
boot_drive_bytes_size: "{{ (SR_MR_storage_controller_data | json_query(query))[0] }}"
vars:
query: "Volumes[?Name=='OS_boot_volume'].CapacityBytes"
when: NS204i_data is undefined and SR_MR_storage_controller_data is defined
- debug: var=boot_drive_bytes_size
when: NS204i_data is undefined and SR_MR_storage_controller_data is defined
- name: Set the size of the OS volume as '0' with local disk
set_fact:
boot_drive_bytes_size: "0"
when: no_NS204i_no_SR_MR_but_local_disk is defined
- debug:
msg: "Size of RAID volume: {{ ((boot_drive_bytes_size | int) / (1024 ** 3)) | round(1) }} GB"
when: NS204i_data is undefined and SR_MR_storage_controller_data is defined
#--------------------------------------Customize WinPE ISO image --------------------------------------------------------------------------------------
# - set_fact:
# boot_drive_bytes_size: "599584145408"
# Controller_type: "HPE MR416i-a Gen10+"
# - set_fact:
# boot_drive_bytes_size: "480103981056"
# Controller_type: "NS204i"
- name: Check if WinPE image ISO file '{{ winpe_iso_file }}' exists in '{{ src_iso_directory }}' on '{{lookup("pipe","hostname")}}'
stat:
path: "{{ src_iso_directory }}/{{ winpe_iso_file }}"
register: WinPE_Present
delegate_to: localhost
- name: Create the directory '{{ src_iso_directory }}' to host the WinPE ISO file on '{{ lookup("pipe","hostname") }}'
file:
path: "{{ src_iso_directory }}"
state: directory
when: WinPE_Present.stat.exists == False
delegate_to: localhost
- name: Check if WinPE image ISO '{{ winpe_iso_url }}/{{ winpe_iso_file }}' exists
uri:
url: "{{ winpe_iso_url }}/{{ winpe_iso_file }}"
method: HEAD
status_code: 200 # The HTTP status code for a successful request.
validate_certs: false
when: WinPE_Present.stat.exists == False
delegate_to: localhost
- name: Download file '{{ winpe_iso_file }}' to '{{ lookup("pipe","hostname") }}' in '{{ src_iso_directory }}' if not present
get_url:
url: "{{ winpe_iso_url }}/{{ winpe_iso_file }}"
dest: "{{ src_iso_directory }}"
validate_certs: no
when: WinPE_Present.stat.exists == False
delegate_to: localhost
# - debug: var=WinPE_Present
- name: Create '/mnt/{{ inventory_hostname }}-WinPE' on '{{lookup("pipe","hostname")}}'
become: yes
file:
path: /mnt/{{ inventory_hostname }}-WinPE
state: directory
mode: "0755"
delegate_to: localhost
- name: Create '{{ staging_directory }}/baremetal/{{ inventory_hostname }}-WinPE/' on '{{lookup("pipe","hostname")}}' if it does not exist
file:
path: "{{ staging_directory }}/baremetal/{{ inventory_hostname }}-WinPE"
state: directory
delegate_to: localhost
- name: Mount WinPE ISO '{{ src_iso_directory }}/{{ winpe_iso_file }}' to '/mnt/{{ inventory_hostname }}-WinPE/'
become: yes
shell:
mount -o loop -t udf {{ src_iso_directory }}/{{ winpe_iso_file }} /mnt/{{ inventory_hostname }}-WinPE/
delegate_to: localhost
- name: Copy WinPE files to '{{ staging_directory }}/baremetal/{{ inventory_hostname }}-WinPE/' on '{{lookup("pipe","hostname")}}'
shell: |
rsync -a /mnt/{{ inventory_hostname }}-WinPE/. {{ staging_directory }}/baremetal/{{ inventory_hostname }}-WinPE/
delegate_to: localhost
- name: Unmount directory '/mnt/{{ inventory_hostname }}-WinPE'
become: yes
shell:
umount /mnt/{{ inventory_hostname }}-WinPE
delegate_to: localhost
# Generating unattended file and adding to WinPE
- name: Create autounattend.xml file with customized values in '{{ staging_directory }}/baremetal/{{ inventory_hostname }}-WinPE/'
become: yes
template:
src: files/{{ windows_version }}/{{ unattend }}
dest: "{{ staging_directory }}/baremetal/{{ inventory_hostname }}-WinPE/"
delegate_to: localhost
# NOT NECESSARY. SINCE WINDOWS SERVER 2012, WinRM IS ENABLED BY DEFAULT
# Adding WinRM script to configure Windows for remote management with Ansible
# - name: Copying ConfigureRemotingForAnsible.ps1 file to WinPE
# become: yes
# copy:
# src: files/ConfigureRemotingForAnsible.ps1
# dest: "{{ staging_directory }}/baremetal/{{ inventory_hostname }}-WinPE/"
# delegate_to: localhost
# Adding HPE Agentless Management Service (AMS) file to WinPE (required by COM to detect the end of the OS installation)
- name: Copying HPE AMS package file to {{ inventory_hostname }}
become: yes
copy:
src: files/{{ windows_version }}/{{ AMS_package }}
dest: "{{ staging_directory }}/baremetal/{{ inventory_hostname }}-WinPE/"
delegate_to: localhost
# Adding HPE iLO Channel Interface Driver file to WinPE (required to install AMS)
- name: Copying HPE iLO CHIF driver package file to {{ inventory_hostname }}
become: yes
copy:
src: files/{{ windows_version }}/{{ iLO_CHIF_package }}
dest: "{{ staging_directory }}/baremetal/{{ inventory_hostname }}-WinPE/"
delegate_to: localhost
# Creating a pre-installation PowerShell script which will run before Windows Server installation starts.
- name: Create 'Pre_installation_script.ps1' in WinPE root to start the OS installation
become: yes
copy:
force: true
dest: "{{ staging_directory }}/baremetal/{{ inventory_hostname }}-WinPE/Pre_installation_script.ps1"
content: |
$logFilePath = "X:\Pre_installation_script.log"
#-------- Identify CDROM Drive --------------------------------------------------------------------------------------------------------------------------------------
# Get WinPE CDROM drive letter
$WINREDrive = (Get-WmiObject -Query "SELECT * FROM Win32_CDROMDrive").Drive
"`n### CDROM Drive found: {0}" -f $WINREDrive | Tee-Object -Append -FilePath $logFilePath
#-------- Identify OS boot Volume -----------------------------------------------------------------------------------------------------------------------------------
"### Disk detection to be used for the OS installation with size={{ boot_drive_bytes_size }} and controller='{{ Controller_type }}'" | Tee-Object -Append -FilePath $logFilePath
if({{ boot_drive_bytes_size }} -ne 0){
# Retrieve ID of the disk for the OS installation using disk size and controller type found in COM
$targetDisk = Get-Disk | Where-Object { $_.Size -eq {{ boot_drive_bytes_size }} -and $_.Model -match ("{{ Controller_type }}" -split " ")[1] }
$diskID = $targetDisk.DiskNumber
}
else{
# Retrieve ID of the disk for the OS installation using first local disk found
$targetDisk = Get-Disk | select -first 1
$diskID = $targetDisk.DiskNumber
}
"### Disk found for the OS boot: {0}" -f $diskID | Tee-Object -Append -FilePath $logFilePath
#-------- Set the OS installation target disk in autounattend file using DiskID -------------------------------------------------------------------------------------
# Set autounattend file DiskID value with the disk number found for the OS boot volume
$autounattendFilePath = "$WINREDrive\autounattend.xml"
$content = Get-Content -Path $autounattendFilePath
$updatedContent = $content -replace 'Value_to_change_at_WinPE_startup', $diskID
"### Target DiskID {0} added to Autounattend.xml" -f $diskID | Tee-Object -Append -FilePath $logFilePath
#-------- Save new autounattend file with DiskID to X: ---------------------------------------------------------------------------------------------------------------
"### Saving updated Autounattend.xml file to X:\" | Tee-Object -Append -FilePath $logFilePath
Set-Content -Path x:\autounattend.xml -Value $updatedContent
#-------- Set the disk configuration for the new Windows OS installation -------------------------------------------------------------------------------------------
"### Clearing any existing partition on disk {0}" -f $diskID | Tee-Object -Append -FilePath $logFilePath
# Clear any existing partition information
$targetDisk | Clear-Disk -RemoveData -RemoveOEM -Confirm:$false | Out-File -Append $logFilePath
# Initialize the disk as GPT
$targetDisk | Initialize-Disk -PartitionStyle GPT | Out-File -Append $logFilePath
# 1. EFI System partition
"### Creating EFI System partition on disk {0}" -f $diskID | Tee-Object -Append -FilePath $logFilePath
$targetDisk | New-Partition -Size 100MB -GptType "{c12a7328-f81f-11d2-ba4b-00a0c93ec93b}" -DriveLetter S | Format-Volume -FileSystem FAT32 -NewFileSystemLabel "System" | Out-File -Append $logFilePath