diff --git a/tasks/onserver.yml b/tasks/onserver.yml index caf2b761609d73c1d2caa60a7f232096d799fc91..df704598c065571572cb3a5cafcb6938440e1a10 100644 --- a/tasks/onserver.yml +++ b/tasks/onserver.yml @@ -2,11 +2,33 @@ - name: Create Group group: name: "borgbackup" + ignore_errors: yes + register: create_group + +- name: Create Group Fallback + command: addgroup borgbackup + register: create_group_fallback + failed_when: + - create_group_fallback.rc != 0 + - "'in use' not in create_group_fallback.stderr" + changed_when: create_group_fallback.rc == 0 + when: create_group.failed - name: Create User user: name: "borgbackup" group: "borgbackup" + ignore_errors: yes + register: create_user + +- name: Create User Fallback + command: adduser -D -G borgbackup borgbackup + register: create_user_fallback + failed_when: + - create_user_fallback.rc != 0 + - "'in use' not in create_user_fallback.stderr" + changed_when: create_user_fallback.rc == 0 + when: create_user.failed - name: Set permissions file: @@ -16,11 +38,11 @@ mode: 0700 state: directory with_items: - - "{{ borgbackup_pool }}" - - "{{ borgbackup_pool }}/{{ borgbackup_source_host }}" + - "{{ hostvars[borgbackup_target_host]['borgbackup_pool'] }}" + - "{{ hostvars[borgbackup_target_host]['borgbackup_pool'] }}/{{ borgbackup_source_host }}" - name: Add public key authorized_key: user: "borgbackup" key: "{{borgbackup_source_key}}" - key_options: "command=\"cd {{ borgbackup_pool }}/{{ borgbackup_source_host }};borg serve --restrict-to-path {{ borgbackup_pool }}/{{ borgbackup_source_host }}\",restrict" + key_options: "command=\"cd {{ hostvars[borgbackup_target_host]['borgbackup_pool'] }}/{{ borgbackup_source_host }};borg serve --restrict-to-path {{ hostvars[borgbackup_target_host]['borgbackup_pool'] }}/{{ borgbackup_source_host }}\",restrict"