community / community.docker / 3.8.1 / module / docker_network Manage Docker networks Authors: Ben Keith (@keitwb), Chris Houseknecht (@chouseknecht), Dave Bendit (@DBendit)community.docker.docker_network (3.8.1) — module
Install with ansible-galaxy collection install community.docker:==3.8.1
collections: - name: community.docker version: 3.8.1
Create/remove Docker networks and connect containers to them.
Performs largely the same function as the C(docker network) CLI subcommand.
- name: Create a network community.docker.docker_network: name: network_one
- name: Remove all but selected list of containers community.docker.docker_network: name: network_one connected: - container_a - container_b - container_c
- name: Remove a single container community.docker.docker_network: name: network_one connected: "{{ fulllist|difference(['container_a']) }}"
- name: Add a container to a network, leaving existing containers connected community.docker.docker_network: name: network_one connected: - container_a appends: true
- name: Create a network with driver options community.docker.docker_network: name: network_two driver_options: com.docker.network.bridge.name: net2
- name: Create a network with custom IPAM config community.docker.docker_network: name: network_three ipam_config: - subnet: 172.23.27.0/24 gateway: 172.23.27.2 iprange: 172.23.27.0/26 aux_addresses: host1: 172.23.27.3 host2: 172.23.27.4
- name: Create a network with labels community.docker.docker_network: name: network_four labels: key1: value1 key2: value2
- name: Create a network with IPv6 IPAM config community.docker.docker_network: name: network_ipv6_one enable_ipv6: true ipam_config: - subnet: fdd1:ac8c:0557:7ce1::/64
- name: Create a network with IPv6 and custom IPv4 IPAM config community.docker.docker_network: name: network_ipv6_two enable_ipv6: true ipam_config: - subnet: 172.24.27.0/24 - subnet: fdd1:ac8c:0557:7ce2::/64
- name: Delete a network, disconnecting all containers community.docker.docker_network: name: network_one state: absent force: true
tls: default: false description: - Secure the connection to the API by using TLS without verifying the authenticity of the Docker host server. Note that if O(validate_certs) is set to V(true) as well, it will take precedence. - If the value is not specified in the task, the value of environment variable E(DOCKER_TLS) will be used instead. If the environment variable is not set, the default value will be used. type: bool name: aliases: - network_name description: - Name of the network to operate on. required: true type: str debug: default: false description: - Debug mode type: bool force: default: false description: - With state V(absent) forces disconnecting all containers from the network prior to deleting the network. With state V(present) will disconnect all containers, delete the network and re-create the network. - This option is required if you have changed the IPAM or driver options and want an existing network to be updated to use the new options. type: bool scope: choices: - local - global - swarm description: - Specify the network's scope. type: str state: choices: - absent - present default: present description: - V(absent) deletes the network. If a network has connected containers, it cannot be deleted. Use the O(force) option to disconnect all containers and delete the network. - V(present) creates the network, if it does not already exist with the specified parameters, and connects the list 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 O(appends) option to leave existing containers connected. Use the O(force) options to force re-creation of the network. type: str driver: default: bridge description: - Specify the type of network. Docker provides bridge and overlay drivers, but 3rd party drivers can also be used. type: str labels: default: {} description: - Dictionary of labels. type: dict appends: aliases: - incremental default: false description: - By default the connected list is canonical, meaning containers not on the list are removed from the network. - Use O(appends) to leave existing containers connected. type: bool ca_path: aliases: - ca_cert - tls_ca_cert - cacert_path description: - Use a CA certificate when performing server verification by providing the path to a CA certificate file. - If the value is not specified in the task and the environment variable E(DOCKER_CERT_PATH) is set, the file C(ca.pem) from the directory specified in the environment variable E(DOCKER_CERT_PATH) will be used. - This option was called O(ca_cert) and got renamed to O(ca_path) in community.docker 3.6.0. The old name has been added as an alias and can still be used. type: path timeout: default: 60 description: - The maximum amount of time in seconds to wait on a response from the API. - If the value is not specified in the task, the value of environment variable E(DOCKER_TIMEOUT) will be used instead. If the environment variable is not set, the default value will be used. type: int internal: description: - Restrict external access to the network. type: bool connected: aliases: - containers default: [] description: - List of container names or container IDs to connect to a network. - Please note that the module only makes sure that these containers are connected to the network, but does not care about connection options. If you rely on specific IP addresses etc., use the M(community.docker.docker_container) module to ensure your containers are correctly connected to this network. elements: str type: list attachable: description: - If enabled, and the network is in the global scope, non-service containers on worker nodes will be able to connect to the network. type: bool client_key: aliases: - tls_client_key - key_path description: - Path to the client's TLS key file. - If the value is not specified in the task and the environment variable E(DOCKER_CERT_PATH) is set, the file C(key.pem) from the directory specified in the environment variable E(DOCKER_CERT_PATH) will be used. type: path api_version: aliases: - docker_api_version default: auto description: - The version of the Docker API running on the Docker Host. - Defaults to the latest version of the API supported by this collection and the docker daemon. - If the value is not specified in the task, the value of environment variable E(DOCKER_API_VERSION) will be used instead. If the environment variable is not set, the default value will be used. type: str client_cert: aliases: - tls_client_cert - cert_path description: - Path to the client's TLS certificate file. - If the value is not specified in the task and the environment variable E(DOCKER_CERT_PATH) is set, the file C(cert.pem) from the directory specified in the environment variable E(DOCKER_CERT_PATH) will be used. type: path docker_host: aliases: - docker_url default: unix:///var/run/docker.sock description: - The URL or Unix socket path used to connect to the Docker API. To connect to a remote host, provide the TCP connection string. For example, V(tcp://192.0.2.23:2376). If TLS is used to encrypt the connection, the module will automatically replace C(tcp) in the connection URL with C(https). - If the value is not specified in the task, the value of environment variable E(DOCKER_HOST) will be used instead. If the environment variable is not set, the default value will be used. type: str enable_ipv6: description: - Enable IPv6 networking. type: bool ipam_config: description: - List of IPAM config blocks. Consult L(Docker docs,https://docs.docker.com/compose/compose-file/compose-file-v2/#ipam) for valid options and values. Note that O(ipam_config[].iprange) is spelled differently here (we use the notation from the Docker SDK for Python). elements: dict suboptions: aux_addresses: description: - Auxiliary IP addresses used by Network driver, as a mapping from hostname to IP. type: dict gateway: description: - IP gateway address. type: str iprange: description: - IP address range in CIDR notation. type: str subnet: description: - IP subset in CIDR notation. type: str type: list ipam_driver: description: - Specify an IPAM driver. type: str ssl_version: description: - Provide a valid SSL version number. Default value determined by L(SSL Python module, https://docs.python.org/3/library/ssl.html). - If the value is not specified in the task, the value of environment variable E(DOCKER_SSL_VERSION) will be used instead. type: str tls_hostname: description: - When verifying the authenticity of the Docker Host server, provide the expected name of the server. - If the value is not specified in the task, the value of environment variable E(DOCKER_TLS_HOSTNAME) will be used instead. If the environment variable is not set, the default value will be used. - Note that this option had a default value V(localhost) in older versions. It was removed in community.docker 3.0.0. type: str driver_options: default: {} description: - Dictionary of network settings. Consult docker docs for valid options and values. type: dict use_ssh_client: default: false description: - For SSH transports, use the C(ssh) CLI tool instead of paramiko. type: bool version_added: 1.5.0 version_added_collection: community.docker validate_certs: aliases: - tls_verify default: false description: - Secure the connection to the API by using TLS and verifying the authenticity of the Docker host server. - If the value is not specified in the task, the value of environment variable E(DOCKER_TLS_VERIFY) will be used instead. If the environment variable is not set, the default value will be used. type: bool ipam_driver_options: description: - Dictionary of IPAM driver options. type: dict
network: description: - Network inspection results for the affected network. returned: success sample: {} type: dict