<h5 dir="auto">ISSUE TYPE</h5>
<ul dir="auto">
<li>Bug Report</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>
<p dir="auto">docker_network</p>
<h5 dir="auto">ANSIBLE VERSION</h5>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="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]"><pre class="notranslate"><code class="notranslate">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]
</code></pre></div>
<h5 dir="auto">CONFIGURATION</h5>

<p dir="auto">None</p>
<h5 dir="auto">OS / ENVIRONMENT</h5>

<p dir="auto">Debian stretch<br>
Docker 17.09.0-ce</p>
<h5 dir="auto">SUMMARY</h5>

<p dir="auto">If a docker network named <code class="notranslate">foobar</code> exist, ansible will not create a network called <code class="notranslate">foo</code>.</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>


<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="- hosts: localhost
  tasks:
  - docker_network:
      name: foo
      state: absent"><pre class="notranslate">- <span class="pl-ent">hosts</span>: <span class="pl-s">localhost</span>
  <span class="pl-ent">tasks</span>:
  - <span class="pl-ent">docker_network</span>:
      <span class="pl-ent">name</span>: <span class="pl-s">foo</span>
      <span class="pl-ent">state</span>: <span class="pl-s">absent</span></pre></div>

<h5 dir="auto">EXPECTED RESULTS</h5>

<p dir="auto">Ansible should validate OK that network <code class="notranslate">foo</code> is absent when a network named <code class="notranslate">foobar</code> is present.</p>
<h5 dir="auto">ACTUAL RESULTS</h5>

<p dir="auto">Ansible fails to validate that network <code class="notranslate">foo</code> is absent if network <code class="notranslate">foobar</code> is present.</p>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ 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 (&quot;network foo not found&quot;)
fatal: [localhost]: FAILED! =&gt; {&quot;changed&quot;: false, &quot;failed&quot;: true, &quot;module_stderr&quot;: &quot;Traceback (most recent call last):\n  File \&quot;/home/stefanga/.pyenv/versions/3.6.3/envs/ansible-py363/lib/python3.6/site-packages/docker/api/client.py\&quot;, line 220, in _raise_for_status\n    response.raise_for_status()\n  File \&quot;/home/stefanga/.pyenv/versions/3.6.3/envs/ansible-py363/lib/python3.6/site-packages/requests/models.py\&quot;, 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 \&quot;/tmp/ansible_5xkh3wf4/ansible_module_docker_network.py\&quot;, line 387, in &lt;module&gt;\n    main()\n  File \&quot;/tmp/ansible_5xkh3wf4/ansible_module_docker_network.py\&quot;, line 382, in main\n    cm = DockerNetworkManager(client)\n  File \&quot;/tmp/ansible_5xkh3wf4/ansible_module_docker_network.py\&quot;, line 208, in __init__\n    self.absent()\n  File \&quot;/tmp/ansible_5xkh3wf4/ansible_module_docker_network.py\&quot;, line 360, in absent\n    self.remove_network()\n  File \&quot;/tmp/ansible_5xkh3wf4/ansible_module_docker_network.py\&quot;, line 295, in remove_network\n    self.disconnect_all_containers()\n  File \&quot;/tmp/ansible_5xkh3wf4/ansible_module_docker_network.py\&quot;, line 324, in disconnect_all_containers\n    containers = self.client.inspect_network(self.parameters.network_name)['Containers']\n  File \&quot;/home/stefanga/.pyenv/versions/3.6.3/envs/ansible-py363/lib/python3.6/site-packages/docker/utils/decorators.py\&quot;, line 34, in wrapper\n    return f(self, *args, **kwargs)\n  File \&quot;/home/stefanga/.pyenv/versions/3.6.3/envs/ansible-py363/lib/python3.6/site-packages/docker/utils/decorators.py\&quot;, line 19, in wrapped\n    return f(self, resource_id, *args, **kwargs)\n  File \&quot;/home/stefanga/.pyenv/versions/3.6.3/envs/ansible-py363/lib/python3.6/site-packages/docker/api/network.py\&quot;, line 201, in inspect_network\n    return self._result(res, json=True)\n  File \&quot;/home/stefanga/.pyenv/versions/3.6.3/envs/ansible-py363/lib/python3.6/site-packages/docker/api/client.py\&quot;, line 226, in _result\n    self._raise_for_status(response)\n  File \&quot;/home/stefanga/.pyenv/versions/3.6.3/envs/ansible-py363/lib/python3.6/site-packages/docker/api/client.py\&quot;, line 222, in _raise_for_status\n    raise create_api_error_from_http_exception(e)\n  File \&quot;/home/stefanga/.pyenv/versions/3.6.3/envs/ansible-py363/lib/python3.6/site-packages/docker/errors.py\&quot;, 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 (\&quot;network foo not found\&quot;)\n&quot;, &quot;module_stdout&quot;: &quot;&quot;, &quot;msg&quot;: &quot;MODULE FAILURE&quot;, &quot;rc&quot;: 0}

PLAY RECAP ***********************************************************************************************************************************************************************************************************************************
localhost                  : ok=1    changed=0    unreachable=0    failed=1   "><pre class="notranslate"><code class="notranslate">$ 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! =&gt; {"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 &lt;module&gt;\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   
</code></pre></div>
<h5 dir="auto">ISSUE TYPE</h5>
<ul dir="auto">
<li>Bug Report</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>
<p dir="auto">docker_network</p>
<h5 dir="auto">ANSIBLE VERSION</h5>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="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]"><pre class="notranslate"><code class="notranslate">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]
</code></pre></div>
<h5 dir="auto">CONFIGURATION</h5>

<p dir="auto">None</p>
<h5 dir="auto">OS / ENVIRONMENT</h5>

<p dir="auto">Debian stretch<br>
Docker 17.09.0-ce</p>
<h5 dir="auto">SUMMARY</h5>

<p dir="auto">If a docker network named <code class="notranslate">foobar</code> exist, ansible will not create a network called <code class="notranslate">foo</code>.</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>


<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="- 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"><pre class="notranslate">- <span class="pl-ent">hosts</span>: <span class="pl-s">localhost</span>
  <span class="pl-ent">tasks</span>:
  - <span class="pl-ent">docker_network</span>:
      <span class="pl-ent">name</span>: <span class="pl-s">foobar</span>
      <span class="pl-ent">state</span>: <span class="pl-s">absent</span>

  - <span class="pl-ent">docker_network</span>:
      <span class="pl-ent">name</span>: <span class="pl-s">foo</span>
      <span class="pl-ent">state</span>: <span class="pl-s">absent</span>

  - <span class="pl-ent">docker_network</span>:
      <span class="pl-ent">name</span>: <span class="pl-s">foobar</span>
      <span class="pl-ent">driver</span>: <span class="pl-s">bridge</span>
      <span class="pl-ent">state</span>: <span class="pl-s">present</span>

  - <span class="pl-ent">docker_network</span>:
      <span class="pl-ent">name</span>: <span class="pl-s">foo</span>
      <span class="pl-ent">driver</span>: <span class="pl-s">bridge</span>
      <span class="pl-ent">state</span>: <span class="pl-s">present</span></pre></div>

<h5 dir="auto">EXPECTED RESULTS</h5>

<p dir="auto">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 <code class="notranslate">foobar</code> and one named <code class="notranslate">foo</code>.</p>
<h5 dir="auto">ACTUAL RESULTS</h5>

<p dir="auto">The last task will be marked as OK, but should be changed. No network named <code class="notranslate">foo</code> was created.</p>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ 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"><pre class="notranslate"><code class="notranslate">$ 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
</code></pre></div>