Created
May 28, 2020 15:41
-
-
Save alikulov/57910ef5cf7a3dd9bee676d0f6e01404 to your computer and use it in GitHub Desktop.
Examle Ansible playbook for ONTAP disk firmware update
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- name: ONTAP Firmware Upgrade | |
hosts: localhost | |
gather_facts: no | |
collections: | |
- netapp.ontap | |
vars_prompt: | |
- name: "ontap_admin_username" | |
private: no | |
prompt: "Enter your ONTAP admin username" | |
- name: "ontap_admin_password" | |
prompt: "Enter the password for your ONTAP admin user" | |
- name: "ontap_firmware_url" | |
private: no | |
prompt: "Enter the URL to the firmware package (using HTTP is recommended)" | |
- name: "ontap_disk_qual_url" | |
private: no | |
prompt: "Enter the URL to the disk qualification package (using HTTP is recommended)" | |
vars: | |
ontap_use_https: true | |
ontap_validate_certs: false | |
login: &login | |
username: "{{ ontap_admin_username }}" | |
password: "{{ ontap_admin_password }}" | |
https: "{{ ontap_use_https }}" | |
validate_certs: "{{ ontap_validate_certs }}" | |
vars_files: | |
inventory.yml | |
tasks: | |
- name: Run the ONTAP info module to check connectivity | |
na_ontap_info: | |
hostname: "{{ item }}" | |
<<: *login | |
gather_subset: ontap_system_version | |
register: ontap | |
with_items: "{{ clusters }}" | |
# - debug: var=ontap | |
- name: Run the ONTAP command module to validate access permissions | |
na_ontap_command: | |
hostname: "{{ item }}" | |
<<: *login | |
command: version | |
return_dict: false | |
register: ontap | |
with_items: "{{ clusters }}" | |
# - debug: var=ontap | |
- name: Sending Pre-run ASUP | |
na_ontap_command: | |
command: ['autosupport invoke -node * -type all -message "Pre-Ansible Firmware Update"'] | |
hostname: "{{ item }}" | |
<<: *login | |
with_items: "{{ clusters }}" | |
- name: Run the ONTAP Disk Qualification download module | |
na_ontap_firmware_upgrade: | |
hostname: "{{ item }}" | |
<<: *login | |
package_url: "{{ ontap_disk_qual_url }}" | |
register: qualontap | |
ignore_errors: true | |
with_items: "{{ clusters }}" | |
- name: Run the ONTAP Firmware download module | |
na_ontap_firmware_upgrade: | |
hostname: "{{ item }}" | |
<<: *login | |
package_url: "{{ ontap_firmware_url }}" | |
register: ontap | |
ignore_errors: true | |
with_items: "{{ clusters }}" | |
- set_fact: | |
results: "{{ results|default([]) + [ result ] }}" | |
vars: | |
result: | |
name: "{{ item.item | default('') }}" | |
not_changed: "{{ not item.changed }}" | |
url: "{{ item.invocation.module_args.package_url | default('') }}" | |
success: "{{ not item.failed }}" | |
error: "{{ item }}" | |
invalid_url: "{{ item.msg | default('') is search('Invalid package URL') }}" | |
error_502: "{{ item.msg | default('') is search('NetApp API failed. Reason - 502:Bad Gateway') }}" | |
zapi_timeout: "{{ item.msg | default('') is search('NetApp API failed. Reason - 60:API did not finish on time') | default('') }}" | |
with_flattened: | |
- "{{ ontap.results }}" | |
- "{{ qualontap.results }}" | |
loop_control: | |
label: "{{ item.item }}" | |
# loop: "{{ ontap.results }}" | |
- fail: | |
msg: item.error | |
when: not item.success and not item.error_502 and not item.zapi_timeout and not item.invalid_url | |
loop: "{{ results }}" | |
loop_control: | |
label: "{{ item.name }}" | |
- debug: | |
msg: "{{ item.name + ': Firmware download still in progress. The firmware download and update will continue in the background on the ONTAP system.' }}" | |
when: item.error_502 | |
loop: "{{ results }}" | |
loop_control: | |
label: "{{ item.name }}" | |
- debug: | |
msg: "{{ item.name + ': Invalid Firmware URL or a firmware download already in progress on the ONTAP system: ' + item.url }}" | |
when: (item.invalid_url or item.not_changed) and not item.error_502 | |
loop: "{{ results }}" | |
loop_control: | |
label: "{{ item.name }}" | |
- debug: | |
msg: "{{ item.name + ': Firmware download completed. Firmware updates will continue in the background on the ONTAP system.' }}" | |
when: (item.success and not item.not_changed) or item.zapi_timeout | |
loop: "{{ results }}" | |
loop_control: | |
label: "{{ item.name }}" | |
- debug: | |
msg: Firmware update is a background process in ONTAP. To check the status of the firmware update, run 'storage disk firmware show-update-status' command on the conroller shell. | |
# - debug: var=ontap |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment