File size: 2,092 Bytes
53b59a6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5587ee3
 
 
 
 
 
 
 
 
 
 
 
 
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
---
- name: SSH Configuration Setup
  hosts: all
  become: yes
  vars_files:
    - ../vars/secrets.yml
  vars:
    ed25519_public_key: "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIARTYgwoPW+VpBofWGYuHIldh18EUo42PHF/e08Dzcyp admin key CS553"
  tasks:
    - name: Ensure .ssh directory exists
      file:
        path: /home/ubuntu/.ssh
        state: directory
        owner: ubuntu
        group: ubuntu
        mode: '0700'

    - name: Copy SSH keys
      copy:
        content: "{{ item.content }}"
        dest: "/home/ubuntu/.ssh/{{ item.filename }}"
        owner: ubuntu
        group: ubuntu
        mode: "{{ item.mode }}"
      loop:
        - { content: "{{ student_admin_private_key }}", filename: "student-admin-key", mode: "0600" }
        - { content: "{{ student_admin_public_key }}", filename: "student-admin-key.pub", mode: "0644" }
        - { content: "{{ ed25519_public_key }}", filename: "id_ed25519.pub", mode: "0644" }
        - { content: "{{ vault_ssh_private_key }}", filename: "id_ed25519", mode: "0600" }

    - name: Ensure SSH config file exists
      file:
        path: /home/ubuntu/.ssh/config
        state: touch
        owner: ubuntu
        group: ubuntu
        mode: '0600'

    - name: Add SSH config entries
      blockinfile:
        path: /home/ubuntu/.ssh/config
        block: "{{ item.block }}"
        marker: "# {mark} ANSIBLE MANAGED BLOCK FOR {{ item.name }}"
      loop:
        - name: TURING
          block: |
            Host turing.wpi.edu
              User jrmolnia
              Hostname turing.wpi.edu
              IdentityFile ~/.ssh/id_ed25519
        - name: APP SERVER
          block: |
            Host app
              Port 22018
              Hostname paffenroth-23.dyn.wpi.edu
              IdentityFile ~/.ssh/id_ed25519

    - name: Clear known_hosts file
      file:
        path: /home/ubuntu/.ssh/known_hosts
        state: absent
      
    - name: Create empty known_hosts file
      file:
        path: /home/ubuntu/.ssh/known_hosts
        state: touch
        owner: ubuntu
        group: ubuntu
        mode: '0644'