feat: add backup playbook
This commit is contained in:
24
opdracht-2/backup-playbook.yml
Normal file
24
opdracht-2/backup-playbook.yml
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
- name: Backup /etc and /var/www, add cronjob
|
||||||
|
hosts: all
|
||||||
|
become: true
|
||||||
|
tasks:
|
||||||
|
- name: Create backup script
|
||||||
|
ansible.builtin.copy:
|
||||||
|
dest: /usr/local/bin/backup.sh
|
||||||
|
mode: '0755'
|
||||||
|
content: |
|
||||||
|
#!/bin/bash
|
||||||
|
tar -czf /tmp/backup_$(date +\%F).tar.gz /etc /var/www
|
||||||
|
|
||||||
|
- name: Execute backup script
|
||||||
|
ansible.builtin.command: /usr/local/bin/backup.sh
|
||||||
|
register: myoutput
|
||||||
|
changed_when: myoutput.rc != 0
|
||||||
|
|
||||||
|
- name: Add cronjob for daily back-up
|
||||||
|
ansible.builtin.cron:
|
||||||
|
name: "Daily backup of /etc and /var/www"
|
||||||
|
user: iac
|
||||||
|
job: "/usr/local/bin/backup.sh"
|
||||||
|
minute: "0"
|
||||||
|
hour: "1"
|
Reference in New Issue
Block a user