diff --git a/roles/common/tasks/main.yml b/roles/common/tasks/main.yml index 979a085..3187c55 100644 --- a/roles/common/tasks/main.yml +++ b/roles/common/tasks/main.yml @@ -33,6 +33,7 @@ copy: src: "motd-news" dest: "/etc/default/motd-news" + tags: [ motd ] - name: Disable default update-motd tasks file: path: "/etc/update-motd.d/{{ item }}" @@ -49,7 +50,14 @@ - "92-unattended-upgrades" - "95-hwe-eol" - "97-overlayroot" + tags: [ motd ] when: ansible_distribution == "Ubuntu" + - name: Add update-motd tasks + template: + src: 50-ansible-motd.sh + dest: /etc/update-motd.d/50-ansible + mode: "0755" + tags: [ motd ] - name: Configure Ansible user include_tasks: ansibleuser.yml become: yes diff --git a/roles/common/templates/50-ansible-motd.sh b/roles/common/templates/50-ansible-motd.sh new file mode 100755 index 0000000..6d13fe3 --- /dev/null +++ b/roles/common/templates/50-ansible-motd.sh @@ -0,0 +1,34 @@ +#! /bin/sh +# +# 50-ansible-motd.sh +# Copyright (C) 2020 Vintage Salt +# +# Distributed under terms of the MIT license. +# + +# Service statuses +if command -v systemctl > /dev/null 2>&1; then + len=20 + printf "Services:\n" + for unit in \ + 9iron-backup \ + ansible-pull + do + systemctl status $unit > /dev/null 2>&1 + case $? in + 0) + printf " * %-${len}.${len}s\e[32mRunning\e[0m\n" $unit + ;; + 1|2) + printf " * %-${len}.${len}s\e[31mDead\e[0m\n" $unit + ;; + 3) + printf " * %-${len}.${len}s\e[34mExited\e[0m\n" $unit + ;; + *) + printf " * %-${len}.${len}s\e[33mUnknown\e[0m\n" "$unit" + ;; + esac + done +fi +