---
- block:
  - name: Add custom welcome message
    copy:
      src: "ssh_welcome_message"
      dest: "/etc/ssh/sshd-banner"
      owner: root
      group: root
      mode: '644'
    notify: Restart sshd

  - name: Add trusted user ca keys
    copy:
      src: trusted_user_ca_public_key
      dest: "/etc/ssh/trusted_user_ca.pub"
      owner: root
      group: root
      mode: '644'
    notify: Restart sshd

  - name: Check for robot pairing CA
    stat:
      path: /etc/ssh/robot_pairing_ca.pub
    register: robot_pairing_ca

  - name: Add robot pairing CA
    shell: "cat /etc/ssh/robot_pairing_ca.pub >> /etc/ssh/trusted_user_ca.pub"
    args:
      executable: /bin/bash
    when: robot_pairing_ca.stat.exists
    notify: Restart sshd

  - name: Copy the sshd config file
    template:
      src:  "sshd_config_{{ os_release_name }}"
      dest: /etc/ssh/sshd_config
      owner: root
      group: root
      mode: '600'
    notify: Restart sshd

  - name: Copy the ssh config file
    template:
      src:  ssh_config
      dest: /etc/ssh/ssh_config
      mode: '644'
      owner: root
      group: root
    notify: Restart sshd

  become: yes
