---
- name: "Backup storage server | create system user"
  become: yes
  ansible.builtin.user:
    name: '{{ system_user }}'
    comment: "user for backup"
    shell: /bin/bash
  register: create_user

- name: "Create .ssh dir"
  become: yes
  file:
    path: '/home/{{ system_user }}/.ssh/'
    mode: '0700'
    owner: '{{ system_user }}'
    group: '{{ system_user }}'
    state: directory

- name: "Providing SSH priv.key"
  no_log: true
  become: yes
  copy:
    dest: '/home/{{ system_user }}/.ssh/id_rsa'
    mode: '0400'
    owner: '{{ system_user }}'
    group: '{{ system_user }}'
    content: '{{ backup_user_ssh_privkey_vault }}'

- name: "Providing rsync script"
  become: yes
  copy:
    src: '{{ item }}'
    dest: '/home/{{ system_user }}/{{ item }}'
    mode: '0755'
    owner: '{{ system_user }}'
    group: '{{ system_user }}'
  with_items:
    - pull_remote_backups.sh
    - push_backups_to_restore_server.sh

- name: Touch metrics.prom is not exists
  file:
    path: "/home/{{ system_user }}/metrics.prom"
    state: touch
    mode: '0744'
    owner: '{{ system_user }}'
    group: '{{ system_user }}'

- name: Create symbolic link for node_exporter text metrics
  file:
    src: "/home/{{ system_user }}/metrics.prom"
    dest: "/var/lib/prometheus/node-exporter/offsite-metrics.prom"
    state: link

