---
- name: Set MOTD on webservers
  hosts: managed_servers
  vars:
  become: true
  tasks:
    - name: Get MOTD
      ansible.builtin.command: cat /etc/motd
      register: motd

    - ansible.builtin.debug:
        var: motd.stdout_lines

    - name: Set MOTD
      ansible.builtin.copy:
        content: "{{ motd_block }}"
        dest: /etc/motd
      notify: 
        - Get changed MOTD
        - Display new MOTD

  handlers:
    - name: Get changed MOTD
      ansible.builtin.command: cat /etc/motd
      register: motd_changed

    - name: Display new MOTD
      ansible.builtin.debug:
        var: motd_changed.stdout_lines
...
