---

- name: Setup pf_verbindungskonfiguration
  tags: pf_verbindungskonfiguration
  become: true
  block:

    - name: copy deploy_priv_key
      ansible.builtin.copy:
        src: "{{ inventory_hostname }}/gitea-keys/id_pf_verbindung_read_only_ed25519"
        dest: /home/perfact-useradmin/.ssh/id_pf_verbindung_read_only_ed25519
        owner: perfact-useradmin
        group: perfact-useradmin
        mode: '0600'

    - name: copy deploy_pub_key
      ansible.builtin.copy:
        src: "{{ inventory_hostname }}/gitea-keys/id_pf_verbindung_read_only_ed25519.pub"
        dest: /home/perfact-useradmin/.ssh/id_pf_verbindung_read_only_ed25519.pub
        owner: perfact-useradmin
        group: perfact-useradmin
        mode: '0644'

    - name: configure ssh client
      ansible.builtin.blockinfile:
        path: /home/perfact-useradmin/.ssh/config
        create: True
        block: |
          Host git.perfact.de
              Port 3022
              IdentityFile ~/.ssh/id_pf_verbindung_read_only_ed25519
        owner: perfact-useradmin
        group: perfact-useradmin
        mode: '0644'

    - name: Create directory
      ansible.builtin.file:
        path: /opt/perfact/pf_verbindungskonfiguration
        state: directory
        owner: perfact-useradmin
        group: perfact-useradmin
        mode: '0755'

    - name: Clone git repository
      become: true
      become_user: perfact-useradmin
      ansible.builtin.git:
        repo: ssh://git@git.perfact.de:3022/SystemTools/pf_verbindungskonfiguration.git
        dest: /opt/perfact/pf_verbindungskonfiguration
        # accept unkown hostkey:
        accept_hostkey: yes
