diff --git a/tasks/01_install.yml b/tasks/01_install.yml index e4478d9..5844b7a 100644 --- a/tasks/01_install.yml +++ b/tasks/01_install.yml @@ -19,6 +19,7 @@ - "{{ ansible_lsb.id }}.yml" - name: Install general dependencies (openssh) + when: borg_install_method != "docker" ansible.builtin.package: name: "{{ borg_dep_packages }}" state: present diff --git a/tasks/02_user_management.yml b/tasks/02_user_management.yml index fb396d1..e1ba985 100644 --- a/tasks/02_user_management.yml +++ b/tasks/02_user_management.yml @@ -1,25 +1,29 @@ --- # So in different positions in that role we need the user home # Since we cannot be sure that this FSH is compatible we will determine it. -- name: Get home dir +- name: User management when: - - borg_user == "root" + - borg_install_method != "docker" block: - - name: Get home if borg_user == "root" - ansible.builtin.user: - name: "{{ borg_user }}" - state: present - register: user_info - changed_when: false - check_mode: true # Important, otherwise user will be created + - name: Get home dir + when: + - borg_user == "root" + block: + - name: Get home if borg_user == "root" + ansible.builtin.user: + name: "{{ borg_user }}" + state: present + register: user_info + changed_when: false + check_mode: true # Important, otherwise user will be created - - name: Save the user_info, we need them for the home_dir - ansible.builtin.set_fact: - backup_user_info: "{{ user_info }}" + - name: Save the user_info, we need them for the home_dir + ansible.builtin.set_fact: + backup_user_info: "{{ user_info }}" -- name: Create user if borg_user != "root" - when: - - borg_user != "root" - ansible.builtin.include_tasks: - file: noauto_create_backup_user_and_group.yml + - name: Create user if borg_user != "root" + when: + - borg_user != "root" + ansible.builtin.include_tasks: + file: noauto_create_backup_user_and_group.yml ... diff --git a/tasks/03_create_key.yml b/tasks/03_create_key.yml index 3827d77..9ceffbf 100644 --- a/tasks/03_create_key.yml +++ b/tasks/03_create_key.yml @@ -1,28 +1,50 @@ --- -- name: Create SSH key (if neeeded) for {{ borg_user }} +- name: Create ssh key + when: + - borg_install_method != "docker" 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: Create SSH key (if needed) 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 }}" + - name: Generate an OpenSSH keypair + when: not borg_ssh_private_key + community.crypto.openssh_keypair: + path: "{{ borg_ssh_key_file_path }}" + mode: "0600" + type: "{{ borg_ssh_key_type }}" + owner: "{{ borg_user }}" + group: "{{ borg_group }}" - - name: Read SSH key - ansible.builtin.slurp: - src: "{{ borg_ssh_key_file_path }}.pub" - register: backup_local_ssh_key + - name: Generate public key from private key content # Also ensure priv key content is sound + when: borg_ssh_private_key + delegate_to: localhost + community.crypto.openssl_publickey: + path: "{{ borg_ssh_key_file_path }}.pub" + privatekey_content: "{{ borg_ssh_private_key }}" + register: public_key - - name: Print key - ansible.builtin.debug: - msg: "The generated key is: {{ backup_local_ssh_key['content'] | b64decode }}" + - name: Copy provided OpenSSH private key + when: public_key.succeeded + ansible.builtin.copy: + content: "{{ borg_ssh_private_key }}" + dest: "{{ borg_ssh_key_file_path }}" + mode: "0600" + owner: "{{ borg_user }}" + group: "{{ borg_group }}" + + - name: Read SSH key + ansible.builtin.slurp: + src: "{{ borg_ssh_key_file_path }}.pub" + register: backup_local_ssh_key + + - name: Print key + ansible.builtin.debug: + msg: "The generated key is: {{ backup_local_ssh_key['content'] | b64decode }}" ... diff --git a/tasks/05_configure.yml b/tasks/05_configure.yml index e055c20..c517458 100755 --- a/tasks/05_configure.yml +++ b/tasks/05_configure.yml @@ -1,5 +1,7 @@ --- - name: Add Borgmatic config file + when: + - borg_install_method != "docker" block: - name: Ensure /etc/borgmatic exists ansible.builtin.file: diff --git a/tasks/07_install_timer.yml b/tasks/07_install_timer.yml index 4ca6afa..18e499d 100644 --- a/tasks/07_install_timer.yml +++ b/tasks/07_install_timer.yml @@ -2,6 +2,7 @@ - name: Install timer to run Borgmatic when: - borgmatic_timer is defined and borgmatic_timer | length > 0 + - borg_install_method != "docker" block: - name: Start timer install script ansible.builtin.include_tasks: