-
Notifications
You must be signed in to change notification settings - Fork 0
/
transfer_file.yml
71 lines (61 loc) · 2.17 KB
/
transfer_file.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
---
# Ansible Playbook to upgrade Cisco IOS
- name: TRANSFER file
hosts: hq
gather_facts: no
vars:
ansible_command_timeout: 600
tftp_server: 10.10.1.54
#ios_file: hq_facts.txt
ios_file: c1861-adventerprisek9-mz.152-4.M11.bin
tasks:
#- name: Copy file to flash
#ansible.netcommon.net_put:
# src: " ./firmware/{{ upgrade_ios_image }}"
#src: "/home/swt/Repo/Automation/Ansible_examples/software_update/hq_facts.txt"
# protocol: sftp
#protocol: scp
#dest: "flash:hq_facts.txt"
- name: Collect ios facts
ios_facts:
gather_subset:
- hardware
tags: hwinfo
- name: display hardware info
ansible.builtin.debug:
msg:
- " HARDWARE INFO "
- "{{ ansible_net_filesystems_info }}"
- "Free Space is: {{ ansible_net_filesystems_info['flash:']['spacefree_kb'] }} "
- "Current IOS image is: {{ ansible_net_image }}"
tags: hwinfo
- name: Backup Running Config
ios_command:
commands: show run
register: config
tags: backup
- name: Save output of sh run to ./backups/
ansible.builtin.copy:
content: "{{ config.stdout[0] }}"
dest: "./backups/{{ hostvars.localhost.DTG }}/{{ inventory_hostname }}-{{ hostvars.localhost.DTG }}-config.txt"
mode: u+rw,g-wx,o-rwx
tags: backup
- name: Not enough free space info check
ansible.builtin.debug:
msg:
- " not enought free space"
when: ansible_net_filesystems_info['flash:']['spacefree_kb'] < ios_size
tags: space
- name: Delete old IOS release if not enought free space
ios_command:
commands: delete /force {{ ansible_net_image }}
when: ansible_net_filesystems_info['flash:']['spacefree_kb'] < ios_size
tags: del_old
- name: Copy IOS to device
ios_command:
commands:
- command: 'copy tftp://{{ tftp_server }}/{{ ios_file }} flash:'
prompt: 'Destination filename \[{{ ios_file }}\]?'
answer: "\r"
when: ansible_net_filesystems_info['flash:']['spacefree_kb'] > ios_size
tags: cp_ios