Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the ability to disable IPv6 #43

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ This role will use by default the `inventory_hostname` as mailcow hostname, this
| `mailcow__redirect_http_to_https` | if `yes`, all requests via HTTP will be redirected to HTTPS | `no` | also see https://mailcow.github.io/mailcow-dockerized-docs/u_e-80_to_443/ |
| `mailcow__config_acme_contact` | sets ACME_CONTACT in mailcow.conf | | |
| `mailcow__rspamd_clamd_servers` | configures the clamd server used by rspamd | `clamd:3310` | |
| `mailcow__ipv6` | if `no`, IPv6 will be disabled | `yes` | also see https://docs.mailcow.email/post_installation/firststeps-disable_ipv6/ |

## Usage

Expand Down
3 changes: 3 additions & 0 deletions defaults/main/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ mailcow__install_updates: yes
mailcow__redirect_http_to_https: no

mailcow__rspamd_clamd_servers: clamd:3310

# Enable IPv6 by default
mailcow__ipv6: yes
62 changes: 62 additions & 0 deletions tasks/ipv6_config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---

- name: Set required facts to disable IPv6
set_fact:
mailcow__ipv6_unbound: ["no"]
mailcow__ipv6_postfix_lines: "present"
when: not mailcow__ipv6 | bool

- name: Set required facts to enable IPv6
set_fact:
mailcow__ipv6_unbound: ["yes"]
mailcow__ipv6_postfix_lines: "absent"
when: mailcow__ipv6 | bool

- name: "Configure Unbound"
become: yes
replace:
path: "{{ mailcow__install_path }}/data/conf/unbound/unbound.conf"
regexp: "^(\\s*)do-ip6.*"
replace: "\\1do-ip6: {{ mailcow__ipv6_unbound[0] }}"
notify: Recreate mailcow

- name: "Make sure the extra.cf exists"
become: yes
file:
path: "{{ mailcow__install_path }}/data/conf/postfix/extra.cf"
state: touch
mode: 0644
owner: root
group: root
modification_time: preserve
access_time: preserve

- name: "Configure Postfix"
become: yes
lineinfile:
path: "{{ mailcow__install_path }}/data/conf/postfix/extra.cf"
regexp: "^{{ item.variable }}.*"
line: "{{ item.variable }} = {{ item.value }}"
state: "{{ mailcow__ipv6_postfix_lines }}"
notify: Recreate mailcow
loop:
- variable: "smtp_address_preference"
value: "ipv4"
- variable: "inet_protocols"
value: "ipv4"

- name: "Override docker-compose to disable IPv6"
become: yes
template:
src: docker-compose.override.yml.j2
dest: "{{ mailcow__install_path }}/docker-compose.override.yml"
notify: Recreate mailcow
when: not mailcow__ipv6 | bool

- name: "Make sure docker-compose.override.yml is removed"
become: yes
file:
path: "{{ mailcow__install_path }}/docker-compose.override.yml"
state: absent
notify: Recreate mailcow
when: mailcow__ipv6 | bool
4 changes: 4 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@
chdir: "{{ mailcow__install_path }}"
when: not mailcow_running.exists

- name: Set IPv6 to {{ mailcow__ipv6 }}
include_tasks: ipv6_config.yml
when: mailcow_running.exists

- name: Update mailcow
include_tasks: update.yml
when:
Expand Down
16 changes: 16 additions & 0 deletions templates/docker-compose.override.yml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
version: '2.1'
services:
ipv6nat-mailcow:
image: bash:latest
restart: "no"
entrypoint: ["echo", "ipv6nat disabled in compose.override.yml"]

networks:
mailcow-network:
enable_ipv6: false
ipam:
driver: default
config:
- subnet: ${IPV4_NETWORK:-172.22.1}.0/24
...