mirror of
https://github.com/borgbase/ansible-role-borgbackup.git
synced 2026-03-19 02:22:23 +01:00
Add when conditions to skip SSH key generation and borgmatic config creation when corresponding variables are empty. This allows users to install only borg/borgmatic without configuring them. Closes #188 #152 Co-Authored-By: Leonidas Avdelas <avdelasleonidas@gmail.com>
33 lines
1.1 KiB
YAML
33 lines
1.1 KiB
YAML
---
|
|
- name: Create SSH key (if neeeded) for {{ borg_user }}
|
|
block:
|
|
- name: Ensure directory exist
|
|
ansible.builtin.file:
|
|
path: "{{ backup_user_info.home }}/.ssh/"
|
|
state: directory
|
|
mode: "0700"
|
|
owner: "{{ borg_user }}"
|
|
group: "{{ borg_group }}"
|
|
|
|
- name: Generate an OpenSSH keypair
|
|
community.crypto.openssh_keypair:
|
|
path: "{{ borg_ssh_key_file_path }}"
|
|
mode: "0600"
|
|
type: "{{ borg_ssh_key_type }}"
|
|
owner: "{{ borg_user }}"
|
|
group: "{{ borg_group }}"
|
|
comment: "{{ borg_ssh_key_comment }}"
|
|
when: borg_ssh_key_file_path is defined and borg_ssh_key_file_path | length > 0
|
|
|
|
- name: Read SSH key
|
|
ansible.builtin.slurp:
|
|
src: "{{ borg_ssh_key_file_path }}.pub"
|
|
register: backup_local_ssh_key
|
|
when: borg_ssh_key_file_path is defined and borg_ssh_key_file_path | length > 0
|
|
|
|
- name: Print key
|
|
ansible.builtin.debug:
|
|
msg: "The generated key is: {{ backup_local_ssh_key['content'] | b64decode }}"
|
|
when: borg_ssh_key_file_path is defined and borg_ssh_key_file_path | length > 0
|
|
...
|