diff --git a/roles/post-install/files/motd-carp-state.sh b/roles/post-install/files/motd-carp-state.sh new file mode 100755 index 0000000..cc29db3 --- /dev/null +++ b/roles/post-install/files/motd-carp-state.sh @@ -0,0 +1,47 @@ +#!/bin/sh + +if [ ! -f /etc/motd-original ]; then + cp /etc/motd /etc/motd-original +fi + +if [ ! -f /tmp/carp.state ]; then + echo "unknown" > /tmp/carp.state +fi + +ifconfig carp0 | grep -q master +master=$? +ifconfig carp0 | grep -q backup +backup=$? + +if [ "$master" -eq 0 ]; then + if [ $(cat /tmp/carp.state) = "master" ]; then + # We already were master, no change + exit 0 + fi +cat /etc/motd-original - << EOF > /etc/motd + __ ______ _____________________ + / |/ / | / ___/_ __/ ____/ __ \ + / /|_/ / /| | \__ \ / / / __/ / /_/ / + / / / / ___ |___/ // / / /___/ _, _/ +/_/ /_/_/ |_/____//_/ /_____/_/ |_| + +EOF +echo "master" > /tmp/carp.state +elif [ "$backup" -eq 0 ]; then + if [ $(cat /tmp/carp.state) = "backup" ]; then + # We already were backup, no change + exit 0 + fi +cat /etc/motd-original - << EOF > /etc/motd + ____ ___ ________ ____ ______ + / __ )/ | / ____/ //_/ / / / __ \ + / __ / /| |/ / / ,< / / / / /_/ / + / /_/ / ___ / /___/ /| / /_/ / ____/ +/_____/_/ |_\____/_/ |_\____/_/ + +EOF +echo "backup" > /tmp/carp.state +else + # No CARP + exit 0 +fi diff --git a/roles/post-install/tasks/main.yml b/roles/post-install/tasks/main.yml index 1876037..40f494c 100644 --- a/roles/post-install/tasks/main.yml +++ b/roles/post-install/tasks/main.yml @@ -2,3 +2,4 @@ # tasks files - include: ldif.yml - include: update.yml +- include: motd.yml diff --git a/roles/post-install/tasks/motd.yml b/roles/post-install/tasks/motd.yml new file mode 100644 index 0000000..cbecbfd --- /dev/null +++ b/roles/post-install/tasks/motd.yml @@ -0,0 +1,14 @@ +--- +- name: Deploy dynamic motd script for CARP master or backup + copy: + src: motd-carp-state.sh + dest: /usr/share/scripts/motd-carp-state.sh + owner: root + group: wheel + mode: '0755' + +- name: Cron job for dynamic motd script is installed + cron: + name: dynamic motd for CARP + job: "/bin/sh /usr/share/scripts/motd-carp-state.sh" + disabled: true