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 'ingress' option to docker_network module #998

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
14 changes: 14 additions & 0 deletions plugins/modules/docker_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@
- Enable IPv6 networking.
type: bool

ingress:
description:
- Enable swarm routing-mesh.
MaxVorobyev marked this conversation as resolved.
Show resolved Hide resolved
type: bool

ipam_driver:
description:
- Specify an IPAM driver.
Expand Down Expand Up @@ -309,6 +314,7 @@ def __init__(self, client):
self.labels = None
self.debug = None
self.enable_ipv6 = None
self.ingress = None
self.scope = None
self.attachable = None

Expand Down Expand Up @@ -493,6 +499,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,
Expand Down Expand Up @@ -537,6 +548,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:
Expand Down Expand Up @@ -679,6 +692,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),
Expand Down
52 changes: 52 additions & 0 deletions tests/integration/targets/docker_network/tasks/tests/overlay.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,55 @@
docker_swarm:
state: absent
force: true

####################################################################
## ingress #########################################################
####################################################################

- block:
# Overlay 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') }}"
MaxVorobyev marked this conversation as resolved.
Show resolved Hide resolved

- name: ingress
docker_network:
name: "{{ nname_1 }}"
driver: overlay
ingress: true
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This task currently fails with

01:43 An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ansible_collections.community.docker.plugins.module_utils._api.errors.APIError: 409 Client Error for http+docker://localhost/v1.43/networks/create: Conflict ("rpc error: code = AlreadyExists desc = ingress network (j14ca3x29squ0lvqcyooyr5ik) is already present")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in a952631

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


Loading