45 lines
1.7 KiB
YAML
45 lines
1.7 KiB
YAML
- include_vars: backup-receiver.yml
|
|
- name: Make sure the receiver group exist
|
|
group: name="{{ group }}" state=present
|
|
|
|
- name: Add the receiver group
|
|
user: name="{{ user }}" shell=/bin/bash home="{{ home }}" createhome=yes group="{{ group }}" groups= state=present
|
|
|
|
- name: Create the homedirectory for the receiver
|
|
file: path="{{ home }}" owner="{{ user }}" group="{{ group }}" mode=0700 state=directory
|
|
|
|
- name: Create the .ssh dir for the receiver
|
|
file: path="{{ home }}/.ssh" owner="{{ user }}" group="{{ group }}" mode=0700 state=directory
|
|
|
|
- name: Create a directory for the pool
|
|
file: path="{{ pool }}" owner="{{ user }}" group="{{ group }}" mode=0700 state=directory
|
|
|
|
- name: Install client-keys
|
|
authorized_key:
|
|
user="{{ user }}"
|
|
key="{{ item.key }}"
|
|
key_options='command="cd {{ pool }}/{{ item.host }};borg serve --restrict-to-path {{ pool }}/{{ item.host }}",no-port-forwarding,no-X11-forwarding,no-pty'
|
|
when: item.key is defined
|
|
with_items:
|
|
- '{{ auth_users }}'
|
|
|
|
- name: Add empty authorized key file (with the correct permissions)
|
|
file: path="{{ home }}/.ssh/authorized_keys" owner="{{ user }}" group="{{ group }}" mode=0600 state=file
|
|
|
|
- name: Create pools for all hosts
|
|
file: path="{{ pool }}/{{ item.host }}" owner="{{ user }}" group="{{ group }}" mode=0700 state=directory
|
|
with_items:
|
|
- '{{ auth_users }}'
|
|
|
|
- name: Check if repositories need to be initialized (i.e. readme not exists)
|
|
stat: path="{{ pool }}/{{ item.host }}/README"
|
|
register: repoinit
|
|
with_items:
|
|
- '{{ auth_users }}'
|
|
|
|
- name: Initialize the repositories
|
|
command: /usr/bin/sudo -u "{{ user }}" /usr/local/bin/borg init -e none "{{ pool }}/{{ item.item.host }}"
|
|
when: item.stat.exists == False
|
|
with_items:
|
|
- '{{ repoinit.results }}'
|