aboutsummaryrefslogblamecommitdiffstats
path: root/roles/sshd/tasks/main.yml
blob: 8c032eee68b1d2e029ba17d4790edbed22d1521c (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14













                                              




















                                                









                            

# 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:
    var: keys

- name: synchronize ssh keys
  ansible.posix.authorized_key:
    user: "{{ item.path | dirname | basename }}"
    state: present
    key: "{{ lookup('file', item.path) }}"
  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.