2016-03-02 04:50:30 +01:00
|
|
|
# Docker_Network Module Proposal
|
|
|
|
|
|
|
|
## Purpose and Scope:
|
|
|
|
|
|
|
|
The purpose of Docker_network is to create networks, connect containers to networks, disconnect containers from
|
|
|
|
networks, and delete networks.
|
|
|
|
|
|
|
|
Docker network will manage networks using docker-py to communicate with either a local or remote API. It will
|
|
|
|
support API versions >= 1.14. API connection details will be handled externally in a shared utility module similar to
|
|
|
|
how other cloud modules operate.
|
|
|
|
|
|
|
|
## Parameters:
|
|
|
|
|
|
|
|
Docker_network will accept the parameters listed below. Parameters related to connecting to the API will be handled in
|
|
|
|
a shared utility module, as mentioned above.
|
|
|
|
|
|
|
|
```
|
2016-03-02 17:22:34 +01:00
|
|
|
connected:
|
2016-03-02 04:50:30 +01:00
|
|
|
description:
|
2016-03-02 17:22:34 +01:00
|
|
|
- List of container names or container IDs to connect to a network.
|
2016-03-02 04:50:30 +01:00
|
|
|
default: null
|
|
|
|
|
|
|
|
driver:
|
|
|
|
description:
|
|
|
|
- Specify the type of network. Docker provides bridge and overlay drivers, but 3rd party drivers can also be used.
|
|
|
|
default: bridge
|
|
|
|
|
2016-03-02 17:22:34 +01:00
|
|
|
force:
|
2016-03-02 04:50:30 +01:00
|
|
|
description:
|
2016-03-02 17:22:34 +01:00
|
|
|
- With state 'absent' forces disconnecting all containers from the network prior to deleting the network. With
|
|
|
|
state 'present' will disconnect all containers, delete the network and re-create the network.
|
|
|
|
default: false
|
2016-03-02 04:50:30 +01:00
|
|
|
|
2016-03-02 17:22:34 +01:00
|
|
|
incremental:
|
2016-03-02 04:50:30 +01:00
|
|
|
description:
|
2016-03-02 17:22:34 +01:00
|
|
|
- By default the connected list is canonical, meaning containers not on the list are removed from the network.
|
|
|
|
Use incremental to leave existing containers connected.
|
|
|
|
default: false
|
2016-03-02 04:50:30 +01:00
|
|
|
|
2016-03-02 17:22:34 +01:00
|
|
|
network_name:
|
2016-03-02 04:50:30 +01:00
|
|
|
description:
|
2016-03-02 17:22:34 +01:00
|
|
|
- Name of the network to operate on.
|
|
|
|
default: null
|
|
|
|
required: true
|
2016-03-02 04:50:30 +01:00
|
|
|
|
2016-03-02 17:22:34 +01:00
|
|
|
options:
|
2016-03-02 04:50:30 +01:00
|
|
|
description:
|
2016-03-02 17:22:34 +01:00
|
|
|
- Dictionary of network settings. Consult docker docs for valid options and values.
|
|
|
|
default: null
|
2016-03-02 04:50:30 +01:00
|
|
|
|
|
|
|
state:
|
|
|
|
description:
|
|
|
|
- "absent" deletes the network. If a network has connected containers, it cannot be deleted. Use the force option
|
|
|
|
to disconnect all containers and delete the network.
|
|
|
|
- "present" creates the network, if it does not already exist with the specified parameters, and connects the list
|
2016-03-02 17:22:34 +01:00
|
|
|
of containers provided via the connected parameter. Containers not on the list will be disconnected. An empty
|
|
|
|
list will leave no containers connected to the network. Use the incremental option to leave existing containers
|
|
|
|
connected. Use the force options to force re-creation of the network.
|
2016-03-02 04:50:30 +01:00
|
|
|
default: present
|
|
|
|
choices:
|
|
|
|
- absent
|
|
|
|
- present
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
## Examples:
|
|
|
|
|
|
|
|
```
|
|
|
|
- name: Create a network
|
|
|
|
docker_network:
|
|
|
|
name: network_one
|
|
|
|
|
|
|
|
- name: Remove all but selected list of containers
|
|
|
|
docker_network:
|
|
|
|
name: network_one
|
|
|
|
connected:
|
|
|
|
- containera
|
|
|
|
- containerb
|
2016-03-02 17:22:34 +01:00
|
|
|
- containerc
|
2016-03-02 04:50:30 +01:00
|
|
|
|
2016-03-02 17:22:34 +01:00
|
|
|
- name: Remove a single container
|
2016-03-02 04:50:30 +01:00
|
|
|
docker_network:
|
|
|
|
name: network_one
|
2016-03-02 17:22:34 +01:00
|
|
|
connected: "{{ fulllist|difference(['containera']) }}"
|
|
|
|
|
|
|
|
- name: Add a container to a network, leaving existing containers connected
|
2016-03-02 04:50:30 +01:00
|
|
|
docker_network:
|
|
|
|
name: network_one
|
|
|
|
connected:
|
|
|
|
- containerc
|
2016-03-02 17:22:34 +01:00
|
|
|
incremental: yes
|
|
|
|
|
|
|
|
- name: Create a network with options (Not sure if 'ip_range' is correct key name)
|
2016-03-02 04:50:30 +01:00
|
|
|
docker_network
|
|
|
|
name: network_two
|
|
|
|
options:
|
|
|
|
subnet: '172.3.26.0/16'
|
|
|
|
gateway: 172.3.26.1
|
|
|
|
ip_range: '192.168.1.0/24'
|
2016-03-02 17:22:34 +01:00
|
|
|
|
|
|
|
- name: Delete a network, disconnecting all containers
|
|
|
|
docker_network:
|
|
|
|
name: network_one
|
|
|
|
state: absent
|
|
|
|
force: yes
|
2016-03-02 04:50:30 +01:00
|
|
|
```
|
|
|
|
|
|
|
|
## Returns:
|
|
|
|
|
|
|
|
```
|
|
|
|
{
|
|
|
|
changed: True,
|
|
|
|
failed: false
|
|
|
|
rc: 0
|
|
|
|
action: created | removed | none
|
|
|
|
results: {
|
|
|
|
< results from docker inspect for the affected network >
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|