homeserver/roles/mgrote_munin_server/tasks/main.yml

149 lines
4.1 KiB
YAML
Raw Normal View History

2024-08-12 12:46:22 +02:00
---
- name: ensure packages are installed
become: true
ansible.builtin.package:
name: "{{ munin_packages }}"
state: present
2024-08-12 13:01:35 +02:00
- name: Ensure needed dirs exists
ansible.builtin.file:
path: "{{ item }}"
state: directory
mode: '0755'
owner: munin
group: munin
loop: "{{ munin_dirs }}"
2024-08-12 12:53:37 +02:00
- name: Template apache config
ansible.builtin.template:
src: /etc/munin/apache.conf
2024-08-12 12:47:43 +02:00
dest: /etc/apache2/sites-available/000-default.conf
2024-08-12 13:00:45 +02:00
- name: Template logrotate config
ansible.builtin.template:
src: logrotate
dest: /etc/logrotate.d/munin
2024-08-12 12:59:52 +02:00
# (chfn -f 'munin' root) ??? TODO
2024-08-12 12:46:22 +02:00
2024-08-12 12:59:52 +02:00
- name: Enable fgcid
ansible.builtin.command: /usr/sbin/a2enmod fcgid # TODO CHANGED/when
2024-08-12 12:46:22 +02:00
2024-08-12 12:59:52 +02:00
- name: Template munin-server plugins
ansible.builtin.template:
src: "{{ item }}"
dest: "/etc/munin/plugins/{{ item }}"
mode: '0755'
loop: "{{ munin_server_plugins }}"
2024-08-12 12:46:22 +02:00
2024-08-12 13:06:55 +02:00
- name: Template munin config
ansible.builtin.template:
src: munin.conf
dest: /etc/munin/munin.conf
mode: '0644'
owner: munin
group: munin
2024-08-12 12:46:22 +02:00
2024-08-12 13:10:59 +02:00
- name: Enable or disable the munin cron job.
lineinfile:
dest: /etc/cron.d/munin
state: "{{ munin_cron_job }}"
regexp: "^\\*/5 \\* \\* \\* \\*"
line: "*/5 * * * * munin if [ -x /usr/bin/munin-cron ]; then /usr/bin/munin-cron; fi"
create: true
mode: 0644
2024-08-12 13:06:55 +02:00
# TODO mail config? wie senden?
# COPY munin_mail.conf /etc/munin/munin-conf.d/munin_mail.conf
2024-08-12 13:10:59 +02:00
# configure mail notification
if [[ -n "$MAILCONTACT" && -n "$MAILSERVER" && -n "$MAILPORT" && -n "$MAILUSER" && -n "$MAILPASSWORD" && -n "$MAILDOMAIN" ]] ; then
MAILCONTACT=${MAILCONTACT:="contact@domain.test"}
sed -i "s/mailcontact/$MAILCONTACT/g" /etc/ssmtp/ssmtp.conf
sed -i "s/mailcontact/$MAILCONTACT/g" /etc/munin/munin-conf.d/munin_mail.conf
MAILSERVER=${MAILSERVER:="mail.domain.test"}
sed -i "s/mailserver/$MAILSERVER/g" /etc/ssmtp/ssmtp.conf
sed -i "s/mailserver/$MAILSERVER/g" /etc/ssmtp/revaliases
MAILPORT=${MAILPORT:="25"}
sed -i "s/mailport/$MAILPORT/g" /etc/ssmtp/ssmtp.conf
sed -i "s/mailport/$MAILPORT/g" /etc/ssmtp/revaliases
MAILUSER=${MAILUSER:="alert@domain.test"}
sed -i "s/mailuser/$MAILUSER/g" /etc/ssmtp/ssmtp.conf
MAILFROM=${MAILFROM:="munin@domain.test"}
sed -i "s/mailfrom/$MAILFROM/g" /etc/ssmtp/revaliases
MAILPASSWORD=${MAILPASSWORD:="XXXXXXXXX"}
sed -i "s/mailpassword/$MAILPASSWORD/g" /etc/ssmtp/ssmtp.conf
MAILDOMAIN=${MAILDOMAIN:="domain.test"}
sed -i "s/maildomain/$MAILDOMAIN/g" /etc/ssmtp/ssmtp.conf
sed -i "s/mailhost/$MAILDOMAIN/g" /etc/ssmtp/ssmtp.conf
MAILNAME=${MAILNAME:="Munin"}
sed -i "s/munin application user/$MAILNAME/g" /etc/passwd
else
rm /etc/munin/munin-conf.d/munin_mail.conf /etc/ssmtp/ssmtp.conf
fi
# cronjoib? timer? TODO
# sed -i "s/\*\/5/\*\/5/g" /etc/cron.d/munin kommt imho aus paket
# generate node list
NODES=${NODES:-}
for NODE in $NODES
do
NAME=`echo $NODE | cut -d ':' -f1`
HOST=`echo $NODE | cut -d ':' -f2`
grep -q "${HOST}$" /etc/munin/munin.conf || cat << EOF >> /etc/munin/munin.conf
[$NAME]
address $HOST
use_node_name yes
EOF
done
# placeholder html to prevent permission error
if [ ! -f /var/cache/munin/www/index.html ]; then
cat << EOF > /var/cache/munin/www/index.html
<html>
<head>
<title>Munin</title>
</head>
<body>
Munin has not run yet. Please try again in a few moments.
</body>
</html>
EOF
chown -R munin: /var/cache/munin/www/index.html
fi
# ensure munin folder exist and have right permission
mkdir -p /var/lib/munin/cgi-tmp /var/cache/munin/www
chown -R munin:munin /var/lib/munin /var/cache/munin
chmod -R ugo+rw /var/lib/munin/cgi-tmp
chown munin:munin /var/log/munin/munin-graph.log
chown munin:munin /var/log/munin/munin-limits.log
chown munin:munin /var/log/munin/munin-html.log
# start cron
/usr/sbin/cron &
# start local munin-node
/usr/sbin/munin-node > /dev/null 2>&1 &
2024-08-12 12:46:22 +02:00
2024-08-12 13:10:59 +02:00
# confirm nodes
echo "Using the following munin nodes:"
echo " $THISNODENAME"
echo " $NODES"
2024-08-12 12:46:22 +02:00
2024-08-12 13:10:59 +02:00
# start apache
/usr/sbin/apache2ctl start
2024-08-12 13:00:45 +02:00
2024-08-12 13:10:59 +02:00
# display logs
touch /var/log/munin/munin-update.log
chown munin:munin /var/log/munin/munin-update.log
tail -f /var/log/munin/munin-*.log