-
Notifications
You must be signed in to change notification settings - Fork 0
/
upgrade.yml
68 lines (59 loc) · 2.05 KB
/
upgrade.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
# start backup process
- name: backup current configuration save to /tmp
shell:
cmd: "sysupgrade -b /tmp/{{inventory_hostname}}_{{ansible_host}}_{{firmware_version}}.tar.gz"
register: sysbackup
timeout: 30
- name: fetch backup file from host to /tmp
fetch:
src: "/tmp/{{inventory_hostname}}_{{ansible_host}}_{{firmware_version}}.tar.gz"
dest: "/tmp/"
flat: yes
timeout: 600
when: sysbackup.changed
- name: add {{ docker_host.name }} to inventory
add_host: "{{ docker_host }}"
run_once: true
changed_when: false
- name: copy backup file to {{ docker_host.name }}:/etc/ansible/backups
copy:
src: "/tmp/{{inventory_hostname}}_{{ansible_host}}_{{firmware_version}}.tar.gz"
dest: "/etc/ansible/backups/"
timeout: 600
delegate_to: "{{ docker_host.name }}"
register: backup_copy
# start firmware upgrade process
- name: copy {{ task_firmware }} firmware to device
copy:
src: "{{playbook_dir}}/files/firmware/{{ task_firmware }}.bin"
dest: /tmp/{{ task_firmware }}.bin
timeout: 600
when: backup_copy is success
- name: start {{ task_firmware }} sysupgrade and wait for reboot
shell: |
sysupgrade /tmp/{{ task_firmware }}.bin &> /tmp/sysupgrade_output &
while true; do
if grep -i "upgrade" /tmp/sysupgrade_output; then
exit 0
fi
done
register: sysupgrade
timeout: 60
- name: wait for host to become reachable
wait_for_connection:
delay: 90
register: wait_for_connection
until: wait_for_connection.unreachable is not defined
retries: 7
when: sysupgrade.changed
- name: get current firmware version
slurp:
src: /etc/version
register: version
timeout: 30
- set_fact:
previous_version: "{{ firmware_version }}"
firmware_version: "{{ version['content'] | b64decode | regex_replace('\n', '') }}"
- name: confirm upgrade
debug:
msg: "firmware on host {{ ansible_host }} successfully upgraded from {{ previous_version }} ---> {{ firmware_version }}, proceeding to {% if firmware_version in target %}package installation{% else %}upgrade to {{ target[0] }}{% endif %}"