---
- name: Deploy custom motd
  template:
    src: "{{ item }}"
    dest: /etc/motd
    force: True
    owner: root
    group: root
    mode: "0644"
  loop: "{{ query('first_found', templates) }}"
  vars:
    templates:
      - "templates/motd/motd.{{ inventory_hostname }}.j2"
      - "templates/motd/motd.{{ host_group | default('all') }}.j2"
      - "templates/motd/motd.default.j2"
      - "templates/motd.default.j2"
  tags:
    - motd
