[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>
This commit is contained in:
parent
2f523ad08e
commit
37df89b2d8
2 changed files with 17 additions and 1 deletions
2
changelogs/fragments/docker_network_aux_addresses.yml
Normal file
2
changelogs/fragments/docker_network_aux_addresses.yml
Normal file
|
@ -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…
Add table
Reference in a new issue