Ansible – VyOS Backup

$ vi ansible.cfg

[defaults]
inventory = /home/backup/conf/vyos/ansible/hosts
remote_tmp = /home/backup/conf/vyos/ansible/ansible-${USER}/tmp
local_tmp = /home/backup/conf/vyos/ansible/tmp/ansible-${USER}/tmp
host_key_checking = False
timeout = 15
log_path = /home/backup/conf/vyos/ansible/ansible.log

$ vi hosts

[vyos]
CYBER_VyOS_1 ansible_host=172.16.16.100
CYBER_VyOS_2 ansible_host=172.16.16.200

[vyos:vars]
ansible_user = agink
ansible_password = ...[sensor]...
ansible_port = 25900
ansible_connection = network_cli
ansible_network_os = vyos 
gather_facts = false

$ vi vyos_backup.yml

---
- name: AGINK - VyOS Backup Automation
  hosts: vyos 
  connection: local
  gather_facts: no
  ignore_errors: yes

  vars:
    date: "{{ lookup('pipe', 'date +%Y%m%d_%H%M') }}"
    backup_path: "/home/backup/conf/vyos"

  tasks:
    - name: show config 
      block:
      - name: get show config 
        vyos_command: 
          commands: "show configuration" 
        register: config

      - name: get show config command
        vyos_command:
          commands: "show configuration commands"
        register: config_cmd

      - name: create directory
        file:
          path: "{{ backup_path }}/{{ inventory_hostname }}"
          state: directory

      - name: copy config to backup folder
        copy: 
          content: "{{ config.stdout[0] }}"
          dest: "{{ backup_path }}/{{ inventory_hostname }}/VyOS-config_{{ date }}.txt"

      - name: copy config command to backup folder
        copy:
          content: "{{ config_cmd.stdout[0] }}"
          dest: "{{ backup_path }}/{{ inventory_hostname }}/VyOS-config-commnand_{{ date }}.txt"

run
—-

$ ansible-playbook vyos_backup.yml