Guest User

Untitled

a guest
Mar 29th, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. ---
  2.  
  3. - name: Upgrade a Cisco IOS Device
  4. hosts: ios_switch
  5. tasks:
  6. - name: Gathering Facts
  7. ios_facts:
  8. gather_subset: hardware
  9. provider: "{{ creds_ssh }}"
  10. tags: always
  11.  
  12. - name: Copying image to device flash
  13. ntc_file_copy:
  14. platform: cisco_ios_ssh
  15. local_file: images/{{ image }}
  16. host: "{{ inventory_hostname }}"
  17. username: "{{ username }}"
  18. password: "{{ password }}"
  19. when: ansible_net_version != "{{ standard_version }}"
  20. tags: copy
  21.  
  22. - name: Setting boot image
  23. ios_config:
  24. lines:
  25. - no boot system
  26. - boot system flash:{{ image }}
  27. provider: "{{ creds_ssh }}"
  28. host: "{{ inventory_hostname }}"
  29. when: ansible_net_version != "{{ standard_version }}"
  30. tags: set_boot
  31. notify: save config
  32.  
  33. - name: Backup config
  34. ntc_save_config:
  35. platform: cisco_ios_ssh
  36. host: "{{ inventory_hostname }}"
  37. username: "{{ username }}"
  38. password: "{{ password }}"
  39. local_file: backup/{{ inventory_hostname }}.cfg
  40. when: ansible_net_version != "{{ standard_version }}"
  41. tags: backup
  42.  
  43. - name: Reloading the device
  44. ntc_reboot:
  45. platform: cisco_ios_ssh
  46. confirm: true
  47. timer: 2
  48. host: "{{ inventory_hostname }}"
  49. username: "{{ username }}"
  50. password: "{{ password }}"
  51. when: ansible_net_version != "{{ standard_version }}"
  52. tags: reload
  53.  
  54. - name: Verifying connectivity
  55. wait_for:
  56. port: 22
  57. host: "{{ inventory_hostname }}"
  58. timeout: 600
  59. - ios_command:
  60. commands: ping 8.8.8.8
  61. provider: "{{ creds_ssh }}"
  62. wait_for:
  63. - result[0] contains "!!!"
  64. register: result
  65. failed_when: "not '!!!' in result.stdout[0]"
  66. tags: verify
  67.  
  68. handlers:
  69. - name: save config
  70. ios_config:
  71. provider: "{{ creds_ssh }}"
  72. save_when: always
Add Comment
Please, Sign In to add comment