@create date 2020-06-02 17:12:00

@desc [Automation - Cisco IOS Device Backup and Configure Template]


- name: Cisco IOS Device Backup and Configure Template

- hosts: Cisco

  connection: network_cli
  gather_facts: false

tasks:

- name: Get current date

  local_action: command date +%Y-%b-%d
  register: date

- name: Get current time

  local_action: command date +%H:%M
  register: time

- name: Get running-config and save it

  ios_config:
   backup: yes
   backup_options:
     #ansible_host = getting device IP, ansible_net_hostname = getting device hostname
     filename: "{{ ansible_net_hostname }}_{{ ansible_host }}.cfg"
     #Please change /home/hawar/Desktop to your direcotry
     #Every time create a new directory under named date and time
     dir_path: /tmp/backups/{{ date.stdout }}_at_{{ time.stdout }}
  ios_config:
    parents: "interface Ethernet0/1"
    lines:
      - description Uplink
      - ip address 192.168.0.1 255.255.255.0

- name: Tasks done

  debug: msg="All tasks completed on {{ date.stdout }} at {{ time.stdout }}."