---
- name: validate ios_checkpoint_filename is defined
  fail:
    msg: "missing required var: ios_checkpoint_filename"
  when: ios_checkpoint_filename is undefined

- name: get current files on disk
  cli:
    command: dir
  register: ios_dir_listing

- name: verify checkpoint file exists
  fail:
    msg: "missing checkpoint file {{ ios_checkpoing_filename }}"
  when: ios_checkpoint_filename not in ios_dir_listing.stdout

- name: checkpoint configuration restore pre hook
  include_tasks: "{{ ios_checkpoint_restore_pre_hook }}"
  when: ios_checkpoint_restore_pre_hook is defined

- name: restore checkpoint configuration
  cli:
    command: "config replace flash:/{{ ios_checkpoint_filename }} force"
  register: ios_rollback_results

- name: checkpoint configuration restore post hook
  include_tasks: "{{ ios_checkpoint_restore_post_hook }}"
  when: ios_checkpoint_restore_post_hook is defined

- name: remove checkpoint file from remote device
  cli:
    command: "delete /force flash:/{{ ios_checkpoint_filename }}"
