copy:
dest: /etc/resolv.conf
content: "nameserver 127.0.0.2\n"
+# some providers need extra hacks to make our DNS persistent
+- name: install DNS-fix cronjob
+ template:
+ dest: /etc/cron.hourly/fix-dns
+ src: templates/fix-dns
--- /dev/null
+#!/bin/bash
+set -e
+
+# Fix for some providers messing with DNS settings
+if ! diff /etc/resolv.conf <(echo "nameserver 127.0.0.2") > /dev/null; then
+ echo "Someone messed up our DNS! Fixing it..."
+ echo "nameserver 127.0.0.2" > /etc/resolv.conf
+{% if 'email' in group_names %}
+ # Just to make sure postfix uses the new settings
+ systemctl restart postfix
+{% endif %}
+fi