-
Notifications
You must be signed in to change notification settings - Fork 147
/
Copy pathnetwork_backup.yml
76 lines (68 loc) · 2.55 KB
/
network_backup.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
---
- name: Retrieve network configurations
hosts: network
gather_facts: false
tasks:
# fail with good error for Automation controller user
- name: Determine that both AAP and Machine credentials are set
ansible.builtin.assert:
that:
- "lookup('env', 'CONTROLLER_USERNAME') !=''"
fail_msg:
- "This Job requires two credentials"
- "Red Hat Ansible Automation Platform credential is not set"
- "Please assign correct credentials to the Job Template"
- name: Determine that both AAP and Machine credentials are set
ansible.builtin.debug:
msg:
- "{{ lookup('env', 'CONTROLLER_USERNAME') }}"
- "{{ lookup('env', 'CONTROLLER_PASSWORD') }}"
- "{{ lookup('env', 'CONTROLLER_HOST') }}"
- name: Backup configuration
ansible.builtin.include_role:
name: "../roles/backup"
when: ansible_network_os is defined
- name: Create time stamp for play
ansible.builtin.set_fact:
datetime: "{{ lookup('pipe', 'date +%Y-%m-%d-%H-%M') }}"
delegate_to: backup-server
delegate_facts: true
run_once: true
- name: Create a directory if it does not exist
ansible.builtin.file:
path: /backup/
state: directory
mode: "755"
delegate_to: backup-server
become: true
run_once: true
- name: Save configuration to backup server
ansible.builtin.copy:
src: "{{ config_output.backup_path }}"
dest: "/backup/{{ hostvars['backup-server'].datetime }}/"
mode: "644"
when: config_output is defined
become: true
delegate_to: backup-server
- name: Find backups
ansible.builtin.find:
paths: /backup
file_type: directory
register: backups
run_once: true
become: true
delegate_to: backup-server
delegate_facts: true
- name: Create restore job template
ansible.controller.job_template:
name: "Network Automation - Restore"
job_type: "run"
inventory: "{{ restore_inventory | default('Network Inventory') }}"
project: "{{ restore_project | default('Network Toolkit') }}"
playbook: "{{ restores_playbook | default('playbooks/network_restore.yml') }}"
credential: "{{ restore_credential | default('Network Credential') }}"
survey_enabled: true
survey_spec: "{{ lookup('template', '{{ playbook_dir }}/templates/backup.j2') }}"
validate_certs: false
execution_environment: "Default execution environment"
run_once: true