aboutsummaryrefslogtreecommitdiffstats
path: root/roles/sshd/tasks/main.yml
blob: 1e1493d05e9abecb2e9bd98ef3a21c00f0393ad3 (plain) (blame)
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

# sshd ~~ roles/sshd/tasks/main.yml
# Create sshd configuration and restart daemon

---

- name: generate sshd configuration
  template:
    src: templates/sshd_config.j2
    dest: /etc/ssh/sshd_config
    owner: "{{ user_root }}"
    group: "{{ group_root }}"
    mode: 0644

- name: get ssh keys for all user
  find:
    paths: "{{ inventory_dir }}/files/pubkeys"
    pattern: "*.pub"
    recurse: true
    file_type: link
  register: keys
  delegate_to: localhost

- name: show pubkeys
  debug:
    msg: |
      {% for key in keys.files %}
      {{ key.path }}
      {% endfor %}

- name: synchronize ssh keys
  authorized_key:
    user: "{{ item.path | dirname | basename }}"
    state: present
    key: "{{ lookup('file', item.path) }}"
  ignore_errors: true
  loop: "{{ keys.files }}"

- name: chown ssh file to correct user
  file:
    path: "/home/{{ item.path | dirname | basename }}/.ssh/authorized_keys"
    owner: "{{ item.path | dirname | basename }}"
    mode: 0600
  ignore_errors: true
  loop: "{{ keys.files }}"

- name: restart sshd
  service:
    name: sshd
    state: restarted

- name: check ssh connection
  wait_for:
    port: 22
    delay: 1
    state: started
remember that computers suck.