bypasses tasks not relevent to docker install method

This commit is contained in:
jerome.gagnon 2023-10-09 00:18:54 +00:00
parent d9dfd5c6b5
commit d8c51011e7
5 changed files with 69 additions and 39 deletions

View File

@ -19,6 +19,7 @@
- "{{ ansible_lsb.id }}.yml" - "{{ ansible_lsb.id }}.yml"
- name: Install general dependencies (openssh) - name: Install general dependencies (openssh)
when: borg_install_method != "docker"
ansible.builtin.package: ansible.builtin.package:
name: "{{ borg_dep_packages }}" name: "{{ borg_dep_packages }}"
state: present state: present

View File

@ -1,25 +1,29 @@
--- ---
# So in different positions in that role we need the user home # 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. # Since we cannot be sure that this FSH is compatible we will determine it.
- name: Get home dir - name: User management
when: when:
- borg_user == "root" - borg_install_method != "docker"
block: block:
- name: Get home if borg_user == "root" - name: Get home dir
ansible.builtin.user: when:
name: "{{ borg_user }}" - borg_user == "root"
state: present block:
register: user_info - name: Get home if borg_user == "root"
changed_when: false ansible.builtin.user:
check_mode: true # Important, otherwise user will be created 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 - name: Save the user_info, we need them for the home_dir
ansible.builtin.set_fact: ansible.builtin.set_fact:
backup_user_info: "{{ user_info }}" backup_user_info: "{{ user_info }}"
- name: Create user if borg_user != "root" - name: Create user if borg_user != "root"
when: when:
- borg_user != "root" - borg_user != "root"
ansible.builtin.include_tasks: ansible.builtin.include_tasks:
file: noauto_create_backup_user_and_group.yml file: noauto_create_backup_user_and_group.yml
... ...

View File

@ -1,28 +1,50 @@
--- ---
- name: Create SSH key (if neeeded) for {{ borg_user }} - name: Create ssh key
when:
- borg_install_method != "docker"
block: block:
- name: Ensure directory exist - name: Create SSH key (if needed) for {{ borg_user }}
ansible.builtin.file: block:
path: "{{ backup_user_info.home }}/.ssh/" - name: Ensure directory exist
state: directory ansible.builtin.file:
mode: "0700" path: "{{ backup_user_info.home }}/.ssh/"
owner: "{{ borg_user }}" state: directory
group: "{{ borg_group }}" mode: "0700"
owner: "{{ borg_user }}"
group: "{{ borg_group }}"
- name: Generate an OpenSSH keypair - name: Generate an OpenSSH keypair
community.crypto.openssh_keypair: when: not borg_ssh_private_key
path: "{{ borg_ssh_key_file_path }}" community.crypto.openssh_keypair:
mode: "0600" path: "{{ borg_ssh_key_file_path }}"
type: "{{ borg_ssh_key_type }}" mode: "0600"
owner: "{{ borg_user }}" type: "{{ borg_ssh_key_type }}"
group: "{{ borg_group }}" owner: "{{ borg_user }}"
group: "{{ borg_group }}"
- name: Read SSH key - name: Generate public key from private key content # Also ensure priv key content is sound
ansible.builtin.slurp: when: borg_ssh_private_key
src: "{{ borg_ssh_key_file_path }}.pub" delegate_to: localhost
register: backup_local_ssh_key community.crypto.openssl_publickey:
path: "{{ borg_ssh_key_file_path }}.pub"
privatekey_content: "{{ borg_ssh_private_key }}"
register: public_key
- name: Print key - name: Copy provided OpenSSH private key
ansible.builtin.debug: when: public_key.succeeded
msg: "The generated key is: {{ backup_local_ssh_key['content'] | b64decode }}" 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 }}"
... ...

View File

@ -1,5 +1,7 @@
--- ---
- name: Add Borgmatic config file - name: Add Borgmatic config file
when:
- borg_install_method != "docker"
block: block:
- name: Ensure /etc/borgmatic exists - name: Ensure /etc/borgmatic exists
ansible.builtin.file: ansible.builtin.file:

View File

@ -2,6 +2,7 @@
- name: Install timer to run Borgmatic - name: Install timer to run Borgmatic
when: when:
- borgmatic_timer is defined and borgmatic_timer | length > 0 - borgmatic_timer is defined and borgmatic_timer | length > 0
- borg_install_method != "docker"
block: block:
- name: Start timer install script - name: Start timer install script
ansible.builtin.include_tasks: ansible.builtin.include_tasks: