forked from init4/f5_ansible_upgrade
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupgrade.yaml
136 lines (113 loc) · 3.68 KB
/
upgrade.yaml
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
- hosts: all
gather_facts: no
#connection: local
collections:
- f5networks.f5_modules
vars_prompt:
- name: f5_username
prompt: "Enter F5 Username"
private: no
default: "{{ lookup('env','USER') }}"
- name: f5_password
prompt: "Enter F5 Password"
tasks:
- name: Wait For Confirmation
pause:
prompt: "Press <Enter> to proceed..."
- name: Get Software Volume Information
bigip_device_info:
gather_subset:
- software-volumes
provider: "{{ provider }}"
register: sv
- name: Get Current Version
set_fact:
current_version: "{{ item.version }}"
current_boot_loc: "{{ item.name }}"
when: item.active == "yes"
with_items: "{{ sv.software_volumes }}"
- name: Set New Version from ISO name
set_fact:
new_ver: "{{ new_image.split('-') }}"
- name: Identify Hosts That Require Upgrade
set_fact:
wants_upgrade: True
when: not new_image is search(current_version)
- name: Identify Hosts That Don't Require Upgrade
set_fact:
wants_upgrade: False
when: new_image is search(current_version)
- name: Identify Hosts need Hotfix
set_fact:
wants_upgrade: True
when:
- new_image is search("Hotfix")
- new_image is search(current_version)
- name: Identify Hosts that DO NOT need Hotfix
set_fact:
wants_upgrade: False
when:
- new_image is search("Hotfix")
- not new_image is search(current_version)
- name: Only Upgrading Devices Which Need It
block:
- name: Check For Only One Boot Location
set_fact:
dest_boot_loc: "HD1.2"
when: (not dest_boot_loc is defined) and (sv.software_volumes|length == 1)
- name: Check First Boot Location
set_fact:
dest_boot_loc: "{{ sv.software_volumes.0.name }}"
when: (not dest_boot_loc is defined) and (sv.software_volumes.0.active != "yes")
- name: Check Second Boot Location
set_fact:
dest_boot_loc: "{{ sv.software_volumes.1.name }}"
when: (not dest_boot_loc is defined) and (sv.software_volumes.1.active != "yes")
when: wants_upgrade
- name: Device Version Status
debug:
msg:
- "Current version: {{ current_version }}"
- "Desired image: {{ new_image }}"
- "Upgrade needed: {{ wants_upgrade }}"
- name: Print Upgrade Information
debug:
msg:
- "Current version: {{ current_version }} booting from {{ current_boot_loc }}"
- "New Image '{{ new_image }}' will be uploaded from '{{ new_image_dir }}'"
- "It will be installed to boot location '{{ dest_boot_loc }}'"
when: wants_upgrade
- name: Wait For Confirmation
pause:
prompt: "Press a key to continue..."
- name: Save the running configuration of the BIG-IP
bigip_config:
provider: "{{ provider }}"
save: yes
when: wants_upgrade
- name: Ensure backup directory exists
file:
path: "{{ backup_loc }}/{{ inventory_hostname_short }}"
state: directory
when: wants_upgrade
#- name: Get Pre-Upgrade UCS Backup
# bigip_ucs_fetch:
# create_on_missing: yes
# backup: yes
# src: "{{ backup_pfx }}_pre-upgrade.ucs"
# dest: "{{ backup_loc }}/{{ inventory_hostname_short }}/{{ backup_pfx }}_pre-upgrade.ucs"
# provider: "{{ provider }}"
# when: wants_upgrade
- name: Upload image
bigip_software_image:
provider: "{{ provider }}"
image: "{{ new_image }}"
delegate_to: localhost
when: wants_upgrade
- name: Install Image
bigip_software_install:
provider: "{{ provider }}"
image: "{{ new_image }}"
state: installed
volume: "{{ dest_boot_loc }}"
when: wants_upgrade