@ -132,6 +132,14 @@ options:
default : null
default : null
required : false
required : false
labels :
version_added : 2.8
description :
- Dictionary of labels .
type : dict
default : null
required : false
scope :
scope :
version_added : 2.8
version_added : 2.8
description :
description :
@ -216,6 +224,13 @@ EXAMPLES = '''
host1 : 172.3 .27 .3
host1 : 172.3 .27 .3
host2 : 172.3 .27 .4
host2 : 172.3 .27 .4
- name : Create a network with labels
docker_network :
name : network_four
labels :
key1 : value1
key2 : value2
- name : Create a network with IPv6 IPAM config
- name : Create a network with IPv6 IPAM config
docker_network :
docker_network :
name : network_ipv6_one
name : network_ipv6_one
@ -283,6 +298,7 @@ class TaskParameters(DockerBaseClass):
self . appends = None
self . appends = None
self . force = None
self . force = None
self . internal = None
self . internal = None
self . labels = None
self . debug = None
self . debug = None
self . enable_ipv6 = None
self . enable_ipv6 = None
self . scope = None
self . scope = None
@ -437,6 +453,17 @@ class DockerNetworkManager(object):
differences . add ( ' attachable ' ,
differences . add ( ' attachable ' ,
parameter = self . parameters . attachable ,
parameter = self . parameters . attachable ,
active = net . get ( ' Attachable ' ) )
active = net . get ( ' Attachable ' ) )
if self . parameters . labels :
if not net . get ( ' Labels ' ) :
differences . add ( ' labels ' ,
parameter = self . parameters . labels ,
active = net . get ( ' Labels ' ) )
else :
for key , value in self . parameters . labels . items ( ) :
if not ( key in net [ ' Labels ' ] ) or value != net [ ' Labels ' ] [ key ] :
differences . add ( ' labels. %s ' % key ,
parameter = value ,
active = net [ ' Labels ' ] . get ( key ) )
return not differences . empty , differences
return not differences . empty , differences
@ -475,6 +502,8 @@ class DockerNetworkManager(object):
params [ ' scope ' ] = self . parameters . scope
params [ ' scope ' ] = self . parameters . scope
if self . parameters . attachable is not None :
if self . parameters . attachable is not None :
params [ ' attachable ' ] = self . parameters . attachable
params [ ' attachable ' ] = self . parameters . attachable
if self . parameters . labels :
params [ ' labels ' ] = self . parameters . labels
if not self . check_mode :
if not self . check_mode :
resp = self . client . create_network ( self . parameters . network_name , * * params )
resp = self . client . create_network ( self . parameters . network_name , * * params )
@ -586,6 +615,7 @@ def main():
) ) ,
) ) ,
enable_ipv6 = dict ( type = ' bool ' ) ,
enable_ipv6 = dict ( type = ' bool ' ) ,
internal = dict ( type = ' bool ' ) ,
internal = dict ( type = ' bool ' ) ,
labels = dict ( type = ' dict ' , default = { } ) ,
debug = dict ( type = ' bool ' , default = False ) ,
debug = dict ( type = ' bool ' , default = False ) ,
scope = dict ( type = ' str ' , choices = [ ' local ' , ' global ' , ' swarm ' ] ) ,
scope = dict ( type = ' str ' , choices = [ ' local ' , ' global ' , ' swarm ' ] ) ,
attachable = dict ( type = ' bool ' ) ,
attachable = dict ( type = ' bool ' ) ,
@ -598,6 +628,7 @@ def main():
option_minimal_versions = dict (
option_minimal_versions = dict (
scope = dict ( docker_py_version = ' 2.6.0 ' , docker_api_version = ' 1.30 ' ) ,
scope = dict ( docker_py_version = ' 2.6.0 ' , docker_api_version = ' 1.30 ' ) ,
attachable = dict ( docker_py_version = ' 2.0.0 ' , docker_api_version = ' 1.26 ' ) ,
attachable = dict ( docker_py_version = ' 2.0.0 ' , docker_api_version = ' 1.26 ' ) ,
labels = dict ( docker_api_version = ' 1.23 ' ) ,
)
)
client = AnsibleDockerClient (
client = AnsibleDockerClient (