blob: 2b6a8b4b9a08132d2e9ff49574644bd5b17ce525 (
plain)
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
|
---
#
# The hosts group used is provided by the group variable or defaulted to 'Intersight_Servers'.
# You can specify a specific host (or host group) on the command line:
# ansible-playbook ... -e group=<your host group>
# e.g., ansible-playbook server_profiles.yml -e group=TME_Demo
#
- hosts: "{{ group | default('Intersight_Servers') }}"
connection: local
collections:
- cisco.intersight
gather_facts: false
vars:
# Create an anchor for api_info that can be used throughout the file
api_info: &api_info
api_private_key: "{{ api_private_key }}"
api_key_id: "{{ api_key_id }}"
api_uri: "{{ api_uri | default(omit) }}"
validate_certs: "{{ validate_certs | default(omit) }}"
state: "{{ state | default(omit) }}"
fw_version: 4.1(2b)
tasks:
# Set the distributable type based on the management mode and server type
- set_fact:
dist_type: IMMHOST
when: mode == 'Intersight' or mode == 'IntersightStandalone'
- set_fact:
dist_type: UMMBLADE
when: mode == 'UCSM' and object_type == 'Blade'
- set_fact:
dist_type: UMMRACK
when: mode == 'UCSM' and object_type == 'RackUnit'
# Get a user defined FW version
- name: Get Moid of user defined FW version
intersight_rest_api:
<<: *api_info
resource_path: /firmware/Distributables
query_params:
$filter: "SupportedModels eq '{{ model }}' and Version eq '{{ fw_version }}' and Tags.Key eq 'cisco.meta.distributabletype' and Tags.Value eq '{{ dist_type }}' and Tags.Key eq 'cisco.meta.repositorytype' and Tags.Value eq 'Cisco'"
delegate_to: localhost
register: fw_resp
# Update server firmware with a post based on server moid
- name: Update server firmware
intersight_rest_api:
<<: *api_info
resource_path: /firmware/Upgrades
query_params:
$filter: "Server.Moid eq '{{ server_moid }}'"
update_method: post
api_body: {
"DirectDownload": {
"Upgradeoption": "upgrade_mount_only"
},
"Distributable": {
"Moid": "{{ fw_resp.api_response.Moid }}"
},
"Server": {
"Moid": "{{ server_moid }}",
"ObjectType": "compute.{{ object_type }}"
},
"UpgradeType": "direct_upgrade",
"SkipEstimateImpact": true
}
delegate_to: localhost
register: update_resp
when:
- server_moid is defined
- fw_resp.api_response.Moid is defined
# Wait for download to complete
- name: Check firmware download status
intersight_rest_api:
<<: *api_info
resource_path: /firmware/UpgradeStatuses
query_params:
$filter: "Moid eq '{{ update_resp.api_response.UpgradeStatus.Moid }}'"
delegate_to: localhost
register: status_resp
until: status_resp.api_response.Overallstatus == 'pending' or status_resp.api_response.Overallstatus == 'success'
# 60 minutes to allow download to complete
retries: 60
delay: 60
when:
- update_resp.api_response is defined
|