diff --git a/plugins/modules/docker_network.py b/plugins/modules/docker_network.py index 00b79cd2d..8523d0552 100644 --- a/plugins/modules/docker_network.py +++ b/plugins/modules/docker_network.py @@ -96,6 +96,12 @@ - Enable IPv6 networking. type: bool + ingress: + description: + - Enable Swarm routing-mesh. + version_added: 4.2.0 + type: bool + ipam_driver: description: - Specify an IPAM driver. @@ -309,6 +315,7 @@ def __init__(self, client): self.labels = None self.debug = None self.enable_ipv6 = None + self.ingress = None self.scope = None self.attachable = None @@ -493,6 +500,11 @@ def has_different_config(self, net): parameter=self.parameters.enable_ipv6, active=net.get('EnableIPv6', False)) + if self.parameters.ingress is not None and self.parameters.ingress != net.get('Ingress', False): + differences.add('ingress', + parameter=self.parameters.ingress, + active=net.get('Ingress', False)) + if self.parameters.internal is not None and self.parameters.internal != net.get('Internal', False): differences.add('internal', parameter=self.parameters.internal, @@ -537,6 +549,8 @@ def create_network(self): data['ConfigFrom'] = {'Network': self.parameters.config_from} if self.parameters.enable_ipv6: data['EnableIPv6'] = True + if self.parameters.ingress: + data['Ingress'] = True if self.parameters.internal: data['Internal'] = True if self.parameters.scope is not None: @@ -679,6 +693,7 @@ def main(): aux_addresses=dict(type='dict'), )), enable_ipv6=dict(type='bool'), + ingress=dict(type='bool'), internal=dict(type='bool'), labels=dict(type='dict', default={}), debug=dict(type='bool', default=False), diff --git a/tests/integration/targets/docker_network/tasks/tests/ingress.yml b/tests/integration/targets/docker_network/tasks/tests/ingress.yml new file mode 100644 index 000000000..ba1ad6c30 --- /dev/null +++ b/tests/integration/targets/docker_network/tasks/tests/ingress.yml @@ -0,0 +1,66 @@ +--- +# Copyright (c) Ansible Project +# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) +# SPDX-License-Identifier: GPL-3.0-or-later + +- name: Registering network name + set_fact: + nname_1: "{{ name_prefix ~ '-network-1' }}" +- name: Registering network name + set_fact: + dnetworks: "{{ dnetworks + [nname_1] }}" + +#################################################################### +## overlay ######################################################### +#################################################################### + +- block: + # Ingress networks require swarm initialization before they'll work + - name: swarm + docker_swarm: + state: present + advertise_addr: "{{ ansible_default_ipv4.address | default('127.0.0.1') }}" + + - name: cleanup default swarm ingress network + docker_network: + name: ingress + state: absent + + - name: ingress + docker_network: + name: "{{ nname_1 }}" + driver: overlay + ingress: true + register: ingress_1 + + - name: ingress (idempotency) + docker_network: + name: "{{ nname_1 }}" + driver: overlay + ingress: true + register: ingress_2 + + - name: ingress (change) + docker_network: + name: "{{ nname_1 }}" + driver: overlay + ingress: false + register: ingress_3 + + - name: cleanup network + docker_network: + name: "{{ nname_1 }}" + state: absent + force: true + + - assert: + that: + - ingress_1 is changed + - ingress_2 is not changed + - ingress_3 is changed + + always: + - name: cleanup swarm + docker_swarm: + state: absent + force: true