Skip to content
This repository has been archived by the owner on Jan 5, 2023. It is now read-only.

Commit

Permalink
Fix unnecessary warnings when creating/destroying docker networks (#48)
Browse files Browse the repository at this point in the history
* Fix unnecessary warnings when creating/destroying docker networks

Fixes #47

* Fix flake8-black reformat
  • Loading branch information
Mike Pettypiece authored and ssbarnea committed May 26, 2021
1 parent 813a01e commit 17a3964
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 12 deletions.
33 changes: 30 additions & 3 deletions molecule_docker/playbooks/create.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,40 @@
delay: 30

- name: Create docker network(s)
action: docker_network
args: "{{ item }}"
with_items: "{{ molecule_yml.platforms | molecule_get_docker_networks('present', molecule_labels) }}"
docker_network:
api_version: "{{ item.api_version | default(omit) }}"
appends: "{{ item.appends | default(omit) }}"
attachable: "{{ item.attachable | default(omit) }}"
ca_cert: "{{ item.ca_cert | default(omit) }}"
client_cert: "{{ item.client_cert | default(omit) }}"
client_key: "{{ item.client_key | default(omit) }}"
connected: "{{ item.connected | default(omit) }}"
debug: "{{ item.debug | default(omit) }}"
docker_host: "{{ item.docker_host | default(omit) }}"
driver: "{{ item.driver | default(omit) }}"
driver_options: "{{ item.driver_options | default(omit) }}"
enable_ipv6: "{{ item.enable_ipv6 | default(omit) }}"
force: "{{ item.force | default(omit) }}"
internal: "{{ item.internal | default(omit) }}"
ipam_config: "{{ item.ipam_config | default(omit) }}"
ipam_driver: "{{ item.ipam_driver | default(omit) }}"
ipam_driver_options: "{{ item.ipam_driver_options | default(omit) }}"
key_path: "{{ item.key_path | default(omit) }}"
labels: "{{ item.labels }}"
name: "{{ item.name }}"
scope: "{{ item.scope | default(omit) }}"
ssl_version: "{{ item.ssl_version | default(omit) }}"
state: "present"
timeout: "{{ item.timeout | default(omit) }}"
tls: "{{ item.tls | default(omit) }}"
tls_hostname: "{{ item.tls_hostname | default(omit) }}"
validate_certs: "{{ item.validate_certs | default(omit) }}"
with_items: "{{ molecule_yml.platforms | molecule_get_docker_networks(molecule_labels) }}"
loop_control:
label: "{{ item.name }}"
no_log: false


- name: Determine the CMD directives
set_fact:
command_directives_dict: >-
Expand Down
7 changes: 4 additions & 3 deletions molecule_docker/playbooks/destroy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@
with_items: "{{ server.results }}"

- name: Delete docker network(s)
action: docker_network
args: "{{ item }}"
with_items: "{{ molecule_yml.platforms | molecule_get_docker_networks('absent') }}"
docker_network:
name: "{{ item.name }}"
state: "absent"
with_items: "{{ molecule_yml.platforms | molecule_get_docker_networks() }}"
loop_control:
label: "{{ item.name }}"
no_log: false
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Embedded ansible filter used by Molecule Docker driver create playbook."""


def get_docker_networks(data, state, labels={}):
def get_docker_networks(data, labels={}):
"""Get list of docker networks."""
network_list = []
network_names = []
Expand All @@ -13,8 +13,6 @@ def get_docker_networks(data, state, labels={}):
for key in labels:
docker_network["labels"][key] = labels[key]

docker_network["state"] = state

if "name" in docker_network:
network_list.append(docker_network)
network_names.append(docker_network["name"])
Expand All @@ -26,9 +24,7 @@ def get_docker_networks(data, state, labels={}):
if "name" in network:
name = network["name"]
if name not in network_names:
network_list.append(
{"name": name, "labels": labels, "state": state}
)
network_list.append({"name": name, "labels": labels})
return network_list


Expand Down

0 comments on commit 17a3964

Please sign in to comment.