From 36658addcd688074eb9062ee71f16ed8a0bcad1b Mon Sep 17 00:00:00 2001 From: Slavi Pantaleev Date: Mon, 15 Oct 2018 07:42:26 +0300 Subject: [PATCH] Work around buggy docker_network sometimes failing to work If a network like `matrix-whatever` already exists for some reason, the `docker_network` module would not create our `matrix` network. Working around it by avoiding `docker_network` and doing it manually. Fixes Github issue #12 --- roles/matrix-server/tasks/setup_main.yml | 28 ++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/roles/matrix-server/tasks/setup_main.yml b/roles/matrix-server/tasks/setup_main.yml index 71a6b96c8..a4da6986b 100644 --- a/roles/matrix-server/tasks/setup_main.yml +++ b/roles/matrix-server/tasks/setup_main.yml @@ -30,7 +30,27 @@ - "{{ matrix_base_data_path }}" - "{{ matrix_synapse_base_path }}" -- name: Ensure Matrix network is created in Docker - docker_network: - name: "{{ matrix_docker_network }}" - driver: bridge +# `docker_network` doesn't work as expected when the given network +# is a substring of a network that already exists. +# +# See: +# - https://github.com/spantaleev/matrix-docker-ansible-deploy/issues/12 +# - https://github.com/ansible/ansible/issues/32926 +# +# Due to that, we employ a workaround below. +# +# - name: Ensure Matrix network is created in Docker +# docker_network: +# name: "{{ matrix_docker_network }}" +# driver: bridge + +- name: Check existence of Matrix network in Docker + shell: + cmd: "docker network ls -q --filter='name=^{{ matrix_docker_network }}$'" + register: result_check_docker_network + changed_when: false + +- name: Create Matrix network in Docker + shell: + cmd: "docker network create --driver=bridge {{ matrix_docker_network }}" + when: "result_check_docker_network.stdout == ''" \ No newline at end of file