---
# ----------
# /etc/motd
# ----------

- name: (motd.yml) Check if /etc/motd.ORIG exist
  ansible.builtin.stat:
    path: /etc/motd.ORIG
  register: common_motd_orig_exist

- name: (motd.yml) Check if /etc/motd exist
  ansible.builtin.stat:
    path: /etc/motd
  register: common_motd_exist

- name: (motd.yml)  Backup existing file /etc/motd
  ansible.builtin.command: cp -a /etc/motd /etc/motd.ORIG
  changed_when: true
  when:
    - common_motd_exist.stat.exists
    - not common_motd_orig_exist.stat.exists

- name: (motd.yml) create /etc/motd
  ansible.builtin.shell: figlet {{ ansible_hostname }} > /etc/motd
  changed_when: true
  when: not common_motd_orig_exist.stat.exists
