-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathbackupPkiServer.yml
82 lines (72 loc) · 3.58 KB
/
backupPkiServer.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
77
78
79
80
---
# When DB is NOT on the local node:
# ansible-playbook -i inventory -l ca01,backupServer -e "backup_ejbca_server=true backup_ejbca_conf=true backup_httpd_conf=true backup_wildfly_conf=true copy_backup_to_remote=true backup_server_dir_path=~/backup" backupPkiServer.yml
# When DB is ON the local node:
# ansible-playbook -i inventory -l ca01,backupServer -e "backup_ejbca_server=true backup_ejbca_conf=true backup_httpd_conf=true backup_wildfly_conf=true backup_mariadb=true copy_backup_to_remote=true backup_server_dir_path=~/backup" backupPkiServer.yml
# ansible-playbook -i inventory -l ra01,backupServer -e "backup_ejbca_server=true backup_ejbca_conf=true backup_httpd_conf=true backup_wildfly_conf=true backup_mariadb=true copy_backup_to_remote=true backup_server_dir_path=~/backup" backupPkiServer.yml
# ansible-playbook -i inventory -l va01,backupServer -e "backup_ejbca_server=true backup_ejbca_conf=true backup_httpd_conf=true backup_wildfly_conf=true backup_mariadb=true copy_backup_to_remote=true backup_server_dir_path=~/backup" backupPkiServer.yml
# When DB and SoftHSM are ON the local node:
# ansible-playbook -i inventory -l ca01,backupServer -e "backup_ejbca_server=true backup_ejbca_conf=true backup_httpd_conf=true backup_wildfly_conf=true backup_mariadb=true backup_pkcs11_client=true copy_backup_to_remote=true backup_server_dir_path=~/backup" backupPkiServer.yml
- hosts: pkiServers
become: yes
become_method: sudo
pre_tasks:
- name: Create timestamp fact
ansible.builtin.set_fact:
backup_time_stamp: "{{ lookup('pipe','date +%d-%m-%Y')}}"
delegate_to: localhost
vars:
- backup_dir_path_timestamp: "{{ backup_dir_path }}/{{ hostname }}-{{ backup_time_stamp }}"
roles:
- ansible-pki-ss-cfg-bkup
tags: backup
- hosts: backupServer
gather_facts: false
tasks:
- name: Copy to remote backup server
block:
- name: Find what backup files are on the controller
ansible.builtin.find:
path: "{{ backup_dir_output }}"
file_type: file
recurse: yes
patterns: "*.tgz"
register: find_local_pki_backups
delegate_to: localhost
tags: copy_backup
- name: Check if remote directory {{ backup_server_dir_path }} exists
ansible.builtin.stat:
path: "{{ backup_server_dir_path }}"
register: backup_server_dir_path_exists
changed_when: false
tags: copy_backup
- name: Create remote directory for {{ backup_server_dir_path }} if it doesn't exist
become: no
ansible.builtin.file:
path: "{{ backup_server_dir_path }}"
state: directory
tags: copy_backup
when:
- not backup_server_dir_path_exists.stat.exists
- name: Copy the backup archive to the remote backup server
ansible.builtin.copy:
src: "{{ item.path }}"
dest: "{{ backup_server_dir_path }}/{{ item.path| basename }}"
loop: "{{ find_local_pki_backups.files }}"
loop_control:
label: "{{ item.path }}"
tags: copy_backup
when:
- find_local_pki_backups is defined
- name: Remove backup files from the Ansible controller
ansible.builtin.file:
path: "{{ item.path }}"
state: absent
loop: "{{ find_local_pki_backups.files }}"
loop_control:
label: "{{ item.path }}"
delegate_to: localhost
tags: copy_backup
when:
- copy_backup_to_remote is defined
- copy_backup_to_remote| bool