diff --git a/group_vars/all b/group_vars/all index 3d07b42..7853d54 100644 --- a/group_vars/all +++ b/group_vars/all @@ -1,3 +1,7 @@ --- common_aliases: - "root: bofh@fet.at" +common_hostname: False +common_apt: False +common_rsyslog: False +common_resolvconf: False \ No newline at end of file diff --git a/group_vars/backup b/group_vars/backup new file mode 100644 index 0000000..23a39d0 --- /dev/null +++ b/group_vars/backup @@ -0,0 +1,7 @@ +backup: + repositories: + - path: "/srv/rep1" + name: "Repository1" + - path: "/srv/rep2" + name: "Repository2" + \ No newline at end of file diff --git a/host_vars/backup01 b/host_vars/backup01 new file mode 100644 index 0000000..7b9530f --- /dev/null +++ b/host_vars/backup01 @@ -0,0 +1 @@ +inventory_hostname_short: backup01 \ No newline at end of file diff --git a/hosts/production b/hosts/production index e6e150b..7ce8a9b 100644 --- a/hosts/production +++ b/hosts/production @@ -1,2 +1,5 @@ [backup] 10.0.3.113 + +[backupclient] +10.0.3.161 diff --git a/roles/backup/tasks/borg.yml b/roles/backup/tasks/borg.yml index 4580530..f35aa98 100644 --- a/roles/backup/tasks/borg.yml +++ b/roles/backup/tasks/borg.yml @@ -1,3 +1,21 @@ --- - name: install borg - apt: name="borgbackup" state=present \ No newline at end of file + apt: name="borgbackup" state=present + +- name: create repositories + file: + path: "{{item.path}}" + state: directory + with_items: "{{backup.repositories}}" + +- name: init borg repositories + command: "borg init {{item.path}} --encryption=none" + args: + creates: "{{item.path}}/README" + with_items: "{{backup.repositories}}" + +- name: create READMES + template: + src=borg_README.j2 + dest="{{item.path}}/README" + with_items: "{{backup.repositories}}" diff --git a/roles/backup/templates/borg_README.j2 b/roles/backup/templates/borg_README.j2 new file mode 100644 index 0000000..349390f --- /dev/null +++ b/roles/backup/templates/borg_README.j2 @@ -0,0 +1,2 @@ +This is a generate FET borg repository. +Name: {{item.name}} \ No newline at end of file diff --git a/roles/backupclient/defaults/main.yml b/roles/backupclient/defaults/main.yml new file mode 100644 index 0000000..81d832e --- /dev/null +++ b/roles/backupclient/defaults/main.yml @@ -0,0 +1,2 @@ +--- +backup_borg: True \ No newline at end of file diff --git a/roles/backupclient/tasks/borg.yml b/roles/backupclient/tasks/borg.yml new file mode 100644 index 0000000..7610993 --- /dev/null +++ b/roles/backupclient/tasks/borg.yml @@ -0,0 +1,26 @@ +--- +- name: install borg + apt: name="borgbackup" state=present + +- name: create backup user + user: + name: borg_backup + comment: "BackupUser für BORG Backup" + group: root + generate_ssh_key: yes + ssh_key_bits: 4096 + ssh_key_file: .ssh/id_rsa + +- name: fetch pubickey + shell: "cat /home/borg_backup/.ssh/id_rsa.pub" + register: id_rsa_pub + +- name: Add authorized key to borg backup servers + authorized_key: + user: "root" + key: "{{id_rsa_pub.stdout}}" + key_options: 'command="borg serve --restrict-to-path /srv/rep1"' + delegate_to: "{{item}}" + with_items: "{{groups['backup']}}" + when: id_rsa_pub.stdout is defined + diff --git a/roles/backupclient/tasks/main.yml b/roles/backupclient/tasks/main.yml new file mode 100644 index 0000000..a17a99e --- /dev/null +++ b/roles/backupclient/tasks/main.yml @@ -0,0 +1,4 @@ +--- +- include: borg.yml + when: backup_borg + tags: ['backup', 'borg'] diff --git a/site.retry b/site.retry index 4639501..ec8c1de 100644 --- a/site.retry +++ b/site.retry @@ -1 +1 @@ -10.0.3.113 +10.0.3.161 diff --git a/site.yml b/site.yml index 11c7e34..8ccae5e 100644 --- a/site.yml +++ b/site.yml @@ -4,4 +4,11 @@ become: False roles: - common - - backup \ No newline at end of file + - backup + +- hosts: backupclient + user: root + become: False + roles: + - common + - backupclient \ No newline at end of file