Issue 1:
ISSUE TYPE

Bug Report

COMPONENT NAME

docker_network

ANSIBLE VERSION

ansible 2.4.1.0
config file = None
configured module search path = ['/home/stefanga/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/stefanga/.pyenv/versions/3.6.3/envs/ansible-py363/lib/python3.6/site-packages/ansible
executable location = /home/stefanga/.pyenv/versions/ansible-py363/bin/ansible
python version = 3.6.3 (default, Oct 30 2017, 13:57:15) [GCC 6.3.0 20170516]

CONFIGURATION

None

OS / ENVIRONMENT

Debian stretch

Docker 17.09.0-ce

SUMMARY

If a docker network named foobar exist, ansible will not create a network called foo.

STEPS TO REPRODUCE

- hosts: localhost
tasks:
- docker_network:
name: foo
state: absent

EXPECTED RESULTS

Ansible should validate OK that network foo is absent when a network named foobar is present.

ACTUAL RESULTS

Ansible fails to validate that network foo is absent if network foobar is present.

$ docker network create foobar
2a8cb4ee29fb6bd809a59146c966a52af378326b32e0f9dd07d2e874a5d4b233
$ ansible-playbook play.yml
[WARNING]: Unable to parse /etc/ansible/hosts as an inventory source

[WARNING]: No inventory was parsed, only implicit localhost is available

[WARNING]: Could not match supplied host pattern, ignoring: all

[WARNING]: provided hosts list is empty, only localhost is available

PLAY [localhost] *****************************************************************************************************************************************************************************************************************************

TASK [Gathering Facts] ***********************************************************************************************************************************************************************************************************************
ok: [localhost]

TASK [docker_network] ************************************************************************************************************************************************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: docker.errors.NotFound: 404 Client Error: Not Found ("network foo not found")
fatal: [localhost]: FAILED! => {"changed": false, "failed": true, "module_stderr": "Traceback (most recent call last):\n File \"/home/stefanga/.pyenv/versions/3.6.3/envs/ansible-py363/lib/python3.6/site-packages/docker/api/client.py\", line 220, in _raise_for_status\n response.raise_for_status()\n File \"/home/stefanga/.pyenv/versions/3.6.3/envs/ansible-py363/lib/python3.6/site-packages/requests/models.py\", line 935, in raise_for_status\n raise HTTPError(http_error_msg, response=self)\nrequests.exceptions.HTTPError: 404 Client Error: Not Found for url: http+docker://localunixsocket/v1.32/networks/foo\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n File \"/tmp/ansible_5xkh3wf4/ansible_module_docker_network.py\", line 387, in <module>\n main()\n File \"/tmp/ansible_5xkh3wf4/ansible_module_docker_network.py\", line 382, in main\n cm = DockerNetworkManager(client)\n File \"/tmp/ansible_5xkh3wf4/ansible_module_docker_network.py\", line 208, in __init__\n self.absent()\n File \"/tmp/ansible_5xkh3wf4/ansible_module_docker_network.py\", line 360, in absent\n self.remove_network()\n File \"/tmp/ansible_5xkh3wf4/ansible_module_docker_network.py\", line 295, in remove_network\n self.disconnect_all_containers()\n File \"/tmp/ansible_5xkh3wf4/ansible_module_docker_network.py\", line 324, in disconnect_all_containers\n containers = self.client.inspect_network(self.parameters.network_name)['Containers']\n File \"/home/stefanga/.pyenv/versions/3.6.3/envs/ansible-py363/lib/python3.6/site-packages/docker/utils/decorators.py\", line 34, in wrapper\n return f(self, *args, **kwargs)\n File \"/home/stefanga/.pyenv/versions/3.6.3/envs/ansible-py363/lib/python3.6/site-packages/docker/utils/decorators.py\", line 19, in wrapped\n return f(self, resource_id, *args, **kwargs)\n File \"/home/stefanga/.pyenv/versions/3.6.3/envs/ansible-py363/lib/python3.6/site-packages/docker/api/network.py\", line 201, in inspect_network\n return self._result(res, json=True)\n File \"/home/stefanga/.pyenv/versions/3.6.3/envs/ansible-py363/lib/python3.6/site-packages/docker/api/client.py\", line 226, in _result\n self._raise_for_status(response)\n File \"/home/stefanga/.pyenv/versions/3.6.3/envs/ansible-py363/lib/python3.6/site-packages/docker/api/client.py\", line 222, in _raise_for_status\n raise create_api_error_from_http_exception(e)\n File \"/home/stefanga/.pyenv/versions/3.6.3/envs/ansible-py363/lib/python3.6/site-packages/docker/errors.py\", line 31, in create_api_error_from_http_exception\n raise cls(e, response=response, explanation=explanation)\ndocker.errors.NotFound: 404 Client Error: Not Found (\"network foo not found\")\n", "module_stdout": "", "msg": "MODULE FAILURE", "rc": 0}

PLAY RECAP ***********************************************************************************************************************************************************************************************************************************
localhost : ok=1 changed=0 unreachable=0 failed=1

Issue 2:
ISSUE TYPE

Bug Report

COMPONENT NAME

docker_network

ANSIBLE VERSION

ansible 2.4.1.0
config file = None
configured module search path = ['/home/stefanga/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/stefanga/.pyenv/versions/3.6.3/envs/ansible-py363/lib/python3.6/site-packages/ansible
executable location = /home/stefanga/.pyenv/versions/ansible-py363/bin/ansible
python version = 3.6.3 (default, Oct 30 2017, 13:57:15) [GCC 6.3.0 20170516]

CONFIGURATION

None

OS / ENVIRONMENT

Debian stretch

Docker 17.09.0-ce

SUMMARY

If a docker network named foobar exist, ansible will not create a network called foo.

STEPS TO REPRODUCE

- hosts: localhost
tasks:
- docker_network:
name: foobar
state: absent

- docker_network:
name: foo
state: absent

- docker_network:
name: foobar
driver: bridge
state: present

- docker_network:
name: foo
driver: bridge
state: present

EXPECTED RESULTS

The first two tasks should make sure that there are no networks with the names that I later want to create. The next two tasks should create two networks, one named foobar and one named foo.

ACTUAL RESULTS

The last task will be marked as OK, but should be changed. No network named foo was created.

$ ansible-playbook play.yml
[WARNING]: Unable to parse /etc/ansible/hosts as an inventory source

[WARNING]: No inventory was parsed, only implicit localhost is available

[WARNING]: Could not match supplied host pattern, ignoring: all

[WARNING]: provided hosts list is empty, only localhost is available

PLAY [localhost] *****************************************************************************************************************************************************************************************************************************

TASK [Gathering Facts] ***********************************************************************************************************************************************************************************************************************
ok: [localhost]

TASK [docker_network] ************************************************************************************************************************************************************************************************************************
ok: [localhost]

TASK [docker_network] ************************************************************************************************************************************************************************************************************************
ok: [localhost]

TASK [docker_network] ************************************************************************************************************************************************************************************************************************
changed: [localhost]

TASK [docker_network] ************************************************************************************************************************************************************************************************************************
ok: [localhost]

PLAY RECAP ***********************************************************************************************************************************************************************************************************************************
localhost : ok=5 changed=1 unreachable=0 failed=0

$ docker network ls
NETWORK ID NAME DRIVER SCOPE
d42fb791c42d bridge bridge local
bbf89471a76c docker_gwbridge bridge local
c7bc6eac5b9f foobar bridge local
45f0b240c613 host host local
imy5g3h4bnw3 ingress overlay swarm
78f35da91298 none null local