- name: Set banner
  become: "{{ false if inventory_hostname == 'nas.home.lan' else true }}"
  block:
    - name: Install packages
      ansible.builtin.apt:
        name:
          - figlet
          - toilet

    - name: Create Banner
      ansible.builtin.command: |
        figlet -c {{ (inventory_hostname | split('.'))[0] }} -f slant
      register: logo
      changed_when: "logo.rc == 0"

    - name: Creating a file with content
      ansible.builtin.copy:
        dest: "/etc/motd"
        content: |
          {{ logo.stdout }}
        owner: 0
        group: 0
        mode: "0777"

    - name: Reconfigure sshd
      ansible.builtin.lineinfile:
        path: /etc/ssh/sshd_config
        regexp: "^Banner.* "
        line: "#Banner /etc/banner"

    - name: Reconfigure sshd
      ansible.builtin.lineinfile:
        path: /etc/ssh/sshd_config
        regexp: "^#PrintLastLog.* "
        line: "PrintLastLog no"

    - name: Sshd
      ansible.builtin.service:
        name: ssh.service
        state: restarted
