---
# main tasks for setting up motd dynamic shell header

- debug: var=ansible_nodename

- name: Install required packages
  apt:
    name: "{{ item }}"
    update_cache: yes
    cache_valid_time: 3600
    state: latest
  with_items:
    - lsb-release
    - figlet
#    - update-motd
    - lm-sensors

- name: Create /etc/update-motd.d/ if it does not exist
  ansible.builtin.file:
    path: /etc/update-motd.d/
    state: directory
    owner: root
    group: root
    mode: '0755'

- name: remove help text
  file:
    state: absent
    path: "{{ item }}"
  with_items:
    - /etc/update-motd.d/10-help-text
    - /etc/update-motd.d/51-cloudguest


- name: add new info
  copy:
    src: "{{ item.src }}"
    dest: /etc/update-motd.d/{{ item.dest }}
    mode: 755
  with_items:
    - { src: motd/hostname.sh, dest: 10-hostname }
    - { src: motd/systats.sh, dest: 11-sysstats}
