[docker_network] Fix idempotency when using aux_addresses in ipam_config (#56901)

* [docker_network] Fix idempotency when using aux_addresses in ipam_config

Mismatch between keys returned by Docker API (AuxilliaryAddresses) vs
expected by Ansible module (aux_addresses) resulted in tasks always
have status 'changed'. The existing code normalizing one set of
keys to another missed this special case where converting
CamelCase to lowercase is not sufficent.

Please see
https://github.com/moby/moby/blob/master/api/types/network/network.go
for reference.

* Correct keywords formatting in changelog file

Co-Authored-By: Felix Fontein <felix@fontein.de>
pull/56975/head
SirFerdek 5 years ago committed by ansibot
parent 2f523ad08e
commit 37df89b2d8

@ -0,0 +1,2 @@
bugfixes:
- docker_network module - fix idempotency when using ``aux_addresses`` in ``ipam_config``.

@ -346,6 +346,20 @@ def get_ip_version(cidr):
raise ValueError('"{0}" is not a valid CIDR'.format(cidr))
def normalize_ipam_config_key(key):
"""Normalizes IPAM config keys returned by Docker API to match Ansible keys
:param key: Docker API key
:type key: str
:return Ansible module key
:rtype str
"""
special_cases = {
'AuxiliaryAddresses': 'aux_addresses'
}
return special_cases.get(key, key.lower())
class DockerNetworkManager(object):
def __init__(self, client):
@ -447,7 +461,7 @@ class DockerNetworkManager(object):
continue
camelkey = None
for net_key in net_config:
if key == net_key.lower():
if key == normalize_ipam_config_key(net_key):
camelkey = net_key
break
if not camelkey or net_config.get(camelkey) != value:

Loading…
Cancel
Save