From 14df9121a860f7315d6a59b3eec763c614adf359 Mon Sep 17 00:00:00 2001 From: Andrea Dell'Amico Date: Thu, 14 Feb 2019 15:15:54 +0100 Subject: [PATCH] Manage motd on both deb/ubuntu and centos installations. --- motd/defaults/main.yml | 8 ++++++++ motd/tasks/deb_motd.yml | 17 +++++++++++++++++ motd/tasks/main.yml | 6 ++++++ motd/tasks/rh_motd.yml | 6 ++++++ motd/templates/motd.j2 | 2 ++ motd/templates/update_motd.j2 | 5 +++++ 6 files changed, 44 insertions(+) create mode 100644 motd/defaults/main.yml create mode 100644 motd/tasks/deb_motd.yml create mode 100644 motd/tasks/main.yml create mode 100644 motd/tasks/rh_motd.yml create mode 100644 motd/templates/motd.j2 create mode 100644 motd/templates/update_motd.j2 diff --git a/motd/defaults/main.yml b/motd/defaults/main.yml new file mode 100644 index 00000000..c04b27f4 --- /dev/null +++ b/motd/defaults/main.yml @@ -0,0 +1,8 @@ +--- +motd_setup: True + +motd_additional_text: "\nThis host runs services\n" + +deb_motd_packages: + - update-notifier-common + - landscape-common \ No newline at end of file diff --git a/motd/tasks/deb_motd.yml b/motd/tasks/deb_motd.yml new file mode 100644 index 00000000..72367a38 --- /dev/null +++ b/motd/tasks/deb_motd.yml @@ -0,0 +1,17 @@ +--- +- block: + - name: Install the packages that manage the dynamic motd file on debian based distributions + apt: pkg={{ deb_motd_packages }} state=present update_cache=yes cache_valid_time=3600 + register: motd_pkgs + + - name: Install our motd template file on debian based distributions + template: src=motd.j2 dest=/etc/static-motd owner=root group=root mode=0644 + + - name: Install the dynamic merge script of the motd file on debian based distributions + template: src=update_motd.j2 dest=/etc/update-motd.d/05-motd-message owner=root group=root mode=0755 + + - name: Initialise the motd prompt on debian based distributions + command: run-parts --lsbsysinit /etc/update-motd.d > /run/motd.dynamic + when: motd_pkgs is changed + + tags: motd diff --git a/motd/tasks/main.yml b/motd/tasks/main.yml new file mode 100644 index 00000000..89caf1d0 --- /dev/null +++ b/motd/tasks/main.yml @@ -0,0 +1,6 @@ +--- +- import_tasks: deb_motd.yml + when: ansible_distribution_file_variety == "Debian" + +- import_tasks: rh_motd.yml + when: ansible_distribution_file_variety == "RedHat" diff --git a/motd/tasks/rh_motd.yml b/motd/tasks/rh_motd.yml new file mode 100644 index 00000000..ba773d88 --- /dev/null +++ b/motd/tasks/rh_motd.yml @@ -0,0 +1,6 @@ +- block: + - name: Install our motd template file on RH/CentOS based distributions + template: src=motd.j2 dest=/etc/motd owner=root group=root mode=0644 + + tags: motd + \ No newline at end of file diff --git a/motd/templates/motd.j2 b/motd/templates/motd.j2 new file mode 100644 index 00000000..b4fd8e86 --- /dev/null +++ b/motd/templates/motd.j2 @@ -0,0 +1,2 @@ + +{{ motd_additional_text }} diff --git a/motd/templates/update_motd.j2 b/motd/templates/update_motd.j2 new file mode 100644 index 00000000..95bff2d9 --- /dev/null +++ b/motd/templates/update_motd.j2 @@ -0,0 +1,5 @@ +#!/bin/sh + +cat /etc/static-motd + +exit 0