aboutsummaryrefslogtreecommitdiff
path: root/tasks/main.yml
blob: 2fa10e91dce2574de188b03b6eeb41ca4c6ec900 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
- name: "Setup passwordless authentication from {{ ssh_relay_accessing_host }} to {{ ssh_relay_accessed_host }}"
  block:
    - name: Deploy ssh-relay ssh pivate key
      delegate_to: "{{ ssh_relay_accessing_host }}"
      ansible.builtin.copy:
        src: "~/.ssh/{{ relay_ssh_key_name }}"
        dest: "~/.ssh/{{ relay_ssh_key_name }}"
        # Make the ssh private key only readable/writable for its owner
        mode: '600'
      no_log: true

    - name: Authorize the ssh-relay key on the relay host
      delegate_to: "{{ ssh_relay_accessed_host }}"
      run_once: true
      authorized_key:
        user: "{{ ssh_relay_accessed_user }}"
        state: present
        key: "{{ lookup('file', relay_ssh_key_name + '.pub') }}"
        key_options: "command=\"echo 'This identity can only be used for port forwarding'\",restrict,port-forwarding"

- name: "Authorize the relay host on the {{ ssh_relay_accessing_host }}"
  tags:
    - ssh
  ansible.builtin.include_role:
    name: ssh_authorize_host
    apply:
      delegate_to: "{{ ssh_relay_accessing_host }}"
  vars:
    ssh_hostname: "{{ ssh_relay_accessed_host }}"