Skip to content

Commit

Permalink
added upgrade playbook for cisco IOS
Browse files Browse the repository at this point in the history
  • Loading branch information
Anas committed Jan 6, 2017
1 parent 295cff2 commit 7aebe23
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 30 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -2,3 +2,4 @@
backup/*
images/*
*.save
*.cfg
4 changes: 2 additions & 2 deletions copy_file.yml
@@ -1,11 +1,11 @@
---
- name: Copy file to a Cisco IOS router
hosts: ios
hosts: csr

tasks:
- ntc_file_copy:
platform: cisco_ios_ssh
local_file: change_hostname.yml
local_file: images/csr1000v-universalk9.03.12.00.S.154-2.S-std.SPA.bin
host: "{{ inventory_hostname }}"
username: vagrant
password: cisco
6 changes: 3 additions & 3 deletions group_vars/ios.yml
@@ -1,7 +1,7 @@
---
version: "15.5S"
new_image: test.bin
username: vagrant
version: "15.4(2)S"
new_image: csr1000v-universalk9.03.12.00.S.154-2.S-std.SPA.bin
username: cisco
password: cisco

cli:
Expand Down
3 changes: 2 additions & 1 deletion hosts
@@ -1,8 +1,9 @@
[ios]
csr ansible_host=192.168.0.201
csr3 ansible_host=192.168.0.203

[junos]
vsrx ansible_host=192.168.0.130

[local]
local ansible_host=127.0.0.1 ansible_python_interpreter=python
local ansible_host=127.0.0.1
12 changes: 6 additions & 6 deletions show_arp.yml
@@ -1,12 +1,12 @@
---
- hosts: all
- hosts: csr
tasks:
- ios_command:
commands: show arp
host: "{{inventory_hostname}}"
provider: "{{cli}}"
when: "'ios' in group_names"
- junos_command:
commands: show arp
provider: "{{netconf}}"
when: "'junos' in group_names"
notify: test

handlers:
- name: test
raw: "show hostname"
10 changes: 7 additions & 3 deletions test.yml
@@ -1,5 +1,9 @@
---
- hosts: all

- hosts: localhost
connection: local
gather_facts: yes
tasks:
- set_fact: mydate="{{lookup('pipe','date +%Y%m%d%H%M%S')}}"
- debug: var=mydate
- name: print time
debug: var=ansible_date_time

49 changes: 34 additions & 15 deletions upgrade.yml
@@ -1,42 +1,46 @@
---

- name: Upgrade a Cisco IOS router
hosts: ios
hosts: csr

tasks:
- name: Gather the ruuning version number
- name: GATHERING FACTS
ios_facts:
gather_subset: hardware
provider: "{{cli}}"
tags: always

- name: Copy the new imag to flash if it doesn't exist
- name: COPYING IMAGE TO DEVICE FLASH
ntc_file_copy:
platform: cisco_ios_ssh
local_file: images/{{ new_image }}
host: "{{ inventory_hostname }}"
username: "{{ username }}"
password: "{{ password }}"
when: ansible_net_version != "{{version}}"

- name: Boot from the new image
ntc_install_os:
platform: cisco_ios_ssh
system_image_file: "{{new_image}}"
host: "{{ inventory_hostname }}"
username: "{{ username }}"
password: "{{ password }}"
when: ansible_net_version != "{{version}}"
tags: copy

- name: Saving configs locally
- name: SETTING BOOT IMAGE
ios_config:
lines:
- no boot system
- boot system flash bootflash:{{new_image}}
provider: "{{cli}}"
host: "{{ inventory_hostname }}"
when: ansible_net_version != "{{version}}"
tags: install

- name: SAVING CONFIGS
ntc_save_config:
platform: cisco_ios_ssh
host: "{{ inventory_hostname }}"
username: "{{ username }}"
password: "{{ password }}"
local_file: backup/{{inventory_hostname}}.cfg
local_file: backup/{{ inventory_hostname }}.cfg
when: ansible_net_version != "{{version}}"
tags: backup

- name: Reboot the device
- name: RELOADING THE DEVICE
ntc_reboot:
platform: cisco_ios_ssh
confirm: true
Expand All @@ -45,3 +49,18 @@
username: "{{ username }}"
password: "{{ password }}"
when: ansible_net_version != "{{version}}"
tags: reload

- name: VERIFYING CONNECTIVITY
wait_for:
port: 22
host: "{{inventory_hostname}}"
timeout: 300
- ios_command:
commands: ping 8.8.4.4
provider: "{{cli}}"
wait_for:
- result[0] contains "!!!"
register: result
failed_when: "not '!!!' in result.stdout[0]"
tags: verify

0 comments on commit 7aebe23

Please sign in to comment.