windmill-backup/playbooks/borg-client.yaml
Paul Belanger ee4386a976 Skip Initialize an empty borg repository when disabled
It is possible that borg-server is empty, if so, don't run init.

Also, fix CI issues due to bitrot.

Change-Id: I0f3a4a71ce095f6fe2916ab0151516849d6e07c7
Signed-off-by: Paul Belanger <pabelanger@redhat.com>
2020-03-19 20:26:55 -04:00

83 lines
2.7 KiB
YAML

# Copyright 2019 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
---
- name: Install borg-client
hosts: borg-client:!disabled
tasks:
- name: Setup windmill.borgbackup role
include_role:
name: windmill.borgbackup
vars:
borgbackup_task_manager:
- pre
- install
- name: Setup windmill.borgmatic role
include_role:
name: windmill.borgmatic
- name: Generage borgbackup SSH keys
become: true
become_user: borgbackup
command: ssh-keygen -b 4096 -t rsa -f ~/.ssh/id_rsa -q -N ""
args:
creates: ~/.ssh/id_rsa
- name: Add borg-server SSH host keys to known_hosts
become: true
become_user: borgbackup
known_hosts:
hash_host: true
key: "{{ hostvars[item].ansible_host }} ssh-ed25519 {{ hostvars[item].ansible_facts['ssh_host_key_ed25519_public'] }}"
name: "{{ hostvars[item].ansible_host }}"
with_inventory_hostnames:
- borg-server:!disabled
- name: Read SSH public key
become: true
become_user: borgbackup
slurp:
src: ~/.ssh/id_rsa.pub
register: borg_id_rsa_pub
- name: Setup windmill.ssh role
become: true
become_user: "borg_{{ inventory_hostname_short }}"
include_role:
name: windmill.ssh
apply:
delegate_to: "{{ item }}"
vars:
ssh_task_manager:
- config
ssh_authorized_keys_content: "restrict,command=\"cd ~/repos;{{ borgbackup_pip_virtualenv }}/bin/borg serve --restrict-to-path ~/repos\" {{ borg_id_rsa_pub.content | b64decode | trim }}"
ssh_key_private_content: false
ssh_key_public_content: false
ssh_known_hosts_content: false
ssh_user_home: "/opt/backups/borg_{{ inventory_hostname_short }}"
ssh_user_name: "borg_{{ inventory_hostname_short }}"
ssh_user_group: borgbackup
with_inventory_hostnames:
- borg-server:!disabled
- name: Initialize an empty borg repository
become: true
become_user: borgbackup
command: "{{ borgmatic_pip_virtualenv }}/bin/borgmatic --init --encryption repokey"
register: r
changed_when: r.stderr | length > 0
with_inventory_hostnames:
- borg-server:!disabled