-
-
Save pr0b3r7/82c9b97c10c9add5c2bea829a68ec0d7 to your computer and use it in GitHub Desktop.
Ansible Playbook to reload Cisco Switches and verify the version is at the target
This file contains hidden or 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
--- | |
- hosts: sw_ios | |
gather_facts: false | |
models: | |
"WS-C2960XR-48FPD-I": | |
ios_version: "15.2(7)E0a" | |
ios_path: "IOS/" | |
ios_archive: "c2960x-universalk9-tar.152-7.E0a.tar" | |
ios_binary: "c2960x-universalk9-mz.152-7.E0a.bin" | |
ios_md5: "07195a8c7866ac2a91c64b716465c516" | |
ios_size_kb: 37489 | |
tasks: | |
- name: Wait until the lock file is removed | |
wait_for: | |
path: playbooks/file.lock | |
state: absent | |
tags: | |
- lock | |
- name: Email start of process on switch Name | |
mail: | |
subject: Reloading {{ inventory_hostname }} | |
host: my.smtp.local | |
port: 25 | |
to: | |
- [email protected] | |
from: [email protected] | |
delegate_to: localhost | |
tags: | |
- reload | |
- name: Create Lock File | |
file: | |
path: playbooks/file.lock | |
state: touch | |
tags: | |
- reload | |
- lock | |
- name: Reload Switch | |
ios_command: | |
commands: | |
- command: "reload" | |
prompt: "Proceed with reload? \[confirm\]" | |
answer: '\r' | |
tags: | |
- reload | |
- name: Wait for the switch to return | |
wait_for: | |
host: "{{ ansible_host }}" | |
port: 22 | |
delay: 180 | |
timeout: 600 | |
delegate_to: localhost | |
tags: | |
- reload | |
- check_online | |
- name: Email switch name back online | |
mail: | |
subject: Back Online {{ inventory_hostname }} | |
host: my.smtp.local | |
port: 25 | |
to: | |
- [email protected] | |
from: [email protected] | |
delegate_to: localhost | |
tags: | |
- reload | |
- name: Gather all legacy facts | |
ios_facts: | |
gather_subset: hardware | |
tags: | |
- facts | |
- name: Asset that the IOS version is the correct one | |
assert: | |
that: | |
- ansible_net_version = models[ansible_net_model]["ios_version"] | |
tags: | |
- facts | |
- name: Delete Lock File | |
file: | |
path: playbooks/file.lock | |
state: absent | |
tags: | |
- reload | |
- lock |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment